Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/292.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 将语音到文本输出设置为文本框_C#_Windows Phone 8 - Fatal编程技术网

C# 将语音到文本输出设置为文本框

C# 将语音到文本输出设置为文本框,c#,windows-phone-8,C#,Windows Phone 8,我是n00b,因此我使用此方法将语音转换为文本: private async void STT_Freeform(object sender, RoutedEventArgs e) { SpeechRecognizerUI speechRecognizer = new SpeechRecognizerUI(); speechRecognizer.Settings.ExampleText = "Fine thanks"; speechRecognizer.Settings.ListenText =

我是n00b,因此我使用此方法将语音转换为文本:

private async void STT_Freeform(object sender, RoutedEventArgs e)
{
SpeechRecognizerUI speechRecognizer = new SpeechRecognizerUI();
speechRecognizer.Settings.ExampleText = "Fine thanks";
speechRecognizer.Settings.ListenText = "How's it goin', eh?";
speechRecognizer.Settings.ReadoutEnabled = true;
speechRecognizer.Settings.ShowConfirmation = true;
SpeechRecognitionUIResult result = await speechRecognizer.RecognizeWithUIAsync();
if (result.ResultStatus == SpeechRecognitionUIStatus.Succeeded)
{
    MessageBox.Show(result.RecognitionResult.Text);
}
}


但是我想更改它,这样无论它说什么,它都会被粘贴到应用程序的文本框中,只需将结果文本分配给文本框,例如:

public partial class TestPage : PhoneApplicationPage  
    {  
        SpeechRecognizerUI speechRecognizer;  

        // Constructor  
        public TestPage ()  
        {  
            InitializeComponent();  

            this.speechRecognizer = new SpeechRecognizerUI();  
        }  

        private async void STT_Freeform(object sender, RoutedEventArgs e)  
        {  
            this.speechRecognizer.Recognizer.Grammars.Clear();  

            // Use the short message dictation grammar with the speech recognizer.  
            this.speechRecognizer.Recognizer.Grammars.AddGrammarFromPredefinedType("message", SpeechPredefinedGrammar.Dictation);  

            await this.speechRecognizer.Recognizer.PreloadGrammarsAsync();  

            try  
            {  
                // Use the built-in UI to prompt the user and get the result.  
                SpeechRecognitionUIResult recognitionResult = await this.speechRecognizer.RecognizeWithUIAsync();  

                if (recognitionResult.ResultStatus == SpeechRecognitionUIStatus.Succeeded)  
                {  
                    // Output the speech recognition result.  
                    txtDictationResult.Text = "You said: " + recognitionResult.RecognitionResult.Text;  
                }  
            }  
            catch (Exception ex)  
            {  
                MessageBox.Show(ex.Message);  
            }  
        }  

        private async void btnWebSearch_Click(object sender, RoutedEventArgs e)  
        {  
            this.speechRecognizer.Recognizer.Grammars.Clear();  

            this.speechRecognizer.Recognizer.Grammars.AddGrammarFromPredefinedType("search", SpeechPredefinedGrammar.WebSearch);  

            await this.speechRecognizer.Recognizer.PreloadGrammarsAsync();  

            try  
            {  
                // Use the built-in UI to prompt the user and get the result.  
                SpeechRecognitionUIResult recognitionResult = await this.speechRecognizer.RecognizeWithUIAsync();  

                if (recognitionResult.ResultStatus == SpeechRecognitionUIStatus.Succeeded)  
                {  
                    // Output the speech recognition result.  
                    this.txtWebSearchResult.Text = "You said: " + recognitionResult.RecognitionResult.Text;  
                }  

            }  
            catch (Exception ex)  
            {  
                MessageBox.Show(ex.Message);  
            }  
        }  
    } 

不清楚你在哪里遇到麻烦。为什么不把结果放在
文本框中,而不是显示
消息框<代码>txtResults.Text=result.RecognitionResult.Text