Node.js 为什么音频流识别的API响应时间如此之慢?
我使用非常类似的代码来使用Node.js客户端库对音频流执行语音识别 API正在正确解析我的音频,但我发现自己等待了30-45秒才得到响应。考虑到它有多时髦,这似乎是不对的。我是否有配置错误的地方 我试着写一个本地文件,只是为了确保音频能够清晰地通过,而且录音看起来很好 谢谢你能给我的帮助Node.js 为什么音频流识别的API响应时间如此之慢?,node.js,google-cloud-speech,Node.js,Google Cloud Speech,我使用非常类似的代码来使用Node.js客户端库对音频流执行语音识别 API正在正确解析我的音频,但我发现自己等待了30-45秒才得到响应。考虑到它有多时髦,这似乎是不对的。我是否有配置错误的地方 我试着写一个本地文件,只是为了确保音频能够清晰地通过,而且录音看起来很好 谢谢你能给我的帮助 import record from 'node-record-lpcm16'; import Speech from '@google-cloud/speech'; function streamToP
import record from 'node-record-lpcm16';
import Speech from '@google-cloud/speech';
function streamToParser(){
const speech = Speech();
const request = {
config: {
encoding: 'LINEAR16',
sampleRateHertz: 16000,
languageCode: 'en-US',
},
interimResults: true,
};
const recognizeStream = speech.createRecognizeStream(request)
.on('error', console.error)
.on('data', (data) => {
console.log(data.results)
});
record
.start({
sampleRate: 16000,
threshold: .6,
verbose: true,
silence: '5.0'
})
.on('error', console.error)
.pipe(recognizeStream)
console.log('Google is listening...')
};
streamToParser();
我没有用身份验证凭据配置
Speech
,所以我的请求必须被解除优先级。下面是修复它的配置,按照说明:
要创建json
keyfile,请遵循“在您自己的服务器上”部分中概述的步骤
const speech = Speech({
projectId: 'my project ID from the Google Cloud dev console',
keyFilename: 'path/to/keyfile.json', // that I generated/downloaded from the Google Cloud dev console
});