javascript - 使用 Google Cloud Speech-to-text 时出现空错误
问题描述
我正在尝试使用 App Engine 中的 Google Speech-to-text api(不需要凭据密钥)。但是,在运行代码以获取响应时,我收到一个空错误。
const detectspeech = async (audioBytes) => {
try {
const client = new speech.SpeechClient();
const audio = {
content: audioBytes,
};
const config = {
enableAutomaticPunctuation: true,
encoding: "LINEAR16",
model: "default",
languageCode: 'en-US',
};
const request = {
audio: audio,
config: config,
};
console.log("1");
const [response] = await client.recognize(request);
console.log("2");
const transcription = response.results
.map(result => result.alternatives[0].transcript)
.join('\n');
return { data: "Success"};
}catch(e)
{
return {error: e};
}
}
在日志上,我打印出数字“1”,但没有打印出“2”,所以我认为结果在 line 中await client.recognize(request);
。但是,发现错误后,我得到了一个空字段的错误,例如{}
.
这当然对调试没有多大帮助。所以任何人都可以帮忙。谢谢。
解决方案
利用
app.get('/', async(req, res) => {
res.send(await detectspeech())
推荐阅读
- javascript - 过滤嵌套数组并返回与键值匹配的数组
- compiler-construction - C/C++ 以外的其他语言的编译器是否有内置的清理解决方案?
- mono - 如何将 c# 文件编译为 .wasm 文件?
- r - 将 ggplot2 分组条形图转换为绘图图会导致一些条形图消失
- python - 使用带有 python(或 gtts-cli)的 Google Text to Speech gtts - 说出疑问句 - 提问
- javascript - Veriff集成到react.js项目中,未定义错误文档
- vue.js - 为什么 vue-plyr 插件一直在服务器端加载
- apache-spark - 将数据帧写入 HDFS
- elasticsearch - 如何在elasticsearch上查找哪个节点是特定索引
- html - 输入表格输入计算值