小编lit*_*ird的帖子

Google Speech API - 识别 Base64 编码的音频

我已经在 Google Speech API 上苦苦挣扎了一段时间,希望得到一些建议。

这就是我想做的:

  1. 在浏览器中录制音频
  2. 将录音转换为 Base64 并发送到我的服务器
  3. 在服务器上,调用Google Speech API的syncRecognize函数,传入我的base 64编码音频

我总是收到一个空的结果对象。

当我按照此入门教程进行操作时,一切正常。

我究竟做错了什么?

任何提示/想法将非常感激。

const Speech = require('@google-cloud/speech');
const SpeechV1beta1 = require('@google-cloud/speech/src/v1beta1')

module.exports = {

    syncRecognize: function(base64Encoding) {

       const speech = Speech();
       const speechV1beta1 = SpeechV1beta1();
       const client = speechV1beta1.speechClient();

       const body = {
           "config": {
               "encoding":"LINEAR16",
               "sampleRate":16000,
               "languageCode":"en-US"
           },
           "audio": {
              "content": base64Encoding
           }
       }

       return client.syncRecognize(body)
        .then((results) => {
            console.log('results', results) 
            return {transcription: results[0]};
        }).catch(function(error) {
            return {error: error};
        });;

    }
}
Run Code Online (Sandbox Code Playgroud)

audio-recording google-speech-api

5
推荐指数
1
解决办法
1422
查看次数

标签 统计

audio-recording ×1

google-speech-api ×1