【问题标题】:Google cloud speech syncrecognize "INVALID_ARGUMENT"谷歌云语音同步识别“INVALID_ARGUMENT”
【发布时间】:2018-03-08 13:02:44
【问题描述】:

我已经完成了“概述教程”:https://cloud.google.com/speech/docs/getting-started 然后我尝试使用我自己的音频文件。我上传了一个采样率为 16000Hz 的 .flac 文件。

我只用我自己托管在谷歌云存储 (gs://my-bucket/test4.flac) 上的音频文件更改了下面的 sync-request.json 文件

{
  "config": {
      "encoding":"flac",
      "sample_rate": 16000
  },
  "audio": {
      "uri":"gs://my-bucket/test4.flac"
  }
}

文件被很好地识别,但请求返回“INVALID_ARGUMENT”错误

{
  "error": {
    "code": 400,
    "message": "Unable to recognize speech, code=-73541, possible error in recognition config. Please correct the config and retry the request.",
    "status": "INVALID_ARGUMENT"
  }
}

【问题讨论】:

    标签: flac google-cloud-speech


    【解决方案1】:

    根据this 的回答,所有编码仅支持 1 声道(单声道) 音频

    我正在使用以下命令创建 FLAC 文件:

    ffmpeg -i test.mp3 test.flac
    

    请求中的采样率与 FLAC 标头不匹配

    但添加 -ac 1(将音频通道数设置为 1)修复了此问题。

    ffmpeg -i test.mp3 -ac 1 test.flac
    

    这是我完整的Node.js 代码

    const Speech = require('@google-cloud/speech');
    const projectId = 'EnterProjectIdGeneratedByGoogle';
    
    const speechClient = Speech({
        projectId: projectId
    });
    
    // The name of the audio file to transcribe
    var fileName = '/home/user/Documents/test/test.flac';
    
    
    // The audio file's encoding and sample rate
    const options = {
        encoding: 'FLAC',
        sampleRate: 44100
    };
    
    // Detects speech in the audio file
    speechClient.recognize(fileName, options)
        .then((results) => {
            const transcription = results[0];
            console.log(`Transcription: ${transcription}`);
        }, function(err) {
            console.log(err);
        });
    

    采样率可以是 16000 或 44100 或其他有效值,编码可以是 FLAC 或 LINEAR16。 Cloud Speech Docs

    【讨论】:

      【解决方案2】:

      我的错,作为文档“https://cloud.google.com/speech/docs/basics”,.flac 文件必须是 16 位 PCM

      总结:

      编码:FLAC
      频道:1 @ 16 位
      采样率:16000Hz

      /!\ 注意不要导出一个立体声文件(2通道)文件,它会抛出另一个错误(只接受一个通道)Google speech API internal server error -83104

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-11-04
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多