Skip to content

Instantly share code, notes, and snippets.

@hiepxanh
Last active October 23, 2024 06:14
Show Gist options
  • Save hiepxanh/de602287ed95fca39a25723297a7dd12 to your computer and use it in GitHub Desktop.
Save hiepxanh/de602287ed95fca39a25723297a7dd12 to your computer and use it in GitHub Desktop.
show list voice and speak vietnamese
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);
@fbukevin
Copy link

fbukevin commented Oct 23, 2024

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".

  • Linh female (Northern accent, Common browser support in Web Speech API)
  • Microsoft NamMinh Online (Natural) - Vietnamese (Vietnam) (vi-VN) male (Northern accent)
  • Microsoft HoaiMy Online (Natural) - Vietnamese (Vietnam) female (Southern accent)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment