node.js - Google Speech to Text API 在本地提供的结果与在线演示不同
问题描述
6秒mp3音频文件(下载)首先直接在https://cloud.google.com/speech-to-text/上测试,响应符合预期。
“你好,兄弟,你好吗,我过得很好,希望妈妈过得好”
然后我创建了firebase函数(见下面的代码):
const speech = require('@google-cloud/speech').v1p1beta1
exports.speechToText = functions.https.onRequest(async (req, res) => {
try {
// Creates a client
const client = new speech.SpeechClient()
const gcsUri = `gs://xxxxx.appspot.com/speech.mp3`
const config = {
encoding: 'MP3',
languageCode: 'en-US',
enableAutomaticPunctuation: false,
enableWordTimeOffsets: false,
}
const audio = {
uri: gcsUri,
}
const request = {
config: config,
audio: audio,
}
// Detects speech in the audio file
const [response] = await client.recognize(request)
const transcription = response.results
.map(result => result.alternatives[0].transcript)
.join('\n')
console.log(`Transcription: ${transcription}`)
res.send({ response })
} catch (error) {
console.log('error:', error)
res.status(400).send({
error,
})
}
})
我得到以下不正确的响应:
“你好兄弟,你好吗希望一切都好”
更新: 本地运行时收到相同的错误响应。所以云功能不是问题。
更新#2:在配置中
设置model:'video'
ORmodel:'phone_call'
解决了这个问题。IE
const config = {
encoding: 'MP3',
languageCode: 'en-US',
enableAutomaticPunctuation: false,
enableWordTimeOffsets: false,
model: 'phone_call',
}
解决方案
设置model:'video'
OR解决model:'phone_call'
了config
这个问题。IE
const config = {
encoding: 'MP3',
languageCode: 'en-US',
enableAutomaticPunctuation: false,
enableWordTimeOffsets: false,
model: 'phone_call',
}
我想该default
模型不适用于某些类型的音频。
推荐阅读
- web-services - Azure 应用程序网关阻止 SOAP 1.2 请求
- image - 如何在 Xamarin Forms 中正确使用网格中多行上的图像
- r - R ggplot2 BoxPlot:改变导致最大值和最小值的线条的结构
- python - 在迭代时引用下一个索引时避免索引错误
- regex - 不同的组,相同的模式 - 正则表达式 cpp
- python - 列表理解中的“代码”
- java - Java Wicket 表单:序列化对象类“myClassName”时出错
- android - 运行谷歌地图活动时出现白屏
- python - 在Django中访问同一数据库中的其他表
- univocity - Univocity - 多次读取期间文件头验证的问题