我将 Node.js 与 IBM Watson 的语音转文本结合使用。目前,我已将其设置为转录预先录制的音频文件。虽然我希望它从用户的麦克风转录实时音频。
speech to text documentation 表示如下:
<块引用>对于在可用时转录实时音频的请求,您必须将 Transfer-Encoding
标头设置为 chunked
以使用流模式。
我不确定如何使用 Transfer-Encoding
或 chunked
。这是我的代码目前的样子:
app.get('/translateSpeech', (req, res) => {
// speech to text authentication
const speechToText = new SpeechToTextV1({
authenticator: new IamAuthenticator({
apikey: 'API-KEY-HERE',
}),
serviceUrl: 'URL-HERE',
});
// speech to text options
const recognizeParams = {
audio: fs.createReadStream('./my-audio-file.mp3'),
contentType: 'audio/mp3',
};
// send speech data, and recieve text data
speechToText.recognize(recognizeParams)
.then(audioResults => {
transcript = audioResults.result.results[0].alternatives[0].transcript;
res.json({ transcript: transcript });
})
.catch(err => {
console.log('error:', err);
});
});
我如何将来自用户麦克风的实时翻译添加到此?