2016-09-21 154 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