5

I have managed the "overview tutorial" : https://cloud.google.com/speech/docs/getting-started Then I tried to use my own audio file . I uploaded a .flac file with a sample rate of 16000Hz.

I only changed the sync-request.json file below with my own audio file hosted on google cloud storage (gs://my-bucket/test4.flac)

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

The file is well recognized but the request return an "INVALID_ARGUMENT" error

{
  "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"
  }
}
4

2 回答 2

9

根据答案,所有编码仅支持 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。云语音文档

于 2017-02-13T21:58:29.237 回答
1

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

总结:

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

/!\ 注意不要导出会引发其他错误的立体声文件(2 个通道)文件(只接受一个通道)Google 语音 API 内部服务器错误 -83104

于 2016-09-21T16:44:00.213 回答