鈍足ランナーのIT日記

走るのが好きな5流のITエンジニアのブログ。

趣味の範囲は広いけど、どれも中途半端なクソブロガー楽しめるWebアプリを作ってあっと言わせたい。サーバーサイドPerl(Mojolicious)、クライアントサイドVue.js。Arduinoにも触手を伸ばす予定。

Web Speech APIと戯れる

まずは、音声一覧を取ってくる、こちらなどを参考にしてくだされ。。
Web Speech API で使える音声一覧。 - 脱力系日記
こんな感じで、どんな音声が使えるか一覧表示してみます。

<!DOCTYPE html>
<html>
    <head>
        <script>
            // wait on voices to be loaded before fetching list
            window.speechSynthesis.onvoiceschanged = function() {
            
            window.speechSynthesis.getVoices().filter(function(voice){
                console.log(voice.voiceURI);
                });
            };
        </script>
    </head>
    <body>
     get voices!
    </body>
</html>


Web Speech API Specification
あとは、voiceURI アトリビュートにて設定するといいらしい。

<html>
    <head>
        <script>
      var synthes = new SpeechSynthesisUtterance("hello world");
      speechSynthesis.voiceURI = 'Google 日本語';
      speechSynthesis.speak( synthes );
    </script>
    </head>
    <body>
     get voices!
    </body>
</html>

日本語ボイスはWindowsでは選択できない

結局、windowsで日本語をしゃべらせるには、”Google 日本人”しか選択できないという感じでした。残念です。