AI Streaming
The stream()
method in the PiopiyAction
class sets up a WebSocket connection to transmit the call's audio in real time. This is ideal for scenarios such as real-time AI processing, interactive voice response (IVR) systems, or any application where live call audio needs to be analyzed or processed.
stream(url, options)
parameter | Type | Description |
---|---|---|
ws_url | string | The WebSocket URL provided by the ngrok TCP service. |
options | object | An object containing optional parameters (listen_mode, voice_quality and stream_on_answer) |
listen_mode | string | Specifies who hears the streamed audio. Options are callee , caller , or both |
voice_quality | string | he desired voice quality in bits per second. Options are 8000 , 16000 |
listen_mode | boolean | Whether to start streaming after the call is answered.The default value is false. |
Example Implementation
- Here’s how to implement the AI streaming feature to send real-time audio from both participants (caller and callee) to a WebSocket server:
- Node.js
- Python
const { PiopiyAction } = require("piopiy");
const action = new PiopiyAction();
const ws_url = "ws://example.tcp.ngrok.url";
const options = {
listen_mode: "caller",
voice_quality: "8000",
stream_on_answer: true,
};
action.stream(ws_url, options);
from piopiy import Action
# Create an instance of the Action class
action = Action()
ws_url = "ws://example.tcp.ngrok.url"
options = { "listen_mode": "caller", "voice_quality": "8000", "stream_on_answer": True }
action.stream(ws_url, options)