Skip to content

Commit fea9248

Browse files
authored
enhancement: support for mulaw encoding within websocket transport (#670)
1 parent dd03e01 commit fea9248

File tree

1 file changed

+45
-5
lines changed

1 file changed

+45
-5
lines changed

fern/calls/websocket-transport.mdx

Lines changed: 45 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ Vapi's WebSocket transport enables real-time, bidirectional audio communication
1818

1919
To initiate a call using WebSocket transport:
2020

21+
### PCM Format (16-bit, default)
22+
2123
```bash
2224
curl 'https://api.vapi.ai/call' \
2325
-H 'authorization: Bearer YOUR_API_KEY' \
@@ -35,6 +37,25 @@ curl 'https://api.vapi.ai/call' \
3537
}'
3638
```
3739

40+
### Mu-Law Format
41+
42+
```bash
43+
curl 'https://api.vapi.ai/call' \
44+
-H 'authorization: Bearer YOUR_API_KEY' \
45+
-H 'content-type: application/json' \
46+
--data-raw '{
47+
"assistantId": "YOUR_ASSISTANT_ID",
48+
"transport": {
49+
"provider": "vapi.websocket",
50+
"audioFormat": {
51+
"format": "mulaw",
52+
"container": "raw",
53+
"sampleRate": 8000
54+
}
55+
}
56+
}'
57+
```
58+
3859
### Sample API Response
3960

4061
```json
@@ -61,13 +82,25 @@ When creating a WebSocket call, the audio format can be customized:
6182
| Parameter | Description | Default |
6283
|-------------|-------------------------|---------------------|
6384
| `format` | Audio encoding format | `pcm_s16le` (16-bit PCM) |
64-
| `container` | Audio container format | `raw` (Raw PCM) |
65-
| `sampleRate`| Sample rate in Hz | `16000` (16kHz) |
85+
| `container` | Audio container format | `raw` (Raw audio) |
86+
| `sampleRate`| Sample rate in Hz | `16000` for PCM, `8000` for Mu-Law |
87+
88+
### Supported Audio Formats
89+
90+
Vapi supports the following audio formats:
6691

67-
Currently, Vapi supports only raw PCM (`pcm_s16le` with `raw` container). Additional formats may be supported in future updates.
92+
- **`pcm_s16le`**: 16-bit PCM, signed little-endian (default)
93+
- **`mulaw`**: Mu-Law encoded audio (ITU-T G.711 standard)
94+
95+
Both formats use the `raw` container format for direct audio streaming.
96+
97+
### Format Selection Guidelines
98+
99+
- **PCM (`pcm_s16le`)**: Higher quality audio, larger bandwidth usage. Ideal for high-quality applications.
100+
- **Mu-Law (`mulaw`)**: Lower bandwidth, telephony-standard encoding. Ideal for telephony integrations and bandwidth-constrained environments.
68101

69102
<Note>
70-
Vapi automatically converts sample rates as needed. You can stream audio at 8kHz, 44.1kHz, etc., and Vapi will handle conversions seamlessly.
103+
Vapi automatically converts sample rates as needed. You can stream audio at 8kHz, 44.1kHz, etc., and Vapi will handle conversions seamlessly. The system also handles format conversions internally when needed.
71104
</Note>
72105

73106
## Connecting to the WebSocket
@@ -86,9 +119,16 @@ socket.onerror = (error) => console.error("WebSocket error:", error);
86119

87120
The WebSocket supports two types of messages:
88121

89-
- **Binary audio data** (PCM, 16-bit signed little-endian)
122+
- **Binary audio data** (format depends on your configuration: PCM or Mu-Law)
90123
- **Text-based JSON control messages**
91124

125+
### Audio Data Format
126+
127+
The binary audio data format depends on your `audioFormat` configuration:
128+
129+
- **PCM (`pcm_s16le`)**: 16-bit signed little-endian samples
130+
- **Mu-Law (`mulaw`)**: 8-bit Mu-Law encoded samples (ITU-T G.711)
131+
92132
### Sending Audio Data
93133

94134
```javascript

0 commit comments

Comments
 (0)