How do you make Speech to Text work in Windows (Phone) 8.1 Universal App

烂漫一生 提交于 2019-12-11 18:23:01

问题


I'm trying to write code to read aloud an incoming Toast (this was trivial in WP8.1) I have this so far

  • Using MediaElement doesn't seem to work (code runs but no audio) either on the phone or in the emulator
  • Using BackgroundMediaPlayer works in the emulator but not on the phone

I've tried both from the UI thread (MediaElement only works on the UI thread) and BackgroundMediaPlayer from the thread that handles the incoming toast

var mediaElement = new MediaElement();
using (var tts = new SpeechSynthesizer())
{
    using (var ttsStream = await tts.SynthesizeSsmlToStreamAsync(ssml))
    {
        //BackgroundMediaPlayer.Current.SetStreamSource(ttsStream);
        mediaElement.SetSource(ttsStream, ttsStream.ContentType);
        mediaElement.Play();
    }
}

I'm obviously missing something simple here but I'm out of ideas how to make this work. The SSML is correct, I think it's probably something to do with scoping and threads


回答1:


     var synth = new SpeechSynthesizer();
     var voice = SpeechSynthesizer.DefaultVoice;
     var newuserText = TheMessage
     var stream = await synth.SynthesizeTextToStreamAsync(newuserText);
     var mediaElement = new MediaElement();
     mediaElement.SetSource(stream, stream.ContentType);
     mediaElement.Play();


来源:https://stackoverflow.com/questions/25880379/how-do-you-make-speech-to-text-work-in-windows-phone-8-1-universal-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!