javascript - 使用 Google Cloud Speech-to-text 时出现空错误

标签 javascript node.js google-cloud-platform google-cloud-speech

我正在尝试使用来自 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/

相关文章:

javascript - 是否需要将函数声明为异步函数才能返回 promise ?

node.js - AWS Node Lambda 发送回二进制图像作为响应

javascript - 新图像响应后图像的位置设置

javascript - 将键盘快捷方式添加到 Google Chrome 扩展的上下文菜单?

javascript - 带有远程 MySQL 的 NodeWebkit

javascript - NodeJS 未加载外部 javascript

ssh - GCP-SSH 连接超时

google-cloud-platform - 创建谷歌云函数时出现错误 "Failed to initialize a region"

mysql - GCP SQL Cloud - 空 MySQL 数据库占用 1.2GB 存储空间

javascript - 如何在 lookbehind 和 lookahead 之间解析文本