Пример #1
0
 /// <summary>
 /// Rises the SpeechHypothesized event
 /// </summary>
 protected virtual void OnFileSpeechHypothesized(RecognizedSpeech recognizedSpeech)
 {
     if (FileSpeechHypothesized != null)
     {
         FileSpeechHypothesized(this, recognizedSpeech);
     }
 }
Пример #2
0
 /// <summary>
 /// Rises the SpeechRecognized event
 /// </summary>
 protected virtual void OnSpeechRecognized(RecognizedSpeech recognizedSpeech)
 {
     if (SpeechRecognized != null)
     {
         SpeechRecognized(this, recognizedSpeech);
     }
 }
Пример #3
0
        private void reco_FileSpeechRecognitionRejected(SpeechRecognizer sender, RecognizedSpeech recognizedSpeech)
        {
            if (this.InvokeRequired)
            {
                if (!this.IsHandleCreated || this.Disposing || this.IsDisposed)
                {
                    return;
                }
                this.BeginInvoke(dlgFileSpeechRecognitionRejected, sender, recognizedSpeech);
                return;
            }

            string textToAppend;

            try
            {
                textToAppend = String.Empty;
                for (int i = 0; i < recognizedSpeech.Count; ++i)
                {
                    textToAppend += GetRecognizedPhraseDisplayText(recognizedSpeech[i]);
                }

                txtRejected.AppendText(textToAppend);
            }
            catch { }
        }
Пример #4
0
 /// <summary>
 /// Rises the SpeechRecognitionRejected event
 /// </summary>
 protected virtual void OnFileSpeechRecognitionRejected(RecognizedSpeech recognizedSpeech)
 {
     if (FileSpeechRecognitionRejected != null)
     {
         FileSpeechRecognitionRejected(this, recognizedSpeech);
     }
 }
Пример #5
0
        private void reco_SpeechHypothesized(SpeechRecognizer sender, RecognizedSpeech recognizedSpeech)
        {
            if (this.InvokeRequired)
            {
                if (!this.IsHandleCreated || this.Disposing || this.IsDisposed)
                {
                    return;
                }
                this.BeginInvoke(dlgSpeechHypothesized, sender, recognizedSpeech);
                return;
            }

            SendHypothesizedSpeech(recognizedSpeech);

            string textToAppend;

            try
            {
                textToAppend = String.Empty;
                //textToAppend = "{";
                for (int i = 0; i < recognizedSpeech.Count; ++i)
                {
                    //textToAppend += "\t";
                    textToAppend += GetRecognizedPhraseDisplayText(recognizedSpeech[i]);
                }
                //textToAppend += "}\r\n";

                txtHypothesis.AppendText(textToAppend);
            }
            catch { }
        }
Пример #6
0
        private void fileSpeechRecognizer_SpeechRecognitionRejected(object sender, SpeechRecognitionRejectedEventArgs e)
        {
            if ((e == null) || (e.Result == null) || (e.Result.Confidence < 0.1) || (e.Result.Alternates == null) || (e.Result.Alternates.Count < 1))
            {
                return;
            }
            RecognizedSpeech recognizedSpeech = GenerateRecognizedSpeechObject(e.Result.Alternates);

            OnSpeechRecognitionRejected(recognizedSpeech);
        }
Пример #7
0
 private void reco_FileSpeechHypothesized(SpeechRecognizer sender, RecognizedSpeech recognizedSpeech)
 {
     if (this.InvokeRequired)
     {
         if (!this.IsHandleCreated || this.Disposing || this.IsDisposed)
         {
             return;
         }
         this.BeginInvoke(dlgFileSpeechHypothesized, sender, recognizedSpeech);
         return;
     }
 }
Пример #8
0
        private void SendHypothesizedSpeech(RecognizedSpeech recognizedSpeech)
        {
            if (!RecognitionEnabled || (recognizedSpeech.Count < 1))
            {
                return;
            }

            if (this.shHypothesizedSpeech != null)
            {
                this.shHypothesizedSpeech.TryWrite(recognizedSpeech);
            }
        }
