下記のコードのように、Web Speech APIのSpeechSynthesisUtteranceインターフェイスを利用して単純に、文字列「hello world」をボタンを押したときに、音声として出力します。パソコンでの確認では対応しているブラウザChromeやfireboxでは、音声を確認できますが、スマフォの確認で、比較的新し目の、Safari 9.0と Android7.0で確認しましたが、音声が出力されません。原因がわからないので、こちらで尋ねるに至りました。
<!DOCTYPE html> <html lang="ja"> <head> <meta charset="utf-8"> <title></title> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> </head> <body> <script> $(function(){ 'use strict'; function audioWord(word) { var synthes = new SpeechSynthesisUtterance(word); synthes.volume = 1.0; synthes.rate = 1.0; synthes.pitch = 1.0; synthes.lang = 'en-US'; speechSynthesis.speak(synthes); } $('button').click(function(){ audioWord('hello world'); }) }); </script> <button>音声テスト (Hello World!)</button> </body> </html>
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/03/01 09:26