Stream audio back to Twilio via websocket connection - twilio

I'm trying out Twillio's Programmable Voice feature and have implemented basic audio stream processing by referring to this doc. I'm planning to stream audio back to Twillio using the same websocket and want Twillio to play that audio to the caller
Is there any way to achieve this?
This is how my TwiML bins app xml configuration looks like
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Start>
<Stream url="wss://XXXXXXX.in.ngrok.io/media" />
</Start>
<Dial>+91**********</Dial>
</Response>
I referred to Twillio Bi-directional Media-Streams, but it doesn't specify in what format and with what structure I need to send audio bytes back to twillio
Also I found this question where in answer he says sending back audio stream back to twillio websocket is not possible.
Can I get some help here please, to understand how can I achieve this

Related

Twilio Stream only when the call has been received

I am using twiml bin attached to one of my twilio numbers.
When a person calls that number it should be able to dial multiple numbers. I want to stream the call only when the call has been picked up. There can be multiple ongoing streams associated with a twilio number.
<Response>
<Start>
<Stream track="both_tracks" url="wss://XXXX.ngrok.io /twilio-stream">
</Stream>
</Start>
<Dial answerOnBridge="true" >
<Number>+91XXXXXXXXX</Number>
<Number>+91XXXXXXXXX</Number>
</Dial>
</Response>
The above twiml starts the stream as soon as the number is dialed. I want it to start the stream only when the call is received at the other end.
Unfortunately, there isn't a way to do this today, without REST API endpoint control.
You can use the REST API Calls resource to initiate calls intead. The approach you are taking doesn't work very well when the dialed parties are mobile end-points in poor coverage areas and/or devices with voicemail enabled.

Problems with verb Record timeout when calling an IVR

We're trying to use Twilio to create an automated test framework for those IVRs.
We do an outbound call from Twilio to the IVR, use the verb Say/Play to interact with the IVR and we're using Record to capture what the IVR is saying, latter we transcribe it and make the assertions.
When I ask Twilio to call a phone number and I pretend to be the IVR, everything works perfectly. But when I ask Twilio to call the real IVR, apparently the Record verb can't recognize the pauses, when the IVR stops talking and is waiting for some input.
We tried tweak the timeout attribute but no luck, it records everything and only when the IVR ends the call, Twilio give me the callback with the entire recording. We want each interaction with the IVR in a separate audio, the way we have when I'm pretending.
Here is an example of the TwiML with the Record verb:
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Record action="http://foo/nextStep"
method="POST"
playBeep="false"
recordingStatusCallback="http://foo/recordStatus"
timeout="2"
transcribe="false"
trim="do-not-trim" />
</Response>
Twilio developer evangelist here.
Rather than using <Record> for this, I would recommend using <Gather input="speech">. The intention of speech input with <Gather> is to react to input to build a voice enabled IVR, but I can only imagine that it will work better in this testing scenario too. It will live transcribe the results for you in place of returning the recordings for you.
Let me know if that helps.

Clarification on Twilio's Record and Transcribe Feature

I'm looking at Twilio's API documentation for Record and wanted some clarification.
1) I saw that transcribe currently is limited to recordings of 2 minutes, so if I set Transcribe to true, if the call goes on longer than 2 minutes there won't be a transcript but the recording will be saved?
2) Is it possible to just dial a number and record the audio without having to be connected to an "agent"?
Twilio developer evangelist here.
Yes, you're right. The recording will still be saved and you will receive a warning written to your debug log. You can transcribe entire calls up to 4 hours long using a couple of add-ons that are available in the Twilio add-on marketplace.
There are a number of ways to record a call.
<Record> in TwiML
<Dial record> in TwiML
<Conference record> in TwiML
Record=true in Outbound REST API
Enabling recording on elastic SIP Trunk in Console
If you are looking to record a whole call, then setting Record=true when creating a call.
If you are doing this for an incoming call, then you can't record the entire call, but that's where setting record on <Dial> or <Conference> or using the <Record> element comes into play. <Dial> or <Conference> likely include an agent, so <Record> is still what you're looking for here.
Let me know if that helps at all.

Can I upload a wav file to twilio and get it transcribed?

We currently use twilio to send out SMS messages to our employees on the field. I see that twilio has a transcription service. We have many voicemails in-house which are wav files that needs to converted to text. I was looking at a way of uploading these voicemails into twilio and get it transcribed. Would it be possible?
Are these voicemails actually connected in any way to Twilio? It sounds like you have just some regular WAV audio files and are wondering if you can use the Twilio transcription API to convert audio files to text?
If this is the case then it looks like you might be better off using a more pure transcription-as-a-service API.
Maybe something like Speechmatics?
If these audio files are in fact from a Twilio received call then it looks like you can use the Twilio Transcription API to receive the text. Check out their API docs page: https://www.twilio.com/docs/api/rest/transcription

Playing music in a call with Twilio

How can you play music in a call with (preferably) a TwiML XML file? I have gotten so far as:
<!-- page located at http://example.com/simple_dial.xml -->
<Response>
<Dial>PHONE NUMBER</Dial>
<Play>
AUDIO FILE URL
</Play>
</Response>
but it waits until PHONE NUMBER hangs up to play the audio. How can I call a phone number, and then play an mp3 in the call?
Initiate a new call via the REST API, using a URL that returns the following TwiML:
<Response>
<Play>AUDIO FILE URL</Play>
</Response>
Here's a quickstart tutorial that talks through the process of making an outbound call with the PHP helper library. It's equally easy with the libraries in the other languages as well.

Resources