我是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);
}
}
但我想改变它,无论它说什么,它都会被粘贴到应用程序内的TextBox上
答案 0 :(得分:0)
只需将结果文本分配给文本框,例如:
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);
}
}
}