javascript - JavaScript SpeechSynthesisUtterance 正确说出数字
问题描述
我将 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'));
推荐阅读
- jquery - 用jquery创建迭代淡入淡出函数的最有效方法是什么
- windows - 如果没有用户登录,则无法通过 Jenkins 运行 COM 应用程序
- java - Jedis 扫描未找到任何密钥
- javascript - 获取元素的所有数据属性及其在jquery中的值
- c# - 如何使用书签添加换行符以在 C# 和 OpenXML 中运行,并带有对齐的文本
- python - Django REST Framework ModelSerializer read_only_fields 不起作用
- asp.net - 错误 400 错误请求 - 单独重定向
- php - 如何在 CanvasJS 图表中显示格式化的日期时间?
- c# - C#获取类声明名称
- java - Class的getClassLoader()什么时候抛出SecurityException