Пример #9
0
        private void SendRecognizedSpeech(RecognizedSpeech recognizedSpeech)
        {
            if (!RecognitionEnabled || (recognizedSpeech.Count < 1))
            {
                return;
            }

            string text = recognizedSpeech[0].Text;

            System.Text.StringBuilder sb = new System.Text.StringBuilder();
            Command cmd = new Command(this, "recognized", text, cmdMan.AutoId);

            cnnMan.Send(cmd);
            for (int i = 0; i < recognizedSpeech.Count; ++i)
            {
                sb.Append("\\\"");
                sb.Append(recognizedSpeech[i].Text);
                sb.Append("\\\" ");
                sb.Append(recognizedSpeech[i].Confidence.ToString("0.00"));
                if (i != (recognizedSpeech.Count - 1))
                {
                    sb.Append(' ');
                }
            }
            if ((this.shRecognizedSpeech != null) && this.shRecognizedSpeech.TryWrite(recognizedSpeech))
            {
                Console("Shared variable written");
            }
            cmd = new Command(this, "recognizedSpeech", sb.ToString(), cmdMan.AutoId);
            cnnMan.Send(cmd);
            Console("Sent: " + cmd.StringToSend);

            /*
             * if ((cnnMan.ConnectedClientsCount < 1) && !cnnMan.IsConnected)
             *      return;
             * if (!cmdMan.SharedVariables.Contains("recognized_speech"))
             *      cmdMan.SharedVariables.Add(new StringSharedVariable("recognized_speech"));
             * if (cmdMan.SharedVariables.Contains("recognized_speech"))
             * {
             *      try
             *      {
             *              cmdMan.SharedVariables[""].Write(text);
             *              Console("Writed variable: recognized_speech");
             *
             *      }
             *      catch { }
             * }
             */
        }
Пример #10
0
        private void speechRecognizer_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
        {
            if ((e == null) || (e.Result == null) || (e.Result.Alternates == null) || (e.Result.Alternates.Count < 1))
            {
                return;
            }

            RecognizedSpeech recognizedSpeech = GenerateRecognizedSpeechObject(e.Result.Alternates);

            OnSpeechRecognized(recognizedSpeech);
            if ((this.AutoSaveMode & AutoSaveMode.Recognized) == AutoSaveMode.Recognized)
            {
                SaveRecognized(e);
            }
        }
Пример #11
0
        private RecognizedSpeech GenerateRecognizedSpeechObject(System.Collections.ObjectModel.ReadOnlyCollection <RecognizedPhrase> engineAlternates)
        {
            RecognizedSpeechAlternate[] alternates;
            RecognizedPhrase            phrase;
            RecognizedSpeech            recognizedSpeech;

            alternates = new RecognizedSpeechAlternate[engineAlternates.Count];
            for (int i = 0; i < engineAlternates.Count; ++i)
            {
                phrase        = engineAlternates[i];
                alternates[i] = new RecognizedSpeechAlternate(phrase.Text, phrase.Confidence);
            }
            recognizedSpeech = new RecognizedSpeech(alternates);
            return(recognizedSpeech);
        }
Пример #12
0
        private void RecoContext_Recognition(int StreamNumber, object StreamPosition, SpeechRecognitionType RecognitionType, ISpeechRecoResult Result)
        {
            ////result_textBox.AppendText(Result.PhraseInfo.GetText(0, -1, true) + "\n");
            //string result;

            //ISpeechPhraseInfo info;
            //ISpeechPhraseAlternate alternate;
            //ISpeechPhraseAlternates alternates = Result.Alternates(20, 0, -1);
            //ISpeechPhraseReplacements replacements;

            //if (alternates != null)
            //    alternate = alternates.Item(0);
            //info = Result.PhraseInfo;
            //replacements = info.Replacements;
            //string rep;
            //if (replacements != null)
            //    rep = replacements.Item(0).Text;

            //result = Result.PhraseInfo.GetText(0, -1, true);
            //if (result.Length < 1) result = "???";
            //OnSpeechRecognized(null);

            ////result_textBox.AppendText(Result.PhraseInfo.GetText(0, -1, true) + "\n");
            //string result;

            string result;
            float  confidence;

            RecognizedSpeechAlternate[] alternates;
            RecognizedSpeech            recognizedSpeech;

            result     = Result.PhraseInfo.GetText(0, -1, true);
            confidence = Result.PhraseInfo.Rule.EngineConfidence;
            //confidence = Result.PhraseInfo.Rule.Confidence;
            if (result.Length < 1)
            {
                return;
            }

            alternates       = new RecognizedSpeechAlternate[1];
            alternates[0]    = new RecognizedSpeechAlternate(result, confidence);
            recognizedSpeech = new RecognizedSpeech(alternates);

            OnSpeechRecognized(recognizedSpeech);
        }
