【发布时间】:2017-09-16 17:07:42
【问题描述】:
我能找到的每个 UWP 文本转语音示例都使用使用 XAML 创建的 MediaElement 控件。例如,像这样的东西,效果很好:
using namespace Windows::Media::SpeechSynthesis;
//..........
void App::MainPage::buttonSpeak_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
create_task(synthesizer->SynthesizeTextToStreamAsync(L"I am ready."))
.then([this](SpeechSynthesisStream ^stream)
{
MediaElement ^media = mediaElement; //created in a separate XAML file
media->AutoPlay = true;
media->SetSource(stream, stream->ContentType);
media->Play();
});
}
在没有基于 XAML 的界面(在我的例子中是全息 DirectX 应用程序)的情况下,如何调整它以使其工作?我尝试过以编程方式创建 MediaElement,例如。 G。 MediaElement ^media = ref new MediaElement();,总是抛出"The application called an interface that was marshalled for a different thread"异常。
【问题讨论】:
标签: uwp text-to-speech c++-cx