Send / Receive audio over WebSocket
# support
b
Hi, I'm building https://finevoicing.com, a tool to test Voice Agents and I'd like to support Vapi agents by initiating calls with them. Ideally, I'd be able to initiate a session over a websocket and get the audio stream, and send audio back. Is it at all possible?
v
@Bubu Hello! Yes, it's absolutely possible to integrate Vapi agents into your tool at FineVoicing.com for testing Voice Agents. The Vapi Web SDK would be perfect for this use case. It's designed to work with web applications and can handle audio streaming to and from the client seamlessly. To initiate a session over a websocket and manage the audio stream, you would use the Vapi Web SDK to establish the connection and start the calls. The SDK will take care of the audio streaming, and you can send audio back through the same interface. The SDK is open source and available on GitHub, so you can easily integrate it into your application. If you need any specific guidance on how to set this up or have any further questions, please let me know!
You can continue this conversation by mentioning me in the message.
Got it. Tagging @User for additional help.
b
@Vapi I'm building a server-side web application, not in the browser. To my understanding, the SDK you mention is browser-side
v
@Bubu I apologize for the confusion. For a server-side web application, you would indeed need a different approach than the browser-based SDK. To support Vapi agents in a server-side context, you would typically use a server-side SDK or directly interact with the Vapi REST API, which should allow you to initiate sessions and handle audio streams. The API would provide endpoints for initiating calls, managing sessions, and sending and receiving audio streams over websockets. If Vapi offers a server-side SDK or direct API access that supports websockets, you would be able to integrate it into your server-side application at FineVoicing.com. Unfortunately, I don't have the specifics of the Vapi server-side capabilities or API documentation, so I would recommend reaching out to the Vapi support team or consulting their API documentation for detailed instructions on how to implement this. If you need further assistance or have more questions, please let me know!
b
@Shubham Bajaj
s
@Bubu it is not possible to send audio back to Vapi instead you can only get the live call audio but yeah can inject messages externally using live call control feature. Do let me know if you require help with anything else.
b
@Shubham Bajaj When a Vapi agent is calling or being called you do receive audio, right?
s
@Bubu Yes, we do receive audio, but you want to act as a telephony or voice provider since we have a custom voice option. Please correct me if I'm wrong.
b
@Shubham Bajaj I'm a client of a Vapi agent, like a human would be when calling (web/telephony). It's just happen that it's done in a programmatic way instead of through manual actions, makes sense?
s
@Bubu Yes, you can do it for sure. Let's hop on a call today to clear your doubts and save back and forth communication. https://discord.gg/E4TEgnHV?event=1329840374939914240
f
What was the resolution to this @Shubham Bajaj ? Can we hold a call over the server? (stream caller audio to, and receive Vapi agent audio back) You mention in another thread that web calls are built on Daily, which supports Twilio bidirectional media streams – can we communicate through those w/ a Vapi web call?
k
Hey fsm_sam, yes web calls are built on daily but not on twilio. Can you rephrase this and explain with an example. "Can we hold a call over the server? (stream caller audio to, and receive Vapi agent audio back)"
f
I'd like to be able to keep the call in our Twilio. When a call comes in, send the live caller audio to you, and have you send back the agent response.
Here's some code that shows what i'm trying to do: 1. Call connects to our Twilio audio handler 2. Setup message handler to forward Twilio messages straight to Vapi if the call has a Vapi connection 3. On START from Twilio, create a Vapi call with phone call provider bypass. 4. Setup websocket connection to Vapi for the call, which will allow messages (Step 2 above) to start flowing 5. Return messages Vapi straight to Twilio I'm able to connect to the Vapi socket successfully and pass the audio, but I do not receive anything back (the handler with vapiData in second ss never fires). cc: @Sahil https://cdn.discordapp.com/attachments/1329523231375495260/1341463001714393109/forward-twilio-to-vapi.png?ex=67b61646&is=67b4c4c6&hm=98e73380d8de88026ab5f7a56ff322068edee0435329eced862ce25b792c5626& https://cdn.discordapp.com/attachments/1329523231375495260/1341463002116915232/forward-vapi-to-twilio.png?ex=67b61646&is=67b4c4c6&hm=2353f135be863b9e5a69100d4aa710de49134a3167eb9d60479c9cccf22421bd&
@User
In your UI, the recordings show that you are generating agent audio for the call, you're receiving the caller audio, and you're generating responses – i just can't hear them. I'm now trying to also use a second connection to the /listen websocket url but getting a 400 response when trying to connect. Will post more updates.
s
Hey @fsm_sam please create a new #1211483291191083018 ticket for your current issue because this ticket has already been marked as closed and not authored by you.
15 Views