node.js - In node on Windows 10, how can I get a list of all the voices installed?
问题描述
I've tried using say js with the following code:
let voices = await say.getInstalledVoices((e, v) => {console.log(v)});
console.log('voices=', voices);
Although the console.log in the callback function returns an array of voices, the voices variable returns a null.
I've had a go at wrapping the call in a promise and got a similar result.
Surely there's a simple one line way of getting those voices? I'm happy to use something other than say to do so.
解决方案
您不应将 await 用于该方法。该方法say.getInstalledVoices
返回无效
只需使用以下语法来获取可用声音的列表:
const say = require('say');
function getVoices() {
return new Promise((resolve) => {
say.getInstalledVoices((err, voice) => {
return resolve(voice)
})
})
}
async function usingVoices() {
const voicesList = await getVoices();
console.log(voicesList)
}
usingVoices()
usingVoices()
您可以使用以下语法并在方法中做任何您想做的事情
推荐阅读
- javascript - 如何使用 reduce 测试 Math.max 函数的数组
- python - 使用 Python 脚本将 JSON 文件转换为新的 CSV 文件
- node.js - const 不能在 Node 的类中定义?
- pytorch - 通过 2d 索引访问 3d 张量
- javascript - Webpack 4 在使用未定义函数时不会抛出编译错误
- scala - 如何从类型中提取类型参数
- node.js - 使用代码中创建的 id 保存实体,猫鼬
- flutter - 输入'未来
' 不是类型 'double' 的子类型 - postgresql - 当我的 Asp.Net Core API 的每秒并发请求数增加时,为什么响应时间会增加
- ionic-framework - 更改 ImagePicker 的语言/文本