Encode LINEAR16 audio to Twilio media audio x-mulaw NodeJS

0 votes

I have been trying to stream mulaw media stream back to Twilio. Requirement is payload must be encoded audio/x-mulaw with a sample rate of 8000 and base64 encoded

My input is from @google-cloud/text-to-speech in LINEAR16

I tried Wavefile

This is how I encodeded response from @google-cloud/text-to-speech

 const wav = new wavefile.WaveFile(speechResponse.audioContent)
    wav.toBitDepth('8')
    wav.toSampleRate(8000)
    wav.toMuLaw()

Then I send the result back to twilio via websocket

twilioWebsocket.send(JSON.stringify({
      event: 'media',
      media: {
        payload: wav.toBase64(),
      },
      streamSid: meta.streamSid,
}))
Jun 23, 2022 in Node-js by Vaani
• 7,070 points
2,433 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In Node-js