Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
获取Java(处理)中字符串的值,并与ascii值进行比较_Java_String - Fatal编程技术网

获取Java(处理)中字符串的值,并与ascii值进行比较

获取Java(处理)中字符串的值,并与ascii值进行比较,java,string,Java,String,我是java新手,在我的程序中,有一部分内容让我陷入了困境 我正在使用一个名为Voce的库。用于语音识别。它识别语音或单词,与内置语法进行比较,并以“字符串”值打印出来。 e、 g:如果你说“五”,它会打印“五” 我问这个问题的原因是。这就是如何将该字符串值与所需值进行比较。 e、 g:如果值为“5”,则将其存储在另一个字符串中,以便进一步处理 代码如下: 你可以在这里找到Voce库 //////////////////////////////////////// //import the l

我是java新手,在我的程序中,有一部分内容让我陷入了困境

我正在使用一个名为Voce的库。用于语音识别。它识别语音或单词,与内置语法进行比较,并以“字符串”值打印出来。 e、 g:如果你说“五”,它会打印“五”

我问这个问题的原因是。这就是如何将该字符串值与所需值进行比较。 e、 g:如果值为“5”,则将其存储在另一个字符串中,以便进一步处理

代码如下: 你可以在这里找到Voce库 ////////////////////////////////////////

 //import the libraries
import guru.ttslib.*;
import processing.serial.*;

//give our instances names
Serial treePort;
TTS tts;

void setup(){
  //the following initiates the voce library
  voce.SpeechInterface.init("libraries/voce-0.9.1/lib", true, true,"libraries/voce-0.9.1/lib/gram","digits");
  //start our port and also tts
  treePort = new Serial(this,Serial.list()[0],9600);
  tts = new TTS();
  //the following settings control the voice sound
  tts.setPitch( 180 );
  tts.setPitchRange( 90 );
  //tts.setPitchShift( -10.5 );
  treePort.write("73");   //send command to turn on the lights and open the eyes
}

void draw(){

  if (voce.SpeechInterface.getRecognizerQueueSize()>0){    //if voce recognizes anything being said
      String s = voce.SpeechInterface.popRecognizedString();      //assign the string that voce heard to the variable s
      println("you said: " + s);                          //print what was heard to the debug window.
      respond(s);
    } 

}
//This function will split the text up into multiple words, and decide how to animate depending on the length of each word and also pauses which are denoted by "!"
void respond(String input){
  if (input.length() > 0){  //we actually have something to say 
  voce.SpeechInterface.setRecognizerEnabled(false);    //stop listening, otherwise we will hear ourselves and go into a loop
  //this just splits up all the words sends motion
  String[] words = split(input," ");
  int howMany = words.length;

  for(int i=0;i<howMany;i++){
    String pieces[] = split(words[i],"!");  //if we see a ! then reading pauses slightly so it is a good time to blink
    if(pieces.length==2){
    treePort.write("1");
    int pause = int(random(100));
    if(pause>60){
      treePort.write("5");
    }
    else{
      treePort.write("7");
      delay(500);
    }
    }
    else{
      treePort.write("1");
    }

  }
  tts.speak(input);
  voce.SpeechInterface.setRecognizerEnabled(true);
}
}
//导入库
导入guru.ttslib.*;
输入处理。串行。*;
//给我们的实例命名
串行树端口;
TTS-TTS;
无效设置(){
//以下命令将启动voce库
voce.SpeechInterface.init(“libraries/voce-0.9.1/lib”,true,true,“libraries/voce-0.9.1/lib/gram”,“digits”);
//启动我们的端口和tts
treePort=new Serial(这是Serial.list()[0],9600);
tts=新的tts();
//以下设置控制语音
tts.设定螺距(180);
tts.设置变桨距范围(90);
//tts.setPitchShift(-10.5);
treePort.write(“73”);//发送命令打开灯并睁开眼睛
}
作废提款(){
if(voce.SpeechInterface.getRecognitizerQueueSize()>0){//如果voce识别出所说的任何内容
String s=voce.SpeechInterface.PopRecognitizedString();//将voce听到的字符串分配给变量s
println(“您说过:”+s);//打印调试窗口中听到的内容。
答复;
} 
}
//此函数将文本拆分为多个单词,并根据每个单词的长度以及用“!”表示的暂停来决定如何设置动画
无效响应(字符串输入){
如果(input.length()>0){//我们实际上有话要说
voce.SpeechInterface.setRecognitizerEnabled(false);//停止侦听,否则我们将听到自己的声音并进入循环
//这只是把所有的单词分开
字符串[]字=拆分(输入“”);
int howMany=单词数。长度;
对于(int i=0;i60){
treePort.write(“5”);
}
否则{
treePort.write(“7”);
延迟(500);
}
}
否则{
treePort.write(“1”);
}
}
说话(输入);
voce.SpeechInterface.SetRecognitizerEnabled(真);
}
}

您所研究的是同等功能。。。查看此参考以了解更多详细信息


你的意思是像
if(件[0].=(“五”)…
?if的可能重复项任何人都可以检查它是否工作。非常感谢