Created
December 1, 2014 10:40
-
-
Save takatama/03337f75216e9261d279 to your computer and use it in GitHub Desktop.
Web Speech API (Synthesis)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
https://dvcs.w3.org/hg/speech-api/raw-file/tip/speechapi.html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<p> | |
<input id="input-japanese" type="text" value="こんにちは" /> | |
<button id="speak-japanese">日本語</button> | |
</p> | |
<p> | |
<input id="input-english" type="text" value="Hello world." /> | |
<button id="speak-english">English</button> | |
</p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(function() { | |
var Speaker = function (rate) { | |
this.rate = rate || 0.5; | |
this.speak = function (text, lang) { | |
var u = new SpeechSynthesisUtterance(); | |
u.rate = this.rate; | |
u.text = text; | |
u.lang = lang; | |
//u.onend = function(event) { alert('Finished in ' + event.elapsedTime + ' seconds.'); } | |
window.speechSynthesis.speak(u); | |
}; | |
this.english = function (text) { | |
this.speak(text, 'en-US'); | |
}; | |
this.japanese = function(text) { | |
this.speak(text, 'ja-JP'); | |
} | |
}; | |
var speaker = new Speaker(); | |
$('#speak-japanese').click(function () { | |
var text = $('#input-japanese').val(); | |
speaker.japanese(text); | |
}); | |
$('#speak-english').click(function () { | |
var text = $('#input-english').val(); | |
speaker.english(text); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment