如何让 Speech to Text 在 Windows (Phone) 8.1 通用应用程序中工作 [英] How do you make Speech to Text work in Windows (Phone) 8.1 Universal App

查看:41
本文介绍了如何让 Speech to Text 在 Windows (Phone) 8.1 通用应用程序中工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编写代码来大声朗读传入的 Toast(这在 WP8.1 中是微不足道的)到目前为止我有这个

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

  • 无论是在电话上还是在模拟器
  • 使用 BackgroundMediaPlayer 可以在模拟器中使用,但不能在手机上使用

我已经从 UI 线程(MediaElement 仅适用于 UI 线程)和处理传入 toast 的线程中的 BackgroundMediaPlayer 进行了尝试

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();
    }
}

我显然在这里遗漏了一些简单的东西,但我不知道如何进行这项工作.SSML 是正确的,我认为这可能与范围和线程有关

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

推荐答案

     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();

这篇关于如何让 Speech to Text 在 Windows (Phone) 8.1 通用应用程序中工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