我正在尝试使用Google云语音API,方法是在Angular FrontEnd中记录音频,将其转换为base64,再将其发送到我的Node后端,然后对Google语音API进行查询。
到目前为止,我还没有成功,谷歌只给我空了结果。
您将看到,为了确定问题,我在遍历所有可能的sampleRate和音频格式。
要注意的另一件事是,使用Google示例audio.raw(在此处https://github.com/googleapis/nodejs-speech/tree/master/samples进行测试)可以正常工作,并且我得到了转录。
这是我的前端:
const onSuccess = stream => {
var options = {
audioBitsPerSecond: 16000, // NB: I have tried several bitrates, and several audio formats (here, and in the blob creation)
// mimeType: 'audio/ogg; codecs=opus'
}
this.mediaRecorder = new MediaRecorder(stream);
this.mediaRecorder.onstop = e => {
const audio = new Audio();
const blob = new Blob(this.chunks, { 'type': 'audio/wav' });
this.chunks.length = 0;
audio.src = window.URL.createObjectURL(blob);
var reader = new FileReader();
reader.readAsDataURL(blob);
reader.onloadend = (function …Run Code Online (Sandbox Code Playgroud)