예제 #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();
        }