Last active
October 23, 2024 06:14
-
-
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); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nowdays, I use Microsoft Edge
Phiên bản 129.0.2792.89 (Bản xây dựng chính thức) (arm64)
. There are more options for "vi-VN".female
(Northern accent, Common browser support in Web Speech API)male
(Northern accent)female
(Southern accent)