Windows phone 8.1 SpeechSynthesizer::SynthesizeTextToStreamAsync函数将永远使用

Windows phone 8.1 SpeechSynthesizer::SynthesizeTextToStreamAsync函数将永远使用,windows-phone-8.1,text-to-speech,c++-cx,speech-synthesis,Windows Phone 8.1,Text To Speech,C++ Cx,Speech Synthesis,我有以下C++/CX代码: Windows::Media::SpeechSynthesis::SpeechSynthesizer^ synth = ref new Windows::Media::SpeechSynthesis::SpeechSynthesizer(); Platform::String^ text = "This is a string of text."; concurrency::create_task(synth->SynthesizeTextToStreamAsy

我有以下C++/CX代码:

Windows::Media::SpeechSynthesis::SpeechSynthesizer^ synth = ref new Windows::Media::SpeechSynthesis::SpeechSynthesizer();
Platform::String^ text = "This is a string of text.";
concurrency::create_task(synth->SynthesizeTextToStreamAsync(text))
  .then([&](Windows::Media::SpeechSynthesis::SpeechSynthesisStream^ stream) {
      mediaElement->AutoPlay = true;
      mediaElement->SetSource(stream, stream->ContentType);
      mediaElement->Play();
  });

如果我的理解是正确的,它应该将字符串
这是一个文本字符串。
合成为一个流,然后通过
媒体元素播放。但是,在执行此代码之后,
task.then()
中指定的lambda将永远不会运行。我错过了什么吗?

这对我来说很好。有几种可能性:

  • 您没有
    麦克风
    功能,您正在吞下一个
    访问被拒绝
    异常(*)
  • 调用
    Play
    正在抛出异常,您正在吞咽异常(**)
  • 您正在未安装默认语音语言的设备上运行(
    DefaultVoice==nullptr
  • (*)虽然您实际上并没有使用麦克风进行语音合成,但按照Windows Phone中语音系统的工作方式,您需要此功能


    (**)设置
    源代码后,决不能立即调用
    Play
    ;您必须等待
    MediaOpened
    事件被引发(或者,在这种情况下,依靠
    自动播放
    来为您完成工作)。

    我确实拥有
    麦克风
    功能,声明在我的
    appxmanifest
    中。我尝试从
    AllVoices
    列表中手动设置一个语音,并将所有代码放在try/catch块中,没有抛出异常。问题不在于
    MediaElement
    本身,而在于
    SynthesizeTextToStreamAsync()
    方法。正如我所说,它永远运行,并且永远不会运行
    任务中指定的lambda。then()
    。我实际上碰到过一次这个问题,并且不得不重新启动设备/模拟器来修复它。基本上,合成呼叫只工作过一次,但再也没有工作过。尝试重新启动SpeechSynthesizer对象,并确保在该对象为您提供帮助时关闭它。