Пример #13
0
        private void reco_FileSpeechRecognized(SpeechRecognizer sender, RecognizedSpeech recognizedSpeech)
        {
            if (this.InvokeRequired)
            {
                if (!this.IsHandleCreated || this.Disposing || this.IsDisposed)
                {
                    return;
                }
                this.BeginInvoke(dlgFileSpeechRecognized, sender, recognizedSpeech);
                return;
            }

            string textToAppend;

            try
            {
                txtHypothesis.Text = "";
                txtRejected.Text   = "";

                textToAppend = recognizedSpeech.Count.ToString() + " alternate";
                if (recognizedSpeech.Count > 1)
                {
                    textToAppend += "s";
                }
                textToAppend += "\r\n{\r\n";

                for (int i = 0; i < recognizedSpeech.Count; ++i)
                {
                    textToAppend += "\t";
                    textToAppend += GetRecognizedPhraseDisplayText(recognizedSpeech[i]);
                }
                textToAppend += "}\r\n";


                if (AppendHistoryLog)
                {
                    txtRecognizedText.AppendText(textToAppend);
                }
                else
                {
                    txtRecognizedText.Text = textToAppend;
                }
            }
            catch { }
        }
Пример #14
0
        private void reco_SpeechRecognitionRejected(SpeechRecognizer sender, RecognizedSpeech recognizedSpeech)
        {
            if (this.InvokeRequired)
            {
                if (!this.IsHandleCreated || this.Disposing || this.IsDisposed)
                {
                    return;
                }
                this.BeginInvoke(dlgSpeechRecognitionRejected, sender, recognizedSpeech);
                return;
            }

            string textToAppend;

            try
            {
                textToAppend = String.Empty;
                //textToAppend = "{";
                for (int i = 0; i < recognizedSpeech.Count; ++i)
                {
                    //textToAppend += "\t";
                    textToAppend += GetRecognizedPhraseDisplayText(recognizedSpeech[i]);
                }
                //textToAppend += "}\r\n";

                txtRejected.AppendText(textToAppend);
                //if (sendRejected)
                //{
                //    txtHypothesis.Text = "";
                //    if (currentRecognitionMaxVolumeLevel > volumeTreshold)
                //        txtRecognizedText.AppendText("*" + recoResult.Text + " (rejected, volume under trshold)\r\n");
                //    else
                //    {
                //        txtRecognizedText.AppendText("*" + recoResult.Text + " (rejected)\r\n");
                //        SendRecognizedText(recoResult.Text);
                //    }
                //}
                currentRecognitionMaxVolumeLevel = 0;
            }
            catch { }
        }
Пример #15
0
        private void SpeechRecognizer_Hypothesis(int StreamNumber, object StreamPosition, ISpeechRecoResult Result)
        {
            string result;
            float  confidence;

            RecognizedSpeechAlternate[] alternates;
            RecognizedSpeech            recognizedSpeech;

            result     = Result.PhraseInfo.GetText(0, -1, true);
            confidence = Result.PhraseInfo.Rule.EngineConfidence;
            if (result.Length < 1)
            {
                return;
            }

            alternates       = new RecognizedSpeechAlternate[1];
            alternates[0]    = new RecognizedSpeechAlternate(result, confidence);
            recognizedSpeech = new RecognizedSpeech(alternates);

            OnSpeechHypothesized(recognizedSpeech);
        }
Пример #16
0
        private void SpeechRecognizer_Hypothesis(int StreamNumber, object StreamPosition, ISpeechRecoResult Result)
        {
            string result;
            float confidence;
            RecognizedSpeechAlternate[] alternates;
            RecognizedSpeech recognizedSpeech;

            result = Result.PhraseInfo.GetText(0, -1, true);
            confidence = Result.PhraseInfo.Rule.EngineConfidence;
            if (result.Length < 1)
                return;

            alternates = new RecognizedSpeechAlternate[1];
            alternates[0] = new RecognizedSpeechAlternate(result, confidence);
            recognizedSpeech = new RecognizedSpeech(alternates);

            OnSpeechHypothesized(recognizedSpeech);
        }
