Chrome Speech Synthesis with longer texts

前端 未结 12 1207
难免孤独
难免孤独 2020-11-30 19:48

I am getting a problem when trying to use Speech Synthesis API in Chrome 33. It works perfectly with a shorter text, but if I try longer text, it just stops in the middle. A

12条回答
  •  遥遥无期
    2020-11-30 20:26

    2017 and this bug is still around. I happen to understand this problem quite well, being the developer of the award-winning Chrome extension Read Aloud. OK, just kidding about the award winning part.

    1. Your speech will get stuck if it's longer than 15 seconds.
    2. I discover that Chrome uses a 15 second idle timer to decide when to deactivate an extension's event/background page. I believe this is the culprit.

    The workaround I've used is a fairly complicated chunking algorithm that respects punctuation. For Latin languages, I set max chunk size at 36 words. The code is open-source, if you're inclined: https://github.com/ken107/read-aloud/blob/master/js/speech.js (line 144)

    The 36-word limit works well most of the time, staying within 15 seconds. But there'll be cases where it still gets stuck. To recover from that, I use a 16 second timer.

提交回复
热议问题