我正在尝试使用来自 App Engine 的 Google Speech-to-text api(它不需要凭证 key )。但是,在运行代码以获取响应时,我收到一个空错误。
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”,因此我认为结果位于 await client.recognize(request);
行中。但是,捕获错误后,我得到了一个空字段的错误,例如 {}
。
这当然对调试没有多大帮助。所以任何人都可以帮忙。谢谢。
最佳答案
使用
app.get('/', async(req, res) => {
res.send(await detectspeech())
关于javascript - 使用 Google Cloud Speech-to-text 时出现空错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56484265/