Javascript WebSpeech语音合成:暂停话语1,播放另一个话语2,然后恢复话语1-可能吗?

Javascript WebSpeech语音合成:暂停话语1,播放另一个话语2,然后恢复话语1-可能吗?,javascript,html,speech-synthesis,webspeech-api,Javascript,Html,Speech Synthesis,Webspeech Api,我正在使用WebSpeech的speechSynthesis模块来创建一个web应用程序speak。但是,似乎只能将语句添加到队列中,然后暂停()、恢复()和取消()整个队列 我想有两种表达方式: utterance1 = new SpeechSynthesisUtterance(text1); utterance2 = new SpeechSynthesisUtterance(text2); 我想让UTHECTANS1播放,然后在中间暂停,用UpthReal2播放,然后恢复发音。在代码中,它

我正在使用WebSpeech的speechSynthesis模块来创建一个web应用程序speak。但是,似乎只能将语句添加到队列中,然后暂停()、恢复()和取消()整个队列

我想有两种表达方式:

utterance1 = new SpeechSynthesisUtterance(text1);
utterance2 = new SpeechSynthesisUtterance(text2);

我想让UTHECTANS1播放,然后在中间暂停,用UpthReal2播放,然后恢复发音。在代码中,它将如下所示:

speechSynthesis.speak(utterance1);
// ... after a while
speechSyntehsis.pause(utterance1);
speechSynthesis.speak(utterance2);
// ... after a long while
speechSynthesis.resume(utterance1);
不幸的是,speechSynthesis的pause()、resume()和cancel()方法不接受任何参数并对整个语音队列执行操作。有什么方法可以实现这种行为吗

如果我可以有多个speechSynthesis对象,那么我可以为每个话语创建一个,但我相信我只能有一个

如果我可以跟踪字符串中该语句“被输出到”的位置,那么我可以取消它,然后用文本的其余部分创建一个新的语句,但我不知道这是否可行


有什么建议吗?

我已经使用我的库在speechSynthesis中工作了几个月,并且根据文档(以及我所做的所有测试)暂停单个合成实例并重新分析另一个实例是不可能的,因为所有实例都与window相关。speechSynthesis(如果有一天API发生变化,这将是speechSynthesis中的另一个重要步骤)。当您调用speechSynthesis的暂停方法“instance”时,它将应用于所有队列,没有其他方法

根据报告:

有一个属性的话语(onmark)但是没有很好的记录,可能不会工作,因为这个api仍然是实验性的

在语音合成标记语言(SSML)中到达“标记”标记时,将触发标记事件文件。只需知道,使用基于XML的SSML文档可以将语音数据传递给话语。其主要优点是,在构建需要合成大量文本的应用程序时,可以更轻松地管理语音内容


.

感谢您的快速响应。mark事件正是我想要的。谢谢您!@tborenst如果不是问题,如果您实现了您需要的,请在获得后在此处共享:)
// the only solution would be if the speechSynthesis official API had a constructor like
// and a real NEW instance be created
// var synthRealInstance = new speechSynthesis();
// but till the date ... nope :(

var synthA =  window.speechSynthesis;
var synthB = window.speechSynthesis;

var utterance1 = new SpeechSynthesisUtterance('How about we say this now? This is quite a long sentence to say.');
var utterance2 = new SpeechSynthesisUtterance('We should say another sentence too, just to be on the safe side.');

synthA.speak(utterance1);
synthB.speak(utterance2);

synthA.pause();
// or synthB will anyway stop the synthesis of the queue