- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 WebSpeech 的 speechSynthesis 模块让网络应用程序说话。但是,您似乎只能将话语添加到队列中,然后对整个队列进行 pause()、resume() 和 cancel()。
我有一种情况,我想有两个话语:
utterance1 = new SpeechSynthesisUtterance(text1);
utterance2 = new SpeechSynthesisUtterance(text2);
我想播放 utterance1,然后在中间暂停,播放 utterance2,然后继续播放 utterance1。在代码中,它看起来像这样:
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 中工作了几个月 Artyom.js ,并且根据文档(以及我所做的所有测试)暂停单个合成实例并重新更新另一个是不可能的,因为所有实例都与 window.speechSynthesis 相关(如果有一天 API 发生变化,那将是 speechSynthesis 的又一大进步)。当你调用speechSynthesis“实例”的pause方法时,它会申请所有队列,没有其他办法。
根据documentation :
// 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
话语 (onmark) 上有一个属性,但是没有很好的记录并且可能不会工作,因为这个 api 仍处于实验阶段。
The mark event is fired when a ‘mark’ tag is reached in a Speech Synthesis Markup Language (SSML) file. Just know that it’s possible to pass your speech data to an utterance using an XML-based SSML document. The main advantage of this being that it makes it easier to manage speech content when building applications that have large amount of text that need to be synthesised.
关于javascript - WebSpeech 语音合成 : Pausing utterance1, 播放另一个话语 2,然后恢复话语 1 - 可能吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36091383/
我正在编写一个小脚本来练习使用 boost 库。 使用these header /命名空间,这是我的主要功能: int main() { ifstream inNew("../../Downloads
我正在用 SpriteKit 创建我的第一款游戏。我正在尝试暂停我的 GameScene,然后通过 SpriteKit 运行一些动画。问题是,如果我使用 self.view?.isPaused = t
我在尝试暂停倒计时器时遇到问题。我试图做到这一点,以便在单击播放按钮后,该按钮变为暂停按钮。但由于某种原因它不会暂停。 我尝试将 id“pButton”更改为“pauseButton”,这是有效的,但
在滚动更新之前,我想在我们的监控工具中为每台主机设置停机时间。我为此创建了一个自定义模块。设置停机时间时可能会出现问题,我们无法解决。在那种情况下,我想让用户选择是否应中止部署或继续部署而不设置停机时
根据 this paragraph ,以下有问题: /* usr_interrupt is set by the signal handler. */ if (!usr_interrupt)
我有一个 TThread 对象,希望能够通过程序主窗体上的按钮启动/停止线程。我一直在寻找实现这一目标的方法,到目前为止我有以下想法: 当用户单击“停止”时终止并释放线程,并在单击“开始”时创建一个新
这里我有一个方法 public static Color pickColor(){ final aero.colorpicker.Frame frame = new aero.colorpic
我在这个循环中犯了一些错误,我真的无法弄清楚。这是循环: while (true) { System.out.print(stepName[currentTick]);
我刚刚发现 Barba.js 并发现它非常有用。它提供同一网站的 URL 之间的平滑转换。 我整理了一个 Plunker 由两个页面(index.html 和 about.html)组成,借助 jQu
我写了一个程序来尝试用 C 语言编写线程,但这很奇怪 它不会陷入 while 状态(例如 while (1){}) 我尝试用 getchar、scanf 和 while(1) 暂停我的程序,但它没有停
music.pause(); 似乎在我的代码中不起作用。当我单击播放按钮(该按钮是使用 html 5 Canvas 中的框制作的)时,它可以播放音乐,但是当我单击停止按钮时,它不起作用。请帮助我。 这
我一直在用 python 3.3 编写一个基本的计算器,我希望能够在命令窗口中运行它。 但是我一读完它就关闭了窗口,我还没来得及查看最终答案。 所以我想知道是否有等效于 c++ System('PAU
考虑以下代码: 进程 A(在随机时间点): void catch(){}; // empty handler. signal(SIGCHLD,&catch); // attach empty hand
我在 x.m 中使用了函数“pause”(不带参数),但它无法挂起程序。当程序执行此功能时,它只是继续运行。 最佳答案 kbhit对我不起作用。使用 input函数帮助我解决了问题。 关于Octave
我一直在寻找一些自动的方式来编号与 biblatex 的投影机马德里同一张幻灯片上的引用文献。这适用于 \pause和 \footcite{} .但是当我在同一张幻灯片上有多个项目符号(例如 5),并
好的,所以我上周在iOS8推出之前启动了一个应用程序。在iOS7及更低版本中,一切正常。但是现在,由于人们已经更新到iOS8,我的应用程序无故暂停/崩溃。 当我将NSMutableArray设置为NS
试图在我的应用程序中放置一个“暂停”按钮,以播放一些声音片段循环播放。 当我打电话mp.pause();一切都破了,我完全迷路了! 这是我正在使用的方法。 protected void man
我已经尝试过简单的controls =“pause”代码,但是我不想显示可见的音乐播放器。我希望第二次单击“播放按钮”时出现暂停功能。 有没有办法在此代码中插入“点击暂停”功能?我不想看到一个单独的按
所以我有这样的功能: function music(song) { var audio = new Audio("audio/" + song + ".ogg"); audio.play(); } 我
当我在 Chrome 中打开异常时暂停时,它会在弹出 JavaScript 错误时正确暂停,但我看不到异常消息本身。 有什么办法可以在点击“继续”之前看到该消息吗? 注意有时可以尝试从源代码中读取它,
我是一名优秀的程序员,十分优秀!