Monitor Call
# support
v
Hello, I have a question about the Monitor Call features. What does controlUrl mean? How can a call be controlled in real time? Is there example code in Python where one can pull out the audio/text in real time with listenUrl? listenUrl string Optional This is the URL where the assistant’s calls can be listened to in real-time. To enable, set assistant.monitorPlan.listenEnabled to true. controlUrl string Optional This is the URL where the assistant’s calls can be controlled in real-time. To enable, set assistant.monitorPlan.controlEnabled to true.
v
# Monitor Call Features Explained 🎧 ## What is controlUrl? The
controlUrl
is a key component in Vapi's live call control feature that allows you to inject conversation elements dynamically during an ongoing call. It provides a way to control and modify the flow of a phone call by sending specific commands or messages [in real-time](https://docs.vapi.ai/calls/call-features). ## How to control a call in real-time To control a call in real-time using `controlUrl`: 1. First, obtain the controlUrl by making a POST request to the
/call
endpoint. The response will include a
monitor
object containing both
listenUrl
and
controlUrl
[in the payload](https://docs.vapi.ai/calls/call-features). 2. Send POST requests to the controlUrl to inject messages or control the call:
Copy code
bash
curl -X POST 'https://aws-us-west-2-production1-phone-call-websocket.vapi.ai/7420f27a-30fd-4f49-a995-5549ae7cc00d/control'
-H 'content-type: application/json'
--data-raw '{
  "type": "say", 
  "message": "Welcome to Vapi, this message was injected during the call."
}'
3. Common command types include: - "say" for speaking messages - "end-call" to terminate a call - "transfer" to forward the call to another destination 4. Enable monitoring in your assistant configuration:
Copy code
typescript
const assistant = {
  monitorPlan: {
    listenEnabled: true,  // For live audio streaming
    controlEnabled: true  // For live control capabilities
  }
};
## Python code for extracting audio with listenUrl While there isn't a direct Python example in the documentation, here's a conceptual Python implementation using the
websocket-client
library: ```python import websocket import os pcm_buffer = bytearray() def on_message(ws, message): if isinstance(message, bytes): pcm_buffer.extend(message) print(f"Received PCM data, buffer size: {len(pcm_buffer)}") def on_error(ws, error): print(f"WebSocket error: {error}")
def on_close(ws, close_status_code, close_msg): print("WebSocket closed") if pcm_buffer: with open('audio.pcm', 'wb') as f: f.write(pcm_buffer) print('Audio data saved to audio.pcm') def on_open(ws): print("WebSocket connection established") websocket_url = "your_listen_url_here" ws = websocket.WebSocketApp(websocket_url, on_open=on_open, on_message=on_message, on_error=on_error, on_close=on_close) ws.run_forever() ``` This code connects to the WebSocket provided by
listenUrl
and buffers the audio data, which you can then save or process in real-time [as shown in the documentation](https://docs.vapi.ai/calls/call-features). Sources: - [Vapi Call Features Documentation](https://docs.vapi.ai/calls/call-features) - [Discord Channel Discussion](https://discord.com/channels/1211482211119796234/1211483291191083018/threads/1340737584309211136)
v
for the live call can I get in python 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));
m
Hey man @VapiLLM , did you get this resolved or do you still need assistance?
v
hello, still require assistance, can I get python code to pull out the real audio stream/words from a call
m
Absolutely, when you get the listen url, you can connect to it in python using any python websocket library and then save or stream the data.
If you're looking to just pull out the live transcript (not the audio) it can be done much easier. Let me know which way you want to go and I can walk you through the next steps.
let me know if this solves that for you!
v
thank you can you give me a code snippet for both pulling out the live transcript and audio?
k
Hello, unfortunately I'm not able to provide you code snippets but our documentation is made to be easily processed by LLMs. I'd recommend feeding these docs to one of your choice and testing:
3 Views