風邪をひいて声が出ないので Mac の sayコマンド で文章を読み上げて窮地を乗り切った話 - みかづきブログ その3
前回は Mac の Sayコマンドを活用しました が、気づいてしまいまいした。人は皆、常にMacを持ち歩いているわけではないということに。
というわけで、今回は普段から持ち歩いているiPhoneで文章の読み上げをおこなうべくウェブサイトをつくってみました。
DEMO
JavaScript
(function(win, doc) { "use strict"; var form = doc.getElementById("form"), serif = doc.getElementById("serif"), btn = doc.getElementById("btn"), msg; form.addEventListener("submit", function(evt) { evt.preventDefault(); if (serif.value) { msg = new SpeechSynthesisUtterance(serif.value); msg.lang = "ja-JP"; speechSynthesis.speak(msg); } }, false); })(this, document);
以前 活用した Web Speech Synthesis API をつかっています。
iOS 8.1.2 で SpeechSynthesisUtterance を試す - みかづきブログ その3
これでいつ声がでなくなっても安心です(?)。