@@ -18,6 +18,8 @@ Vapi's WebSocket transport enables real-time, bidirectional audio communication
18
18
19
19
To initiate a call using WebSocket transport:
20
20
21
+ ### PCM Format (16-bit, default)
22
+
21
23
``` bash
22
24
curl ' https://api.vapi.ai/call' \
23
25
-H ' authorization: Bearer YOUR_API_KEY' \
@@ -35,6 +37,25 @@ curl 'https://api.vapi.ai/call' \
35
37
}'
36
38
```
37
39
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
+
38
59
### Sample API Response
39
60
40
61
``` json
@@ -61,13 +82,25 @@ When creating a WebSocket call, the audio format can be customized:
61
82
| Parameter | Description | Default |
62
83
| -------------| -------------------------| ---------------------|
63
84
| ` 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:
66
91
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.
68
101
69
102
<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.
71
104
</Note >
72
105
73
106
## Connecting to the WebSocket
@@ -86,9 +119,16 @@ socket.onerror = (error) => console.error("WebSocket error:", error);
86
119
87
120
The WebSocket supports two types of messages:
88
121
89
- - ** Binary audio data** (PCM, 16-bit signed little-endian )
122
+ - ** Binary audio data** (format depends on your configuration: PCM or Mu-Law )
90
123
- ** Text-based JSON control messages**
91
124
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
+
92
132
### Sending Audio Data
93
133
94
134
``` javascript
0 commit comments