2012-10-06 4 views
0

저는 java에 익숙하지 않아 프로그램의 일부에서 잘못 잡혔습니다.자바 (처리)에서 문자열의 값을 받아서 ascii 값과 비교하십시오.

저는 Voce라는 라이브러리를 사용하고 있습니다. 음성 인식에 사용됩니다. 그것은 음성이나 단어를 인식하고 문법에 내장 된 것과 비교하여 "문자열"값으로 인쇄합니다. 예 : '5'라고 말하면 '5'가 인쇄됩니다.

내가 묻는 이유는 무엇입니까. 그 문자열 값을 원하는 값과 비교하는 방법. 예 : 코드 값이 "다섯"다음 여기에서 더

작업을 위해 다른 문자열에 저장됩니다 당신은 여기 VOCE 라이브러리 http://voce.sourceforge.net/ 을 찾을 수는 /////////// 당신이의 insearch있는 것은 동일한 기능을 /////////////////////////////

//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); 
} 
} 
+2

d 당신은'if (pieces [0] .equals ("five"))와 같은 것을 의미합니까? – dasblinkenlight

+0

예. 하지만 작동하는 경우에만 .. –

+0

[자바에서 문자열을 어떻게 비교합니까?] (http://stackoverflow.com/questions/513832/how-do-i-compare-strings-in-java) –

답변

관련 문제