我们引用了这个链接 - twilio.com/blog/live-trancribing-phone-calls-using-twilio-media-streams-and-google-speech-text。其中下面提到的代码部分给了我们错误,
//Create Stream to the Google Speech to Text API
recognizeStream = client
.streamingRecognize(request)
.on("error", console.error)
.on("data", data => {
console.log(data.results[0].alternatives[0].transcript);
wss.clients.forEach( client => {
if (client.readyState === WebSocket.OPEN) {
client.send(
JSON.stringify({
event: "interim-transcription",
text: data.results[0].alternatives[0].transcript
})
);
}
});
});
break;
case "start":
console.log(`Starting Media Stream ${msg.streamSid}`);
break;
case "media":
// Write Media Packets to the recognize stream
recognizeStream.write(msg.media.payload);
break;
case "stop":
console.log(`Call Has Ended`);
recognizeStream.destroy();
break;
}
});
});
错误:
recognizeStream.write(msg.media.payload);
TypeError: Cannot read property 'write' of undefined
at WebSocket.incoming (C:\Users\Administrator\Documents\COE\Augular-ALP\route\routes.js:210:31)
at WebSocket.emit (events.js:315:20)
at Receiver.receiverOnMessage (C:\Users\Administrator\Documents\COE\Augular-
ALP\node_modules\ws\lib\websocket.js:789:20)
请指导我们解决此错误!