首页 > 解决方案 > 如何在 Node JS 的 Google Cloud Speech 库中启用扬声器分类?

问题描述

我目前正在尝试创建一个使用谷歌云语音到文本的网络应用程序,特别是扬声器分类功能。我的服务器是用节点 js 编写的,我将音频文件作为谷歌存储 URI 发送。我的语音配置看起来像这样

config: {
          encoding: 'LINEAR16',
          languageCode: 'en-GB',
          sampleRateHertz: 8000,
          enableSpeakerDiarization: true,
          diarizationSpeakerCount: true,
        }

我得到的成绩单有一个空的“单词”数组,谷歌云语音文档告诉我应该包含演讲者标签:

{ words: [],
transcript: 'and the rabbit sails at dusk',
confidence: 0.8659023642539978 }

可能值得注意的是,如果我添加

enableWordTimeOffsets: true,

到我的配置然后我得到一个像这样的“单词”数组:

[ { startTime: { seconds: '0', nanos: 0 },
endTime: { seconds: '0', nanos: 600000000 },
word: 'Hello' } etc..

更新

我没有正确导入 nodejs 谷歌云语音库,我这样做了:

const speech = require('@google-cloud/speech');

为了使用 beta 功能,我需要使用它:

const speech = require('@google-cloud/speech').v1p1beta1;

在我进行此更改后,问题已解决。

标签: node.jsgoogle-speech-api

解决方案


配置应该是这样的

const config = {
        encoding: 'LINEAR16',
        sampleRateHertz: 8000,
        languageCode: 'en-GB'
        enableAutomaticPunctuation: true,
        useEnhanced: true,
        model: 'video',
        diarizationConfig : {
          enableSpeakerDiarization: true,
          minSpeakerCount: 2,
          maxSpeakerCount: 3,
      }
    }

有关 RecognitionConfig 的更多信息,请访问

https://cloud.google.com/speech-to-text/docs/reference/rest/v1p1beta1/RecognitionConfig


推荐阅读