1

このリンク - twilio.com/blog/live-transcribing-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)

このエラーの解決方法を教えてください!

4

0 に答える 0