Пример #1
0
        public static void main(string[] args)
        {
            Configuration configuration = new Configuration();

            configuration.setAcousticModelPath("resource:/edu/cmu/sphinx/models/en-us/en-us");
            configuration.setDictionaryPath("resource:/edu/cmu/sphinx/models/en-us/cmudict-en-us.dict");
            configuration.setGrammarPath("resource:/edu/cmu/sphinx/demo/dialog/");
            configuration.setUseGrammar(true);
            configuration.setGrammarName("dialog");
            LiveSpeechRecognizer liveSpeechRecognizer = new LiveSpeechRecognizer(configuration);

            configuration.setGrammarName("digits.grxml");
            LiveSpeechRecognizer liveSpeechRecognizer2 = new LiveSpeechRecognizer(configuration);

            configuration.setUseGrammar(false);
            configuration.setLanguageModelPath("resource:/edu/cmu/sphinx/demo/dialog/weather.lm");
            LiveSpeechRecognizer liveSpeechRecognizer3 = new LiveSpeechRecognizer(configuration);

            liveSpeechRecognizer.startRecognition(true);
            for (;;)
            {
                [email protected]("Choose menu item:");
                [email protected]("Example: go to the bank account");
                [email protected]("Example: exit the program");
                [email protected]("Example: weather forecast");
                [email protected]("Example: digits\n");
                string hypothesis = liveSpeechRecognizer.getResult().getHypothesis();
                if (String.instancehelper_startsWith(hypothesis, "exit"))
                {
                    break;
                }
                if (String.instancehelper_equals(hypothesis, "digits"))
                {
                    liveSpeechRecognizer.stopRecognition();
                    DialogDemo.recognizeDigits(liveSpeechRecognizer2);
                    liveSpeechRecognizer.startRecognition(true);
                }
                if (String.instancehelper_equals(hypothesis, "bank account"))
                {
                    liveSpeechRecognizer.stopRecognition();
                    DialogDemo.recognizerBankAccount(liveSpeechRecognizer);
                    liveSpeechRecognizer.startRecognition(true);
                }
                if (String.instancehelper_endsWith(hypothesis, "weather forecast"))
                {
                    liveSpeechRecognizer.stopRecognition();
                    DialogDemo.recognizeWeather(liveSpeechRecognizer3);
                    liveSpeechRecognizer.startRecognition(true);
                }
            }
            liveSpeechRecognizer.stopRecognition();
        }
Пример #2
0
        private static void recognizerBankAccount(LiveSpeechRecognizer liveSpeechRecognizer)
        {
            [email protected]("This is bank account voice menu");
            [email protected]("-------------------------------");
            [email protected]("Example: balance");
            [email protected]("Example: withdraw zero point five");
            [email protected]("Example: deposit one two three");
            [email protected]("Example: back");
            [email protected]("-------------------------------");
            double num = (double)0f;

            liveSpeechRecognizer.startRecognition(true);
            for (;;)
            {
                string hypothesis = liveSpeechRecognizer.getResult().getHypothesis();
                if (String.instancehelper_endsWith(hypothesis, "back"))
                {
                    break;
                }
                if (String.instancehelper_startsWith(hypothesis, "deposit"))
                {
                    double num2 = DialogDemo.parseNumber(String.instancehelper_split(hypothesis, "\\s"));
                    num += num2;
                    [email protected]("Deposited: $%.2f\n", new object[]
                    {
                        Double.valueOf(num2)
                    });
                }
                else if (String.instancehelper_startsWith(hypothesis, "withdraw"))
                {
                    double num2 = DialogDemo.parseNumber(String.instancehelper_split(hypothesis, "\\s"));
                    num -= num2;
                    [email protected]("Withdrawn: $%.2f\n", new object[]
                    {
                        Double.valueOf(num2)
                    });
                }
                else if (!String.instancehelper_endsWith(hypothesis, "balance"))
                {
                    [email protected](new StringBuilder().append("Unrecognized command: ").append(hypothesis).toString());
                }
                [email protected]("Your savings: $%.2f\n", new object[]
                {
                    Double.valueOf(num)
                });
            }
            liveSpeechRecognizer.stopRecognition();
        }
Пример #3
0
 private static void recognizeWeather(LiveSpeechRecognizer liveSpeechRecognizer)
 {
     [email protected]("Try some forecast. End with \"the end\"");
     [email protected]("-------------------------------------");
     [email protected]("Example: mostly dry some fog patches tonight");
     [email protected]("Example: sunny spells on wednesday");
     [email protected]("-------------------------------------");
     liveSpeechRecognizer.startRecognition(true);
     for (;;)
     {
         string hypothesis = liveSpeechRecognizer.getResult().getHypothesis();
         if (String.instancehelper_equals(hypothesis, "the end"))
         {
             break;
         }
         [email protected](hypothesis);
     }
     liveSpeechRecognizer.stopRecognition();
 }
Пример #4
0
 private static void recognizeDigits(LiveSpeechRecognizer liveSpeechRecognizer)
 {
     [email protected]("Digits recognition (using GrXML)");
     [email protected]("--------------------------------");
     [email protected]("Example: one two three");
     [email protected]("Say \"101\" to exit");
     [email protected]("--------------------------------");
     liveSpeechRecognizer.startRecognition(true);
     for (;;)
     {
         string hypothesis = liveSpeechRecognizer.getResult().getHypothesis();
         if (String.instancehelper_equals(hypothesis, "one zero one"))
         {
             break;
         }
         if (String.instancehelper_equals(hypothesis, "one oh one"))
         {
             break;
         }
         [email protected](hypothesis);
     }
     liveSpeechRecognizer.stopRecognition();
 }