Skip to main content

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)
parameterTypeDescription
ws_urlstringThe WebSocket URL provided by the ngrok TCP service.
optionsobjectAn object containing optional parameters (listen_mode, voice_quality and stream_on_answer)
listen_modestringSpecifies who hears the streamed audio. Options are callee, caller, or both
voice_qualitystringhe desired voice quality in bits per second. Options are 8000, 16000
listen_modebooleanWhether 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:
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);