1

I am currently working on CMU pocketpshinx for Android and wish to separate the menu window from the other windows into activities. I am fairly new to coding and am having difficulties with it. I think my code is right, I just don't know where to place it. Any help would be great !

Here is my new activity code (I am unsure where to place it in the PocketSphinxActivity Java file):

Intent i = new Intent("edu.cmu.pocketsphinx.demo.BloodPressure");
startActivity(i)
Intent j = new Intent("edu.cmu.pocketsphinx.demo.HeartRate");
startActivity(j)
Intent k = new Intent("edu.cmu.pocketsphinx.demo.PatientInfo");
startActivity(k)
OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
Erz
  • 21
  • 5
  • Do add your code which you have already tried, it helps other understand and solve your problem better – Bishal Ghimire Sep 14 '16 at 03:26
  • I have edited my post to add the code. If you have the original Pocketsphinx android demo code, I have changed "Phones", "Forecast" etc into medical terms "BloodPressure", "HeartRate" etc – Erz Sep 14 '16 at 04:12
  • 1
    1) You can only start one Activity. 2) Place this code inside some other Activity when you want to start these – OneCricketeer Sep 14 '16 at 04:13
  • 1
    Possible duplicate of [How to start new activity on button click](http://stackoverflow.com/questions/4186021/how-to-start-new-activity-on-button-click) – OneCricketeer Sep 14 '16 at 04:14
  • I want to start three different activities from the one activity. Each activity is opened by a different voice command. – Erz Sep 14 '16 at 04:24

1 Answers1

0

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

UkFLSUI
  • 5,509
  • 6
  • 32
  • 47