This example shows how to automatically detect the browser language and speak a welcome message in the users own language. In this case, English, French or Spanish.
This is example code to add anywhere in a page.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
<script> var lang = window.navigator.languages ? window.navigator.languages[0] : null; lang = lang || window.navigator.language || window.navigator.browserLanguage || window.navigator.userLanguage; if (lang.indexOf('-') !== -1) lang = lang.split('-')[0]; if (lang.indexOf('_') !== -1) lang = lang.split('_')[0]; console.log(lang); var say = 'Hello'; var voice = 'UK English Female'; switch (lang) { case 'en': say = "Hello"; voice = "UK English Female"; break; case 'es': say = "Hola"; voice = "Spanish Female"; break; case 'fr': say = "Bonjour"; voice = "French Female"; break; default: say = "Hello"; voice = "UK English Female"; break; } setTimeout(responsiveVoice.speak(say, voice),15000); </script> |
Keywords: text to speech multilanguage, french text to speech, spanish text to speech