首页 > 解决方案 > 使用 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);。但是,发现错误后,我得到了一个空字段的错误,例如{}.

这当然对调试没有多大帮助。所以任何人都可以帮忙。谢谢。

标签: javascriptnode.jsgoogle-cloud-platformgoogle-cloud-speech

解决方案


利用

app.get('/', async(req, res) => {
  res.send(await detectspeech())

推荐阅读