weixin_39837139
weixin_39837139
2020-12-01 23:17

Create new utterance instance every time we speak

Firefox will not schedule an utterance twice so we need to create a new utterance every time something is to be spoken. Closes #4

该提问来源于开源项目:IDMNYU/p5.js-speech

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

7条回答

  • weixin_39565300 weixin_39565300 5月前

    this is a firefox issue, not a web speech issue... so the real thing to do is get mozilla to fix their browser, instead of us fixing our library.

    点赞 评论 复制链接分享
  • weixin_39577908 weixin_39577908 5月前

    I believe the inverse is actually true.

    From the specification: https://w3c.github.io/speech-api/webspeechapi.html#tts-methods

    The SpeechSynthesis object takes exclusive ownership of the SpeechSynthesisUtterance object. Passing it as a speak() argument to another SpeechSynthesis object should throw an exception. (For example, two frames may have the same origin and each will contain a SpeechSynthesis object.)

    This implies (At least to me) that using the utterance object in any way after passing it to be synthesised is a violation of the API. Note that despite it specifying it should throw an exception when passed to another SpeechSynthesis object it also says that it takes exclusive ownership, and that editing of the text property after this point is undefined behaviour.

    点赞 评论 复制链接分享
  • weixin_39837139 weixin_39837139 5月前

    I'd re-open the PR if I could, but the maintainers have to do that. Closing the PR that quickly feels a bit rude. Even if it was a problem with Mozilla this is not the avenue for pushing that agenda. A library user just cares about it working and that should be the priority.

    点赞 评论 复制链接分享
  • weixin_39565300 weixin_39565300 5月前

    i'm gonna ping google for clarification on this. I think the way it's written in the API is confusing and is missing a step in explaining what happens. My understanding when i worked with them on this was that a SpeechSynthesisUtterance gets auto-created under the hood when you tell a SpeechSythesis object to speak() a vanilla string, instead of an explicitly created SpeechSynthesisUtterance. That's what I mean when I say I think this is a Firefox bug.

    Making an SpeechSynthesisUtterance explicitly inside the library doesn't make sense to me in this context, because the SpeechSynthesisUtterance is really intended to help you with caching commonly used phrases (they contain all the metadata (rate settings, phonemes, etc.) that the synthesizer needs that stop just short of the actual synthesis, so it's more efficient if your software has only like ten phrases it's gonna use over and over. I could see us adding some groovy functionality where you could pass an Array or JSON or whatever that the object would then bust out into a bunch of cached utterances, but having a new SpeechSynthesisUtterance for every phrase is what the SpeechSynthesis object is supposed to do by default, so if it's not working, then something else seems wrong to me.

    点赞 评论 复制链接分享
  • weixin_39565300 weixin_39565300 5月前

    wasn't meaning to be rude, btw. i wrote this thing over two years ago, and i have literally no idea who any of you are. this library is used in several dozen accessibility projects for years and this has never been reported. i'm happy to entertain putting in an explicit utterance for every speech line to fix firefox, but i need to make sure it doesn't break anything in chrome, safari, etc. first. hang in there and i'll take a look.

    点赞 评论 复制链接分享
  • weixin_39577908 weixin_39577908 5月前

    A SpeachSynthesisUtterance is created on line 56 that is used in all operations, so this change is actually only a bit of a tweak to add more compatibility - I'm fairly certain it maintains full support in current browsers.

    点赞 评论 复制链接分享
  • weixin_39565300 weixin_39565300 5月前

    ah i see what you mean! so are things like rate/pitch sticky if you recreate the utterance?

    let me take a crack at this and see if i can figure it out.

    点赞 评论 复制链接分享

相关推荐