node.js - 如何在 Google Speech API 中显示单词级别的置信度分数
问题描述
我在 Cloud Functions 中包含了 Google Speech API。我想获得单词级别的置信度分数,所以我将“enableWordConfidence”设置为 true。出于某种原因,响应不会返回单词级别的置信度分数。
我曾尝试将 de-DE 和 en-US 作为语言代码,但两者都不起作用。这是来自 Google 的官方文档,但是复制该代码并在云函数中运行它也没有返回单词级别的置信度。 https://cloud.google.com/speech-to-text/docs/word-confidence
这是代码:
const filePath = `gs://PATH_TO_AUDIO.flac`
const audio = {
uri: filePath,
};
const config = {
encoding: 'FLAC',
sampleRateHertz: 16000,
languageCode: languageCode,
enableSpeakerDiarization: true,
enableWordConfidence: true,
useEnhanced: true,
enableWordTimeOffsets: true,
enableAutomaticPunctuation: true,
};
if(languageCode == 'en-US') {
config.model = 'video'
}
const request = {
audio: audio,
config: config,
};
const client = new speech.SpeechClient();
return client
.longRunningRecognize(request)
.then(data => {
const operation = data[0];
return operation.promise();
}).then(data => {
const response = data[0];
if(response.results) {
return storeSegmentInMeeting(response.results, noteId);
} else {
return null;
}
}).catch(err => {
return console.error('ERROR:', err);
});
我希望得到每个单词的置信度分数,所以有什么想法吗?
解决方案
好的,除非您切换到库的“V1P1BETA”版本,否则这可能不起作用。它具有更多功能,包括单词级别的置信度。我建议你试试。
我不知道你是否已经这样做了,所以我分享这个以防万一。
你需要:
const speech = require('@google-cloud/speech').v1p1beta1;
推荐阅读
- google-cloud-network-load-balancer - 面向 VM 实例 NIC0 的 GCP 外部负载均衡器是否支持主动被动模式?
- regex - 匹配 begging 和 end 字符而不从另一个搜索中获取它们
- java - 在 RecyclerView Android Studio 中将 id 设置为 Arraylist 中的项目
- react-native - Ant Media - React-Native - iOS/Android 支持
- python - Python:以科学格式打印,10 的幂仅为 3 的倍数
- javascript - 如何向网页添加全球多语言支持,它仍然相关吗?
- node.js - 无法读取 null 的属性“销毁”
- mongodb - 如何设置MongoDB不区分大小写?
- javascript - 仅使用 React useEffect 钩子对某些依赖项运行效果?
- python - 使用元组和整数将字符串转换为混合列表