2016-09-21 101 views
2

我管理了“概览教程”:https://cloud.google.com/speech/docs/getting-started 然后我尝试使用我自己的音频文件。我上传了一个采样率为16000Hz的.flac文件。Google云语音识别“INVALID_ARGUMENT”

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

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

回答

3

作为每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