java - 将不带空终止的字符串传递给java中的方法
问题描述
我在 Raspberry Pi3 上使用 vr3 语音转文本模块。我想用我给出的语音命令激活引脚输出。下面的代码块有问题。如果我string()
直接输入方法speech2command
,一切看起来都很正常;(speech2command("ONE") ..etc)。如果我使用语音字符串值,我会遇到问题。也许我需要一个空终止的字符串?如果是这样,我应该如何添加?
private static String toASCII(int value) {
int length = 4;
StringBuilder builder = new StringBuilder(length);
for (int i = length - 1; i >= 0; i--) {
builder.append((char) ((value >> (8 * i)) & 0xFF));
}
return builder.toString();
}
//******************************************************************************
public static void speech2command(String strSource) {
// System.out.println("--> Comingstring-->"+strSource);
if(strSource.equals("ZERO")==true) {
System.out.println("--> GPIO state-->ZERO STATE");
output.low(); // LED OFF
}
if(strSource.equals("ONE")==true) {
System.out.println("--> GPIO state-->ONE STATE");
output.high(); // LED ON
}
}
//****************************************************************************
//
//
//
for (int i = 0; i < l; i++) {
ret[i] = Integer.valueOf(globalstringhex.substring(i * 2, i * 2 + 2),
16).byteValue();//Hexstring --> ASCII
int k=ret[i];
if (k>=32 && k<=126) {//input "readable chars"
speechstring+= toASCII(k);
}
}
globalstringhex="";
speech2command(speechstring);//---> This line is not working correctly.
textArea_4.append("\n\r");
speechcommand("ONE");//---> if i use parameter "ZERO" or "ONE" everything is ok. But if i use
speechcommand(speechstring); line , LED never work.
解决方案
推荐阅读
- r - 当级别数低于使用 dplyr 的给定阈值时,将数值变量转换为因子
- jenkins-pipeline - 防止同一存储库上的两个更改请求以主节点为目标在同一节点上运行
- python - socket.recv() 未在发送端触发
- tensorflow - 如何将 Keras Retinanet 模型转换为 TF 模型进行预测?
- image - 你能告诉我我的图片在 Safari 中的样子吗
- linux - npm run start error anaconda:environmental variable ubuntu20.04 :Attempting to bind to HOST environment variable x86_64-conda_cos6-linux-gnu
- html - 驱动程序在 Angular db 中编程外部连接失败
- python - 反转链表(迭代方法)
- google-bigquery - 从 Oracle db 到实时大查询的 Google 数据流能力
- javascript - 如何在不中断主线程的情况下在 three.js / javascript 中加载纹理?