Skip to content

Instantly share code, notes, and snippets.

@wtnabe
Last active December 3, 2023 08:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wtnabe/03419571caec92d4bfb0a897c31dd15a to your computer and use it in GitHub Desktop.
Save wtnabe/03419571caec92d4bfb0a897c31dd15a to your computer and use it in GitHub Desktop.
Web Speech synthesis 上の Google Voice の制限

https://mdn.github.io/dom-examples/web-speech-api/speak-easy-synthesis/ を試す。

一定以上の長さになると途中で speak が切れる現象が発生する。

完了 OS ブラウザ Voice
failure macOS 13.6 Chrome 119 Google 日本語 ( ja-JP )
success macOS 13.6 Chrome 119 Kyoko ( ja-JP )
success macOS 13.6 Safari 17.0 Kyoko ( ja-JP )
success Android 10 Chrome 119 Google 日本語 ( ja-JP )
success iOS 17.1.1 Safari Kyoko ( ja-JP )
success iOS 17.1.1 Chrome Kyoko ( ja-JP )

音声の出力は途中で切れたように感じられるが、実際には speechSynthesis は speaking状態にあり、この状態のまま再度 speak を実行することはできない。これは特定のプログラムでのみ speak を実行できないという意味ではなく、speechSynthesis を利用する同一ブラウザ上のあらゆるアプリケーションで実行できないし、その原因が何かは把握する方法がない1

一度 cancel() を実行すれば再度 speak できる。

macOS, iOS では Chrome 以外から Google 日本語 Voice を選択することがそもそもできない2。Google ネイティブのプラットフォーム以外で Chrome から Google Voice を利用した際の何らかの制限ぽい。

上記の Google Voice は予想通り GCP の何かを利用しているらしく、SpeechSynthesisVoice オブジェクトの localService プロパティが false になっている。あらかじめ長さが決められない場合はこの localServicefalse のものを除外すればよさそう。

cf. https://developer.mozilla.org/en-US/docs/Web/API/SpeechSynthesisVoice

Footnotes

  1. SpeechSynthesisUtterance に error イベントはあるが、切れた際にはこの error は発生しない。cancel() 時に発生する。

  2. iOS の Chrome は中身は実際には Safari

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment