Created
January 1, 2016 14:48
-
-
Save brookslyrette/f39c5e2c23d296c48a22 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| //voices are loaded async | |
| window.speechSynthesis.onvoiceschanged = function() { | |
| for (var i = 0; i < window.speechSynthesis.getVoices().length; i++ ) { | |
| //only non English voices should be added | |
| var voice = window.speechSynthesis.getVoices()[i]; | |
| if (!voice.lang.startsWith('en')) { | |
| //create option tag | |
| var name = voice.name + " (" + voice.lang + ")"; | |
| $('.languageSpoken').append($('<option>', {value: i, text: name})); | |
| } | |
| } | |
| //select french to start | |
| if (speaking === undefined) { | |
| selectVoice(6); | |
| $('.languageSpoken').val(6); | |
| } | |
| }; | |
| //speak it back to me | |
| var talkToMe = function(text) { | |
| recording = false; | |
| recognition.stop(); | |
| //translate from source to target | |
| google.language.translate( | |
| {text : text, type : google.language.ContentType.TEXT}, | |
| languageInput.translateCode, | |
| //grab just the language from the code. | |
| speaking.lang.split('-')[0], | |
| function(result) { | |
| var msg = new SpeechSynthesisUtterance(); | |
| msg.voice = speaking; | |
| msg.text = result.translation; | |
| window.speechSynthesis.speak(msg); | |
| $('.translation').text(result.translation); | |
| } | |
| ) | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment