コード例 #1
0
        public SpeechRecognitionManager(Configuration config)
        {
            this.config = config;

            dialogueMinimumConfidence = float.Parse(config.Get("SpeechRecognition", "dialogueMinConfidence", "0.5"), CultureInfo.InvariantCulture);
            commandMinimumConfidence  = float.Parse(config.Get("SpeechRecognition", "commandMinConfidence", "0.7"), CultureInfo.InvariantCulture);
            logAudioSignalIssues      = config.Get("SpeechRecognition", "bLogAudioSignalIssues", "0") == "1";

            Trace.TraceInformation("Locale: {0}\nDialogueConfidence: {1}\nCommandConfidence: {2}", config.GetLocale(), dialogueMinimumConfidence, commandMinimumConfidence);

            pauseAudioFile  = config.Get("SpeechRecognition", "pauseAudioFile", DEFAULT_PAUSE_AUDIO_FILE).Trim();
            resumeAudioFile = config.Get("SpeechRecognition", "resumeAudioFile", DEFAULT_RESUME_AUDIO_FILE).Trim();

            List <string> pausePhraseStrings  = config.GetPausePhrases();
            List <string> resumePhraseStrings = config.GetResumePhrases();

            foreach (string phrase in pausePhraseStrings)
            {
                if (phrase == null || phrase.Trim() == "")
                {
                    continue;
                }
                Trace.TraceInformation("Found pause phrase: '{0}'", phrase);
                try {
                    Grammar g = Phrases.createGrammar(Phrases.normalize(phrase, config), config);
                    pausePhrases.Add(g);
                } catch (Exception ex) {
                    Trace.TraceError("Failed to create grammar for pause phrase {0} due to exception:\n{1}", phrase, ex.ToString());
                }
            }
            foreach (string phrase in resumePhraseStrings)
            {
                if (phrase == null || phrase.Trim() == "")
                {
                    continue;
                }
                Trace.TraceInformation("Found resume phrase: '{0}'", phrase);
                try {
                    Grammar g = Phrases.createGrammar(Phrases.normalize(phrase, config), config);
                    resumePhrases.Add(g);
                } catch (Exception ex) {
                    Trace.TraceError("Failed to create grammar for resume phrase {0} due to exception:\n{1}", phrase, ex.ToString());
                }
            }

            this.DSN = new SpeechRecognitionEngine(config.GetLocale());
            this.DSN.UpdateRecognizerSetting("CFGConfidenceRejectionThreshold", 10); // Range is 0-100
            this.DSN.EndSilenceTimeoutAmbiguous  = TimeSpan.FromMilliseconds(250);
            this.DSN.AudioStateChanged          += DSN_AudioStateChanged;
            this.DSN.AudioSignalProblemOccurred += DSN_AudioSignalProblemOccurred;
            this.DSN.SpeechRecognized           += DSN_SpeechRecognized;
            this.DSN.SpeechRecognitionRejected  += DSN_SpeechRecognitionRejected;
            this.deviceEnum.RegisterEndpointNotificationCallback(this);

            WaitRecordingDeviceNonBlocking();
        }
コード例 #2
0
        public static CommandList FromIniSection(IniData ini, string sectionName, Configuration config)
        {
            KeyDataCollection sectionData = ini.Sections[sectionName];
            CommandList       list        = new CommandList();

            if (sectionData != null)
            {
                foreach (KeyData key in sectionData)
                {
                    string value = key.Value.Trim();
                    if (value.Length == 0)
                    {
                        Trace.TraceInformation("Ignore empty command '{0}'", key.KeyName);
                        continue;
                    }
                    Grammar grammar;
                    if (value[0] == '@')
                    {
                        string path = config.ResolveFilePath(value.Substring(1));
                        if (path == null)
                        {
                            Trace.TraceError("Cannot find the SRGS XML file '{0}', key: {1}", value.Substring(1), key.KeyName);
                            continue;
                        }

                        // load a SRGS XML file
                        XmlDocument doc = new XmlDocument();
                        doc.Load(path);

                        // If xml:lang in the file does not match the DSN's locale, the grammar cannot be loaded.
                        XmlAttribute xmlLang = doc.CreateAttribute("xml:lang");
                        xmlLang.Value = config.GetLocale().Name;
                        doc.DocumentElement.SetAttributeNode(xmlLang);

                        MemoryStream xmlStream = new MemoryStream();
                        doc.Save(xmlStream);
                        xmlStream.Flush(); //Adjust this if you want read your data
                        xmlStream.Position = 0;

                        grammar = new Grammar(xmlStream);
                    }
                    else
                    {
                        grammar = Phrases.createGrammar(Phrases.normalize(key.KeyName, config), config);
                    }
                    grammar.Name = key.KeyName;
                    list.commandsByPhrase[grammar] = value;
                }
            }
            return(list);
        }
コード例 #3
0
        private DialogueList(long id, List <string> lines, Configuration config)
        {
            this.id     = id;
            this.config = config;

            List <string> goodbyePhrases = config.GetGoodbyePhrases();

            for (int i = 0; i < lines.Count; i++)
            {
                string line = lines[i];
                if (line == null || line.Trim() == "")
                {
                    continue;
                }
                try {
                    Grammar g = Phrases.createGrammar(line, config, config.IsSubsetMatchingEnabled());
                    grammarToIndex[g] = i;
                }
                catch (Exception ex) {
                    Trace.TraceError("Failed to create grammar for line {0} due to exception:\n{1}", line, ex.ToString());
                }
            }

            foreach (string phrase in goodbyePhrases)
            {
                if (phrase == null || phrase.Trim() == "")
                {
                    continue;
                }
                Trace.TraceInformation("Found goodbye phrase: '{0}'", phrase);
                try {
                    Grammar g = Phrases.createGrammar(phrase, config, config.IsSubsetMatchingEnabled());
                    grammarToIndex[g] = -2;
                } catch (Exception ex) {
                    Trace.TraceError("Failed to create grammar for exit dialogue phrase {0} due to exception:\n{1}", phrase, ex.ToString());
                }
            }
        }