朗读
//朗读选中文本 private async void OnRead(object sender, RoutedEventArgs e) { string Text2Read = redit.Document.Selection.Text; if (Text2Read != "") { SpeechSynthesizer synthesizer = new SpeechSynthesizer(); SpeechSynthesisStream stream = await synthesizer.SynthesizeTextToStreamAsync(Text2Read); //Me为MediaElement AutoPlay true; Me.SetSource(stream,stream.ContentType); } }
识别
//识别语音输入 public async Task<string> BegiRecongnize() { string Result = ""; try { using (SpeechRecognizer recognizer = new SpeechRecognizer()) { SpeechRecognitionCompilationResult compilationResult = await recognizer.CompileConstraintsAsync(); if (compilationResult.Status == SpeechRecognitionResultStatus.Success) { recognizer.UIOptions.IsReadBackEnabled = false; recognizer.UIOptions.ShowConfirmation = false; recognizer.UIOptions.AudiblePrompt = "我在听,请说..."; SpeechRecognitionResult recognitionResult = await recognizer.RecognizeWithUIAsync(); //SpeechRecognitionResult recognitionResult = await recognizer.RecognizeAsync(); if (recognitionResult.Status == SpeechRecognitionResultStatus.Success) { Result = recognitionResult.Text; } } } } catch (Exception ex) { Result = ex.Message; } return Result; }