Real-time voice moderation stream (WebSocket)
curl --request GET \
--url wss://voice.moderationapi.com/v1/stream \
--header 'Authorization: <authorization>' \
--header 'Content-Type: application/json' \
--header 'Sec-WebSocket-Protocol: <sec-websocket-protocol>' \
--data '
{
"event": "start",
"mediaFormat": {
"encoding": "audio/x-mulaw",
"sampleRate": 8000
},
"tracks": [
{
"authorId": "<string>"
}
],
"conversationId": "<string>",
"channel": "<string>",
"emitPartials": false,
"metadata": {}
}
'import requests
url = "wss://voice.moderationapi.com/v1/stream"
payload = {
"event": "start",
"mediaFormat": {
"encoding": "audio/x-mulaw",
"sampleRate": 8000
},
"tracks": [{ "authorId": "<string>" }],
"conversationId": "<string>",
"channel": "<string>",
"emitPartials": False,
"metadata": {}
}
headers = {
"Authorization": "<authorization>",
"Sec-WebSocket-Protocol": "<sec-websocket-protocol>",
"Content-Type": "application/json"
}
response = requests.get(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'GET',
headers: {
Authorization: '<authorization>',
'Sec-WebSocket-Protocol': '<sec-websocket-protocol>',
'Content-Type': 'application/json'
},
body: JSON.stringify({
event: 'start',
mediaFormat: {encoding: 'audio/x-mulaw', sampleRate: 8000},
tracks: [{authorId: '<string>'}],
conversationId: '<string>',
channel: '<string>',
emitPartials: false,
metadata: {}
})
};
fetch('wss://voice.moderationapi.com/v1/stream', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "wss://voice.moderationapi.com/v1/stream",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_POSTFIELDS => json_encode([
'event' => 'start',
'mediaFormat' => [
'encoding' => 'audio/x-mulaw',
'sampleRate' => 8000
],
'tracks' => [
[
'authorId' => '<string>'
]
],
'conversationId' => '<string>',
'channel' => '<string>',
'emitPartials' => false,
'metadata' => [
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: <authorization>",
"Content-Type: application/json",
"Sec-WebSocket-Protocol: <sec-websocket-protocol>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "wss://voice.moderationapi.com/v1/stream"
payload := strings.NewReader("{\n \"event\": \"start\",\n \"mediaFormat\": {\n \"encoding\": \"audio/x-mulaw\",\n \"sampleRate\": 8000\n },\n \"tracks\": [\n {\n \"authorId\": \"<string>\"\n }\n ],\n \"conversationId\": \"<string>\",\n \"channel\": \"<string>\",\n \"emitPartials\": false,\n \"metadata\": {}\n}")
req, _ := http.NewRequest("GET", url, payload)
req.Header.Add("Authorization", "<authorization>")
req.Header.Add("Sec-WebSocket-Protocol", "<sec-websocket-protocol>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.get("wss://voice.moderationapi.com/v1/stream")
.header("Authorization", "<authorization>")
.header("Sec-WebSocket-Protocol", "<sec-websocket-protocol>")
.header("Content-Type", "application/json")
.body("{\n \"event\": \"start\",\n \"mediaFormat\": {\n \"encoding\": \"audio/x-mulaw\",\n \"sampleRate\": 8000\n },\n \"tracks\": [\n {\n \"authorId\": \"<string>\"\n }\n ],\n \"conversationId\": \"<string>\",\n \"channel\": \"<string>\",\n \"emitPartials\": false,\n \"metadata\": {}\n}")
.asString();require 'uri'
require 'net/http'
url = URI("wss://voice.moderationapi.com/v1/stream")
http = Net::HTTP.new(url.host, url.port)
request = Net::HTTP::Get.new(url)
request["Authorization"] = '<authorization>'
request["Sec-WebSocket-Protocol"] = '<sec-websocket-protocol>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"event\": \"start\",\n \"mediaFormat\": {\n \"encoding\": \"audio/x-mulaw\",\n \"sampleRate\": 8000\n },\n \"tracks\": [\n {\n \"authorId\": \"<string>\"\n }\n ],\n \"conversationId\": \"<string>\",\n \"channel\": \"<string>\",\n \"emitPartials\": false,\n \"metadata\": {}\n}"
response = http.request(request)
puts response.read_body{
"v": 1,
"event": "session.started",
"sessionId": "<string>",
"tracks": [
"<string>"
],
"conversationId": "<string>"
}Real-time voice stream
Open a WebSocket to moderate live voice audio in real time and receive a verdict per spoken utterance.
Real-time voice moderation stream (WebSocket)
curl --request GET \
--url wss://voice.moderationapi.com/v1/stream \
--header 'Authorization: <authorization>' \
--header 'Content-Type: application/json' \
--header 'Sec-WebSocket-Protocol: <sec-websocket-protocol>' \
--data '
{
"event": "start",
"mediaFormat": {
"encoding": "audio/x-mulaw",
"sampleRate": 8000
},
"tracks": [
{
"authorId": "<string>"
}
],
"conversationId": "<string>",
"channel": "<string>",
"emitPartials": false,
"metadata": {}
}
'import requests
url = "wss://voice.moderationapi.com/v1/stream"
payload = {
"event": "start",
"mediaFormat": {
"encoding": "audio/x-mulaw",
"sampleRate": 8000
},
"tracks": [{ "authorId": "<string>" }],
"conversationId": "<string>",
"channel": "<string>",
"emitPartials": False,
"metadata": {}
}
headers = {
"Authorization": "<authorization>",
"Sec-WebSocket-Protocol": "<sec-websocket-protocol>",
"Content-Type": "application/json"
}
response = requests.get(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'GET',
headers: {
Authorization: '<authorization>',
'Sec-WebSocket-Protocol': '<sec-websocket-protocol>',
'Content-Type': 'application/json'
},
body: JSON.stringify({
event: 'start',
mediaFormat: {encoding: 'audio/x-mulaw', sampleRate: 8000},
tracks: [{authorId: '<string>'}],
conversationId: '<string>',
channel: '<string>',
emitPartials: false,
metadata: {}
})
};
fetch('wss://voice.moderationapi.com/v1/stream', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "wss://voice.moderationapi.com/v1/stream",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_POSTFIELDS => json_encode([
'event' => 'start',
'mediaFormat' => [
'encoding' => 'audio/x-mulaw',
'sampleRate' => 8000
],
'tracks' => [
[
'authorId' => '<string>'
]
],
'conversationId' => '<string>',
'channel' => '<string>',
'emitPartials' => false,
'metadata' => [
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: <authorization>",
"Content-Type: application/json",
"Sec-WebSocket-Protocol: <sec-websocket-protocol>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "wss://voice.moderationapi.com/v1/stream"
payload := strings.NewReader("{\n \"event\": \"start\",\n \"mediaFormat\": {\n \"encoding\": \"audio/x-mulaw\",\n \"sampleRate\": 8000\n },\n \"tracks\": [\n {\n \"authorId\": \"<string>\"\n }\n ],\n \"conversationId\": \"<string>\",\n \"channel\": \"<string>\",\n \"emitPartials\": false,\n \"metadata\": {}\n}")
req, _ := http.NewRequest("GET", url, payload)
req.Header.Add("Authorization", "<authorization>")
req.Header.Add("Sec-WebSocket-Protocol", "<sec-websocket-protocol>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.get("wss://voice.moderationapi.com/v1/stream")
.header("Authorization", "<authorization>")
.header("Sec-WebSocket-Protocol", "<sec-websocket-protocol>")
.header("Content-Type", "application/json")
.body("{\n \"event\": \"start\",\n \"mediaFormat\": {\n \"encoding\": \"audio/x-mulaw\",\n \"sampleRate\": 8000\n },\n \"tracks\": [\n {\n \"authorId\": \"<string>\"\n }\n ],\n \"conversationId\": \"<string>\",\n \"channel\": \"<string>\",\n \"emitPartials\": false,\n \"metadata\": {}\n}")
.asString();require 'uri'
require 'net/http'
url = URI("wss://voice.moderationapi.com/v1/stream")
http = Net::HTTP.new(url.host, url.port)
request = Net::HTTP::Get.new(url)
request["Authorization"] = '<authorization>'
request["Sec-WebSocket-Protocol"] = '<sec-websocket-protocol>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"event\": \"start\",\n \"mediaFormat\": {\n \"encoding\": \"audio/x-mulaw\",\n \"sampleRate\": 8000\n },\n \"tracks\": [\n {\n \"authorId\": \"<string>\"\n }\n ],\n \"conversationId\": \"<string>\",\n \"channel\": \"<string>\",\n \"emitPartials\": false,\n \"metadata\": {}\n}"
response = http.request(request)
puts response.read_body{
"v": 1,
"event": "session.started",
"sessionId": "<string>",
"tracks": [
"<string>"
],
"conversationId": "<string>"
}Moderate live voice and call audio over a WebSocket. You send a
start frame, stream media frames as audio arrives, then stop; the server transcribes speech and returns a moderation verdict for each finalized utterance.
For the full walkthrough and code examples, see Real-time voice.Headers
Body
application/json
Frames sent by the client over the socket (not an HTTP body).
- Option 1
- Option 2
- Option 3
First frame the client sends. Declares the conversation, audio format, and tracks.
Response
101 - application/json
Switching Protocols. The server then streams event frames over the socket; the key one is utterance.final.
Was this page helpful?