C# Windows Phone 8语音合成器暂停
我正在开发一个应用程序,我想在SpeechSynthesizer.SpeakTextAsync运行期间暂停,然后从那里恢复C# Windows Phone 8语音合成器暂停,c#,windows-phone-8,speech-synthesis,speechsynthesizer,C#,Windows Phone 8,Speech Synthesis,Speechsynthesizer,我正在开发一个应用程序,我想在SpeechSynthesizer.SpeakTextAsync运行期间暂停,然后从那里恢复 await synthesizer.SpeakTextAsync(text); 当var stop=true时停止读取不久前有人在这里发帖,同时我刷新了页面,阅读了他的答案,看到了一个通知&再次刷新页面&答案不见了。但不管是谁发的,他都是救命恩人。它一直萦绕在我的脑海里,我最终创造了这个 String text; // your text to read out
await synthesizer.SpeakTextAsync(text);
当
var stop=true时停止读取代码>不久前有人在这里发帖,同时我刷新了页面,阅读了他的答案,看到了一个通知&再次刷新页面&答案不见了。但不管是谁发的,他都是救命恩人。它一直萦绕在我的脑海里,我最终创造了这个
String text; // your text to read out loud
String[] parts = text.Split(' ');
int max = parts.Length;
int count = 0;
private String makeSSML() {
if (count == max) {
count= 0;
}
String s = "<speak version=\"1.0\" ";
s += "xmlns=\"http://www.w3.org/2001/10/synthesis\" xml:lang=\"en-US\">";
for (int i = count; i < max; i++)
{
s += parts[i];
s += "<mark name=\"anything\"/>";
}
s += "<mark name=\"END\"/>";
s += "</speak>";
return s;
}
private void playIT(){
synth = new SpeechSynthesizer();
synth.BookmarkReached += synth_BookmarkReached;
synth.SpeakSsmlAsync(makeSSML());
}
private void synth_BookmarkReached(object sender, SpeechBookmarkReachedEventArgs e)
{
count++;
if (e.Bookmark == "END") {
synth.Dispose();
}
}
private void Pause_Click(object sender, RoutedEventArgs e)
{
synth.Dispose();
}
字符串文本;//你的文字要大声读出来
String[]parts=text.Split(“”);
int max=零件长度;
整数计数=0;
私有字符串makeSSML(){
如果(count==max){
计数=0;
}
字符串s=“”;
对于(int i=计数;i
谢谢你,伙计,你的回答给了我这个想法。不久前有人在这里发帖,同时我刷新了页面,阅读了他的答案,看到了一个通知&再次刷新页面&答案不见了。但不管是谁发的,他都是救命恩人。它一直萦绕在我的脑海里,我最终创造了这个
String text; // your text to read out loud
String[] parts = text.Split(' ');
int max = parts.Length;
int count = 0;
private String makeSSML() {
if (count == max) {
count= 0;
}
String s = "<speak version=\"1.0\" ";
s += "xmlns=\"http://www.w3.org/2001/10/synthesis\" xml:lang=\"en-US\">";
for (int i = count; i < max; i++)
{
s += parts[i];
s += "<mark name=\"anything\"/>";
}
s += "<mark name=\"END\"/>";
s += "</speak>";
return s;
}
private void playIT(){
synth = new SpeechSynthesizer();
synth.BookmarkReached += synth_BookmarkReached;
synth.SpeakSsmlAsync(makeSSML());
}
private void synth_BookmarkReached(object sender, SpeechBookmarkReachedEventArgs e)
{
count++;
if (e.Bookmark == "END") {
synth.Dispose();
}
}
private void Pause_Click(object sender, RoutedEventArgs e)
{
synth.Dispose();
}
字符串文本;//你的文字要大声读出来
String[]parts=text.Split(“”);
int max=零件长度;
整数计数=0;
私有字符串makeSSML(){
如果(count==max){
计数=0;
}
字符串s=“”;
对于(int i=计数;i
谢谢,伙计,你的回答给了我这个想法。根据文档,当你调用cancelall
时,你正在取消异步执行的任务。根据约定,这将导致抛出操作取消异常。这意味着,无论您在哪里调用SpeakTextAsync、SpeakSsmlAsync或SpeakSsmlFromUriAsync,都必须使用try/catch语句来包围这些调用,以防止此异常未被捕获
示例:
private static SpeechSynthesizer synth;
public async static Task<SpeechSynthesizer> SpeechSynth(string dataToSpeak)
{
synth = new SpeechSynthesizer();
IEnumerable<VoiceInformation> englishVoices = from voice in InstalledVoices.All
where voice.Language == "en-US"
&& voice.Gender.Equals(VoiceGender.Female)
select voice;
if (englishVoices.Count() > 0)
{
synth.SetVoice(englishVoices.ElementAt(0));
}
await synth.SpeakTextAsync(dataToSpeak);
return synth;
}
public static void CancelSpeech()
{
synth.CancelAll();
}
专用静态语音合成器synth;
公共异步静态任务SpeechSynth(字符串dataToSpeak)
{
synth=新的语音合成器();
IEnumerable englishVoices=来自安装语音中的语音。全部
其中voice.Language==“en-US”
&&声音。性别。平等(声音性别。女性)
选择语音;
if(englishVoices.Count()>0)
{
synth.SetVoice(englishVoices.ElementAt(0));
}
等待synth.SpeakTextAsync(dataToSpeak);
返回合成器;
}
公共静态语音
{
synth.CancelAll();
}
现在,在需要的地方调用SpeechSynth(“一些要说话的数据”)
,无论何时,只要想取消它,就调用CancelSpeech()
完成了!享受 根据文档,当您调用cancelall
时,您正在取消异步执行的任务。根据约定,这将导致抛出操作取消异常。这意味着,无论您在哪里调用SpeakTextAsync、SpeakSsmlAsync或SpeakSsmlFromUriAsync,都必须使用try/catch语句来包围这些调用,以防止此异常未被捕获
示例:
private static SpeechSynthesizer synth;
public async static Task<SpeechSynthesizer> SpeechSynth(string dataToSpeak)
{
synth = new SpeechSynthesizer();
IEnumerable<VoiceInformation> englishVoices = from voice in InstalledVoices.All
where voice.Language == "en-US"
&& voice.Gender.Equals(VoiceGender.Female)
select voice;
if (englishVoices.Count() > 0)
{
synth.SetVoice(englishVoices.ElementAt(0));
}
await synth.SpeakTextAsync(dataToSpeak);
return synth;
}
public static void CancelSpeech()
{
synth.CancelAll();
}
专用静态语音合成器synth;
公共异步静态任务SpeechSynth(字符串dataToSpeak)
{
synth=新的语音合成器();
IEnumerable englishVoices=来自安装语音中的语音。全部
其中voice.Language==“en-US”
&&声音。性别。平等(声音性别。女性)
选择语音;
if(englishVoices.Count()>0)
{
synth.SetVoice(englishVoices.ElementAt(0));
}
等待synth.SpeakTextAsync(dataToSpeak);
返回合成器;
}
公共静态语音
{
synth.CancelAll();
}
现在,在需要的地方调用SpeechSynth(“一些要说话的数据”)
,无论何时,只要想取消它,就调用CancelSpeech()
完成了!享受