I have the following C++/CX code:
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();
});
If my understanding is correct, it is supposed to synthesize the string This is a string of text.
into a stream that would then be played through a MediaElement
. After I execute this code, however, the lambda specified in task.then()
never runs. Am I missing something?
This works fine for me. A few possibilities:
Microphone
capability and you are swallowing an Access Denied
exception(*)Play
is throwing and you are swallowing the exception(**)DefaultVoice == nullptr
)(*) Although you're not actually using the Microphone for speech synthesis, the way the speech system works in Windows Phone you need this capability
(**) You should never call Play
immediately after setting the Source
; you must wait for the MediaOpened
event to be raised (or, in this case, rely on AutoPlay
to do the work for you).