node.js - 如何在 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;
在我进行此更改后,问题已解决。
解决方案
配置应该是这样的
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
推荐阅读
- python-3.x - 如何为图像 vk 添加描述?
- reporting-services - SSRS:“包含错误:[BC302205] 预期语句结束。”
- vmware - 打开虚拟机时出错。vmx 文件已损坏
- wordpress - How to fix Gutenberg's Convert to Blocks?
- php - 如何在yii2的控制器动作中使用return而不是echo
- elasticsearch - How to use standard tokenizer with preserve_original?
- spring-boot - Springboot + Drools, java.lang.RuntimeException: Illegal class for global
- azure - No SnapshotStart detected. Might need more exceptions to trigger snapshot collector
- php - PHP IF 语句允许 A、B、C 和 D
- python - 为什么我的代码无法从我的 txt 文件中读取 3 位数字?