我将 SpeechSynthesisUtterance 与 JavaScript 和 HTML 结合使用。我想正确地说出数字,所以不要读五三七七九,比如五万三千七百,七十九。那可能吗?我从 localStorage 获取号码。 我正在使用这段代码:
var msg = new SpeechSynthesisUtterance("The number is " + localStorage.getItem("mynumber"));
msg.lang = 'en-US';
msg.rate = 4;
window.speechSynthesis.speak(msg);
`
最佳答案
数字的发音取决于浏览器和从该浏览器中选择的语音。当我在 Chrome 中尝试时,默认语音会说“五三七七九”,但是如果我给数字一个千位分隔符(即将它从 53779 更改为 53,779),所有语音都会说“五万三千七七九”。
因此尝试添加“.toLocaleString('en')”,它添加了千位分隔符:
var msg = new SpeechSynthesisUtterance("The number is " + localStorage.getItem("mynumber").toLocaleString('en'));
关于JavaScript SpeechSynthesisUtterance 正确说出数字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53748420/