我试图在我的wp8&中尝试实现文本到语音转换(TTS)。 8.1使用mvvm模式实现的应用程序。
我可以开始阅读文本,取消阅读工作正常但我需要找出文本何时被阅读,因为我需要重置我的ViewModel中的一些属性,即IsReading
/ IsNotReading
用于显示/隐藏按钮。
我确实花了最后几个小时从文章到文章,但无济于事。当然必须有办法!
我目前正在使用SpeakTextAsync
并且在wp8和wp8.1中工作正常,但是它是否支持一种知道何时完成文本阅读的方法?
当我尝试使用' SpeakSsmlAsync'时,我相信支持标记/书签,我想在我的文本末尾添加书签并在BookmarkReached
事件中捕获它然后重置我的各种ViewModel的属性,但每当我调用' SpeakSsmlAsync'我收到以下错误:
An exception of type 'System.FormatException' occurred in myapp.DLL
but was not handled in user code
WinRT information: The text associated with this error code could not
be found.
Additional information: The text associated with this error code could
not be found.
The text associated with this error code could not be found.
If there is a handler for this exception, the program may be safely
continued.`
它提到了WINRT,但这两个应用都在Silverlight中,所以虽然异常不具有描述性,但是SpeakSsmlAsync
?是什么导致了这个错误?
感谢。
答案 0 :(得分:1)
SpeakTextAsync返回一个任务,您可以等待以任何标准方式完成任务。最简单的是等待它:
private async void speak_Click(object sender, RoutedEventArgs e)
{
speakingState.Text = "Speaking...";
await speechSynth.SpeakTextAsync("A quick brown fox jumps over the lazy dog");
speakingState.Text = "... done";
}
System.FormatException可能意味着您传递了无效的Ssml。你不会说你用过的东西,但这里有一个工作样本:
private async void speakSsml_Click(object sender, RoutedEventArgs e)
{
speakingState.Text = "Speaking...";
string speakText =
@"<speak version=""1.0"" xmlns=""http://www.w3.org/2001/10/synthesis"" xml:lang=""en-US"">
<s>A quick brown fox <mark name=""middle""/> jumps over the lazy dog<mark name=""end""/></s>
</speak>";
await speechSynth.SpeakSsmlAsync(speakText);
speakingState.Text = "... done";
}