Пример #17
0
        private void reco_SpeechRecognized(SpeechRecognizer sender, RecognizedSpeech recognizedSpeech)
        {
            if (this.InvokeRequired)
            {
                if (!this.IsHandleCreated || this.Disposing || this.IsDisposed)
                {
                    return;
                }
                this.BeginInvoke(dlgSpeechRecognized, sender, recognizedSpeech);
                return;
            }

            string textToAppend;

            try
            {
                if (currentRecognitionMaxVolumeLevel >= volumeTreshold)
                {
                    SendRecognizedSpeech(recognizedSpeech);
                }

                txtHypothesis.Text = "";
                txtRejected.Text   = "";

                //textToAppend = String.Empty;
                textToAppend = recognizedSpeech.Count.ToString() + " alternate";
                if (recognizedSpeech.Count > 1)
                {
                    textToAppend += "s";
                }
                textToAppend += "\r\n{\r\n";

                for (int i = 0; i < recognizedSpeech.Count; ++i)
                {
                    textToAppend += "\t";
                    textToAppend += GetRecognizedPhraseDisplayText(recognizedSpeech[i]);
                }
                textToAppend += "}\r\n";



                if (currentRecognitionMaxVolumeLevel < volumeTreshold)
                {
                    textToAppend += " (Not sent due to low volume)\r\n";
                }
                currentRecognitionMaxVolumeLevel = 0;

                if (AppendHistoryLog)
                {
                    txtRecognizedText.AppendText(textToAppend);
                }
                else
                {
                    txtRecognizedText.Text = textToAppend;
                }
            }
            catch { }

            /*
             * if (expectedPhraseList.Count > 0)
             * {
             *      if (MatchExpectedWords(recoResult.Text))
             *      {
             *              txtRecognizedText.AppendText(" (Expected!!!)");
             *              SendRecognizedText(recoResult.Text);
             *      }
             *      else
             *              txtRecognizedText.AppendText(" (Unexpected)");
             *      currentRecognitionMaxVolumeLevel = 0;
             *      txtRecognizedText.AppendText("\r\n");
             *      return;
             * }
             */
        }
Пример #18
0
        private void RecoContext_Recognition(int StreamNumber, object StreamPosition, SpeechRecognitionType RecognitionType, ISpeechRecoResult Result)
        {
            ////result_textBox.AppendText(Result.PhraseInfo.GetText(0, -1, true) + "\n");
            //string result;

            //ISpeechPhraseInfo info;
            //ISpeechPhraseAlternate alternate;
            //ISpeechPhraseAlternates alternates = Result.Alternates(20, 0, -1);
            //ISpeechPhraseReplacements replacements;

            //if (alternates != null)
            //    alternate = alternates.Item(0);
            //info = Result.PhraseInfo;
            //replacements = info.Replacements;
            //string rep;
            //if (replacements != null)
            //    rep = replacements.Item(0).Text;

            //result = Result.PhraseInfo.GetText(0, -1, true);
            //if (result.Length < 1) result = "???";
            //OnSpeechRecognized(null);

            ////result_textBox.AppendText(Result.PhraseInfo.GetText(0, -1, true) + "\n");
            //string result;

            string result;
            float confidence;
            RecognizedSpeechAlternate[] alternates;
            RecognizedSpeech recognizedSpeech;

            result = Result.PhraseInfo.GetText(0, -1, true);
            confidence = Result.PhraseInfo.Rule.EngineConfidence;
            //confidence = Result.PhraseInfo.Rule.Confidence;
            if (result.Length < 1)
                return;

            alternates = new RecognizedSpeechAlternate[1];
            alternates[0] = new RecognizedSpeechAlternate(result, confidence);
            recognizedSpeech = new RecognizedSpeech(alternates);

            OnSpeechRecognized(recognizedSpeech);
        }
Пример #19
0
 /// <summary>
 /// Rises the SpeechRecognized event
 /// </summary>
 protected virtual void OnFileSpeechRecognized(RecognizedSpeech recognizedSpeech)
 {
     if (FileSpeechRecognized != null)
         FileSpeechRecognized(this, recognizedSpeech);
 }
Пример #20
0
        private RecognizedSpeech GenerateRecognizedSpeechObject(System.Collections.ObjectModel.ReadOnlyCollection<RecognizedPhrase> engineAlternates)
        {
            RecognizedSpeechAlternate[] alternates;
            RecognizedPhrase phrase;
            RecognizedSpeech recognizedSpeech;

            alternates = new RecognizedSpeechAlternate[engineAlternates.Count];
            for (int i = 0; i < engineAlternates.Count; ++i)
            {
                phrase = engineAlternates[i];
                alternates[i] = new RecognizedSpeechAlternate(phrase.Text, phrase.Confidence);
            }
            recognizedSpeech = new RecognizedSpeech(alternates);
            return recognizedSpeech;
        }
Пример #21
0
 /// <summary>
 /// Rises the SpeechRecognized event
 /// </summary>
 protected virtual void OnSpeechRecognized(RecognizedSpeech recognizedSpeech)
 {
     if (SpeechRecognized != null)
         SpeechRecognized(this, recognizedSpeech);
 }