🚀

Web Speech API で日本語の読み上げ

2024/06/28に公開

ブラウザーで利用可能かどうかは window オブジェクト経由で調べられる

> 'speechSynthesis' in window
true

読み上げを実行してみる。Chrome のディベロッパーツールでも実行可能である

const uttr = new SpeechSynthesisUtterance();
uttr.lang = "ja-JP";
uttr.text = "こんにちは";
speechSynthesis.speak(uttr);

speechSynthesis.getVoices を通していろいろな音声を選ぶことができる

const uttr = new SpeechSynthesisUtterance();
uttr.text = "こんにちは";
voices = speechSynthesis.getVoices().filter((v) => v.lang === 'ja-JP');
uttr.voice = voices[0];
speechSynthesis.speak(uttr);

Chromebook の場合、13種類の日本語音声が使える

Discussion