Getting recording link as fast as possible
# support
a
Hi there, I was wondering if there was a way to get the recording link as fast as possible after a call? I don't need the post processing analysis. Right now it takes ~15 seconds to get. Alternatively, do you know how I could record the audio on my side at a lower-level? Using twilio directly Thank you!
v
Hi Alex! 👋 I understand you're looking to get recording links faster or find a way to record audio directly. While I don't have specific information on how to use Twilio's API independently for recording, I can definitely help with ways to reduce the delay in getting recording links and alternative recording methods. ## Getting Recording Links Faster Here are some approaches to reduce the delay in obtaining recording links: ### Real-time Audio Recording You can record audio in real-time during the call using Vapi's streaming capability: - Enable streaming via API parameters - Implement a callback or webhook to handle incoming audio chunks - Process audio chunks as needed during the call According to the [documentation](https://docs.vapi.ai/calls/call-features), you can get live call audio in real-time using websockets, which could eliminate the waiting period after the call ends. ### Optimize Network and Server Performance To reduce latency: - Use a Content Delivery Network (CDN) with edge locations close to users - Optimize voice processing algorithms - Ensure code efficiency - Use fast and lightweight communication protocols like WebSockets - Implement efficient audio codecs ### Adjust Endpointing and Transcription Settings Modifying these settings can help reduce delays: - Set
smartEndpointingEnabled
to
false
and Deepgram's endpointing to 300ms - Adjust the
waitSecond
parameter or use custom endpointing - Update these settings using the
UPDATE /assistant/:id API
## Recording Audio Using WebSockets If you want to record audio on your side, you can set up a WebSocket bridge between Twilio and Vapi: ```ts app.post('/twilio/voice', async (req, res) => { // Create a Vapi call with bypass enabled const vapiCall = await fetch('https://api.vapi.ai/call', { method: 'POST', body: JSON.stringify({ phoneCallProviderBypassEnabled: true, // other call parameters... }) }); const { callId } = await vapiCall.json();
// Return TwiML to connect Twilio to your websocket const twiml = new VoiceResponse(); const connect = twiml.connect(); connect.stream({ url:
wss://your-server.com/twilio-bridge/${callId}
}); res.type('text/xml'); res.send(twiml.toString()); });
Copy code
Then handle the audio data:

```ts
twilioWs.on('message', async (data) => {
  try {
    const message = JSON.parse(data.toString());
    if (message.event === 'media') {
      const audio = Buffer.from(message.media.payload, 'base64');
      // Here you can save the audio buffer to a file or storage
      if (vapiTransport.readyState === WebSocket.OPEN) {
        vapiTransport.send(audio);
      }
    }
  } catch (error) {
    console.error('Error processing Twilio message:', error);
  }
});
Is there a specific aspect of recording or reducing the delay that you'd like me to elaborate on? Sources: - [Getting Started Guide](https://docs.vapi.ai/calls/call-features) - [WebSocket Bridge Documentation](https://discord.com/channels/1211482211119796234/1211483291191083018/threads/1341810370700120064) - [Real-time Audio Recording](https://discord.com/channels/1211482211119796234/1211483291191083018/threads/1333380326294290486) - [Optimizing Network and Server Performance](https://discord.com/channels/1211482211119796234/1211483291191083018/threads/1336685825227755591) - [Adjusting Endpointing and Transcription Settings](https://discord.com/channels/1211482211119796234/1211483291191083018/threads/1332286268805087272)
m
use the streaming url and save it on your server instead.
actually this is what the doc says on how to record the stream:https://docs.vapi.ai/calls/call-features#4-end-call const WebSocket = require('ws'); const fs = require('fs'); let pcmBuffer = Buffer.alloc(0); const ws = new WebSocket("wss://aws-us-west-2-production1-phone-call-websocket.vapi.ai/7420f27a-30fd-4f49-a995-5549ae7cc00d/transport"); ws.on('open', () => console.log('WebSocket connection established')); ws.on('message', (data, isBinary) => { if (isBinary) { pcmBuffer = Buffer.concat([pcmBuffer, data]); console.log(
Received PCM data, buffer size: ${pcmBuffer.length}
); } else { console.log('Received message:', JSON.parse(data.toString())); } }); ws.on('close', () => { if (pcmBuffer.length > 0) { fs.writeFileSync('audio.pcm', pcmBuffer); console.log('Audio data saved to audio.pcm'); } }); ws.on('error', (error) => console.error('WebSocket error:', error));
k
Hey AdeB, you have to wait for 15-30 seconds to get the call recording after end of call. The alternative is to use live call control and curate the audio buffer by yourself, then generate the audio file. Now it's up to you which method to go with.
a
Ok thank you both!
k
Marking this ticket as Solved ✅
2 Views