#which format should i send the data to deepgram
1 messages · Page 1 of 1 (latest)
Hey there! This channel allows you to ask Kapa.ai for assistance. But it looks like you haven't connected your Discord profile to your Deepgram account yet. You can do so at https://community.deepgram.com - by doing so, you'll be able to ask questions in #1115960287183511643 if you need human assistance!
Deepgram’s community offers tons of resources to support you on your voice AI journey
Hi @fluid echo. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
To send the payload from Twilio to Deepgram's WebSocket for real-time transcription, you should follow these guidelines:
-
The audio data from Twilio is typically encoded in base64 format and needs to be decoded before sending to Deepgram.
-
Deepgram expects raw audio data in the mulaw format with a sample rate of 8000 Hz for Twilio voice calls.
Here's how you should process and send the data:
- Decode the base64 payload from Twilio.
- Send the decoded raw mulaw audio data to Deepgram.
When setting up the Deepgram live transcription, make sure to specify the correct encoding and sample rate:
deepgramLive = transcriber.transcription.live({
punctuate: true,
encoding: "mulaw",
sample_rate: 8000,
# other options...
})
Here's an example of how to handle the Twilio payload and send it to Deepgram:
if msg['event'] == 'media':
media = msg['media']
chunk = base64.b64decode(media['payload'])
deepgramLive.send(chunk)
This approach is consistent with the recommendations from both the Deepgram Twilio integration guide (https://developers.deepgram.com/docs/on-premise-twilio-integration#forward-data-to-proxy-1) and the Deepgram live streaming API documentation (https://developers.deepgram.com/reference/listen-live).
Remember to set up your Deepgram WebSocket connection with the appropriate parameters for Twilio audio, as shown in the code snippet above. This ensures that Deepgram correctly interprets the audio format coming from Twilio.
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
@fluid echo Kapa.ai is still learning and improving, please let me know how I did by reacting below.
when should i send those params
punctuate: true,
encoding: "mulaw",
sample_rate: 8000,
?
this is my code
$client = new Client('wss://api.deepgram.com/v1/listen');
$client->addHeader("Authorization", "Token dd");
activity()->useLog('Connected to Deepgram WebSocket')->withProperties("")->log('Connected to Deepgram WebSocket');
// Decode the Twilio audio payload (base64 audio) and send it to Deepgram
$streamsReceived = \Illuminate\Support\Facades\DB::table("activity_log")->whereRaw('properties like \'{"event":"media"%\'')->select('properties')->limit(100)->get();
foreach ($streamsReceived as $stream){
// $audio = base64_decode("LSssJixTNue43sivvrqsr7SusbfIvN1r0v/oxsvMu8bKx93d523saGpiS1dHQUI5NzkyMTIrKyonRUNDushpr7fDrK26r7C0wb/DX97NWc3H1sG+yMvF2+Tc7G9zXk1dS0VEPDU6LzI0Li0rJyxFOu658sKvvraqsrastbi6xNDR7vTh0N3MxsPHx8jp2dZg72JVVUxOSj4+Ojc1MTQuLA==");
$media = json_decode($stream->properties);
if(isset($media->media) && isset($media->media->payload) && $media->media->payload!=""){
$audio = base64_decode($media->media->payload);
$client->send(new \WebSocket\Message\Binary($audio));
}
}
any infos man ?
Note: you can ask me a follow up question by @ mentioning me again