You have to place the codes in onPartialResult()
method. For different actions to be performed for different voice commands, you can use if-else
or switch
as per your need in the code.
I am assuming that your provided code for starting different new activities are ok and the BloodPressure
class will run for listening the command "blood pressure", the HeartRate
class will run for listening the command "heart rate" and the PatientInfo
class will run for listening the command "patient info". I also assume that you have made correct configurations in your grammar files and recognition system to recognize the parts "blood pressure", "heart rate" and "patient info".
Then your code may go like this using if-else
:
public void onPartialResult(Hypothesis arg0) {
if(arg0 == null){ return; }
String command = arg0.getHypstr();
if(command.equals("blood pressure")) {
recognizer.stop();
Intent i = new Intent("edu.cmu.pocketsphinx.demo.BloodPressure");
startActivity(i);
}
else if(command.equals("heart rate")) {
recognizer.stop();
Intent j = new Intent("edu.cmu.pocketsphinx.demo.HeartRate");
startActivity(j);
}
else if(command.equals("patient info")) {
recognizer.stop();
Intent k = new Intent("edu.cmu.pocketsphinx.demo.PatientInfo");
startActivity(k);
}
}
Hope this helps