Last active
May 7, 2024 11:55
-
-
Save hiepxanh/de602287ed95fca39a25723297a7dd12 to your computer and use it in GitHub Desktop.
show list voice and speak vietnamese
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
var langList = document.getElementById('langList'); | |
if ('speechSynthesis' in window) { | |
// Start an html table for languages details | |
var text = '<table border=1><tr><th>Default<th>Language<th>Local<th>Name<th>URI</tr>'; | |
// Get voices; add to table markup | |
function loadVoices() { | |
var voices = speechSynthesis.getVoices(); | |
voices.forEach(function(voice, i) { | |
// Add all details to table | |
text += '<tr><td>' + voice.default + '<td>' | |
+ voice.lang + '<td>' + voice.localService | |
+ '<td>' + voice.name + '<td>' + voice.voiceURI; | |
}); | |
} | |
loadVoices(); | |
langList.innerHTML = text; | |
// Chrome loads voices asynchronously. | |
window.speechSynthesis.onvoiceschanged = function(e) { | |
loadVoices(); | |
langList.innerHTML = text; | |
} | |
} | |
var lang = 'vi-VN' | |
var msg = new SpeechSynthesisUtterance(); | |
var voices = window.speechSynthesis.getVoices(); | |
msg.voice = voices.filter(voice => voice.lang == lang)[0]; | |
msg.text = 'Hệ thống đã khởi động, chào mừng Hiệp quay trở lại'; | |
msg.lang = lang; | |
window.speechSynthesis.speak(msg); |
var msg = new SpeechSynthesisUtterance();
msg.lang = "vi-VN";
msg.text = "Xin Chào, tôi là Tâm";
speechSynthesis.speak(msg);
This is awesome tutorial.
I would appreciate if daothithientamn or some experts will show an working example of an HTML file using Javascript with selected voice "vi-VN".
Thank you.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It is not working right now!