pipecat-wavix 1.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of pipecat-wavix might be problematic. Click here for more details.
- pipecat_wavix-1.0.0/LICENSE +21 -0
- pipecat_wavix-1.0.0/MANIFEST.in +2 -0
- pipecat_wavix-1.0.0/PKG-INFO +335 -0
- pipecat_wavix-1.0.0/README.md +306 -0
- pipecat_wavix-1.0.0/pyproject.toml +49 -0
- pipecat_wavix-1.0.0/setup.cfg +4 -0
- pipecat_wavix-1.0.0/src/pipecat_wavix/__init__.py +13 -0
- pipecat_wavix-1.0.0/src/pipecat_wavix/wavix_serializer.py +268 -0
- pipecat_wavix-1.0.0/src/pipecat_wavix.egg-info/PKG-INFO +335 -0
- pipecat_wavix-1.0.0/src/pipecat_wavix.egg-info/SOURCES.txt +11 -0
- pipecat_wavix-1.0.0/src/pipecat_wavix.egg-info/dependency_links.txt +1 -0
- pipecat_wavix-1.0.0/src/pipecat_wavix.egg-info/requires.txt +5 -0
- pipecat_wavix-1.0.0/src/pipecat_wavix.egg-info/top_level.txt +1 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Wavix
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,335 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: pipecat-wavix
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Wavix WebSocket serializer for Pipecat
|
|
5
|
+
Author-email: Wavix <support@wavix.com>
|
|
6
|
+
Project-URL: Homepage, https://github.com/wavix/pipecat-wavix
|
|
7
|
+
Project-URL: Repository, https://github.com/wavix/pipecat-wavix
|
|
8
|
+
Project-URL: Issues, https://github.com/wavix/pipecat-wavix/issues
|
|
9
|
+
Keywords: wavix,pipecat,voice,telephony,websocket,audio,serializer
|
|
10
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
+
Classifier: Operating System :: OS Independent
|
|
18
|
+
Classifier: Topic :: Communications :: Telephony
|
|
19
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
20
|
+
Requires-Python: >=3.10
|
|
21
|
+
Description-Content-Type: text/markdown
|
|
22
|
+
License-File: LICENSE
|
|
23
|
+
Requires-Dist: pipecat-ai[deepgram,runner,websocket]>=0.0.105
|
|
24
|
+
Requires-Dist: loguru>=0.7.0
|
|
25
|
+
Requires-Dist: dotenv>=0.9.9
|
|
26
|
+
Requires-Dist: fastapi>=0.135.1
|
|
27
|
+
Requires-Dist: pyngrok>=7.5.1
|
|
28
|
+
Dynamic: license-file
|
|
29
|
+
|
|
30
|
+
# pipecat-wavix
|
|
31
|
+
|
|
32
|
+
Stream real-time audio between Pipecat and Wavix using WebSockets.
|
|
33
|
+
|
|
34
|
+
`pipecat-wavix` converts audio between Pipecat frames and the Wavix media stream format so you can build voice-enabled applications quickly.
|
|
35
|
+
|
|
36
|
+
---
|
|
37
|
+
|
|
38
|
+
## What this project does
|
|
39
|
+
|
|
40
|
+
This repository contains the source code for the Wavix Frame Serializer for Pipecat.
|
|
41
|
+
|
|
42
|
+
It lets you stream audio between Pipecat and Wavix by converting audio data between their formats in real time.
|
|
43
|
+
|
|
44
|
+
---
|
|
45
|
+
|
|
46
|
+
## What’s included
|
|
47
|
+
|
|
48
|
+
This project includes:
|
|
49
|
+
|
|
50
|
+
* **WavixFrameSerializer**
|
|
51
|
+
Converts audio between Pipecat frames and the Wavix WebSocket media stream format.
|
|
52
|
+
|
|
53
|
+
* **bot.py**
|
|
54
|
+
A minimal example that runs a Pipecat development bot and connects to a Wavix media stream.
|
|
55
|
+
Use this if you want full control over call handling.
|
|
56
|
+
|
|
57
|
+
* **server.py**
|
|
58
|
+
A complete example that handles the full Wavix call flow, including webhooks, call answering, and media streaming.
|
|
59
|
+
Use this if you want a ready-to-run setup with minimal configuration.
|
|
60
|
+
|
|
61
|
+
---
|
|
62
|
+
|
|
63
|
+
## When to use this
|
|
64
|
+
|
|
65
|
+
Use this project if you want to:
|
|
66
|
+
|
|
67
|
+
* Build voice applications with Pipecat and Wavix
|
|
68
|
+
* Stream real-time audio over WebSockets
|
|
69
|
+
* Prototype or test telephony integration
|
|
70
|
+
|
|
71
|
+
---
|
|
72
|
+
|
|
73
|
+
## Wavix audio format
|
|
74
|
+
|
|
75
|
+
Wavix uses the following audio format:
|
|
76
|
+
|
|
77
|
+
* Format: PCM16
|
|
78
|
+
* Sample rate: 24 kHz
|
|
79
|
+
* Bit depth: 16-bit
|
|
80
|
+
* Frame size: 20 ms
|
|
81
|
+
* Channels: mono
|
|
82
|
+
* Endianness: little-endian
|
|
83
|
+
|
|
84
|
+
---
|
|
85
|
+
|
|
86
|
+
## Prerequisites
|
|
87
|
+
|
|
88
|
+
### Wavix account
|
|
89
|
+
|
|
90
|
+
Before you start, make sure you have:
|
|
91
|
+
|
|
92
|
+
* A Wavix account: https://docs.wavix.com/getting-started/create-account
|
|
93
|
+
* A Wavix phone number
|
|
94
|
+
|
|
95
|
+
### Environment variables
|
|
96
|
+
|
|
97
|
+
Set these environment variables:
|
|
98
|
+
|
|
99
|
+
* `WAVIX_API_KEY` – your Wavix API key
|
|
100
|
+
* `OPENAI_API_KEY` – your OpenAI API key
|
|
101
|
+
* `DEEPGRAM_API_KEY` – your Deepgram API key
|
|
102
|
+
* `CARTESIA_API_KEY` – your Cartesia API key
|
|
103
|
+
|
|
104
|
+
### System requirements
|
|
105
|
+
|
|
106
|
+
* Python 3.12
|
|
107
|
+
* `uv` package manager
|
|
108
|
+
* ngrok (for local development)
|
|
109
|
+
|
|
110
|
+
---
|
|
111
|
+
|
|
112
|
+
## Setup
|
|
113
|
+
|
|
114
|
+
Install the package:
|
|
115
|
+
|
|
116
|
+
```bash
|
|
117
|
+
pip install pipecat-wavix
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
If you use `uv`, add it to your `pyproject.toml`:
|
|
121
|
+
|
|
122
|
+
```toml
|
|
123
|
+
[project]
|
|
124
|
+
dependencies = [
|
|
125
|
+
"pipecat-wavix>=1.0.0"
|
|
126
|
+
]
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
Then install dependencies:
|
|
130
|
+
|
|
131
|
+
```bash
|
|
132
|
+
uv sync
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
---
|
|
136
|
+
|
|
137
|
+
## Use with a Pipecat pipeline
|
|
138
|
+
|
|
139
|
+
Import the serializer:
|
|
140
|
+
|
|
141
|
+
```python
|
|
142
|
+
from pipecat_wavix import WavixFrameSerializer
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
Configure it:
|
|
146
|
+
|
|
147
|
+
```python
|
|
148
|
+
WAVIX_SAMPLE_RATE = 24000
|
|
149
|
+
BOT_SAMPLE_RATE = 16000
|
|
150
|
+
|
|
151
|
+
serializer = WavixFrameSerializer(
|
|
152
|
+
stream_id=stream_id,
|
|
153
|
+
params=WavixFrameSerializer.InputParams(
|
|
154
|
+
wavix_sample_rate=WAVIX_SAMPLE_RATE,
|
|
155
|
+
sample_rate=BOT_SAMPLE_RATE,
|
|
156
|
+
audio_track="inbound",
|
|
157
|
+
),
|
|
158
|
+
)
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
Set up the transport:
|
|
162
|
+
|
|
163
|
+
```python
|
|
164
|
+
transport = FastAPIWebsocketTransport(
|
|
165
|
+
websocket=websocket,
|
|
166
|
+
params=FastAPIWebsocketParams(
|
|
167
|
+
audio_in_enabled=True,
|
|
168
|
+
audio_in_passthrough=True,
|
|
169
|
+
audio_in_sample_rate=BOT_SAMPLE_RATE,
|
|
170
|
+
audio_out_enabled=True,
|
|
171
|
+
audio_out_sample_rate=WAVIX_SAMPLE_RATE,
|
|
172
|
+
add_wav_header=False,
|
|
173
|
+
serializer=serializer,
|
|
174
|
+
audio_out_10ms_chunks=2,
|
|
175
|
+
fixed_audio_packet_size=960,
|
|
176
|
+
),
|
|
177
|
+
)
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
Outbound audio is automatically converted to Wavix’s required format: PCM16, 24 kHz, mono, little-endian, 20 ms frames.
|
|
181
|
+
|
|
182
|
+
---
|
|
183
|
+
|
|
184
|
+
## Run the example
|
|
185
|
+
|
|
186
|
+
### Option 1: run server.py (recommended)
|
|
187
|
+
|
|
188
|
+
Use `server.py` to handle the full Wavix call flow.
|
|
189
|
+
|
|
190
|
+
Run:
|
|
191
|
+
|
|
192
|
+
```bash
|
|
193
|
+
uv run server.py
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
The server:
|
|
197
|
+
|
|
198
|
+
* Starts a FastAPI app
|
|
199
|
+
* Opens an ngrok tunnel
|
|
200
|
+
* Exposes:
|
|
201
|
+
|
|
202
|
+
* `POST /wavix/inbound` (webhook)
|
|
203
|
+
* `GET /health` (health check)
|
|
204
|
+
* `WS /ws` (WebSocket for media stream)
|
|
205
|
+
|
|
206
|
+
When a call reaches your Wavix number, the server:
|
|
207
|
+
|
|
208
|
+
* Answers the call
|
|
209
|
+
* Starts bidirectional streaming to `/ws`
|
|
210
|
+
* Launches the bot from `bot.py`
|
|
211
|
+
|
|
212
|
+
### What you’ll see
|
|
213
|
+
|
|
214
|
+
The server prints:
|
|
215
|
+
|
|
216
|
+
* Local URL (for example, `http://localhost:7860`)
|
|
217
|
+
* Public ngrok URL
|
|
218
|
+
* Webhook URL (`https://.../wavix/inbound`)
|
|
219
|
+
* WebSocket URL (`wss://.../ws`)
|
|
220
|
+
|
|
221
|
+
### Configure Wavix
|
|
222
|
+
|
|
223
|
+
Set your Wavix number’s voice webhook to:
|
|
224
|
+
|
|
225
|
+
```text
|
|
226
|
+
https://your-public-url/wavix/inbound
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
To update your number:
|
|
230
|
+
|
|
231
|
+
1. Sign in to your Wavix account.
|
|
232
|
+
2. Go to **Numbers & trunks** > **My numbers**.
|
|
233
|
+
3. Select your number.
|
|
234
|
+
4. Choose **Edit number**.
|
|
235
|
+
5. Paste the webhook URL.
|
|
236
|
+
6. Select **Save**.
|
|
237
|
+
|
|
238
|
+
Then call your number. The server handles the rest.
|
|
239
|
+
|
|
240
|
+
### Important
|
|
241
|
+
|
|
242
|
+
* Don’t start ngrok manually in this mode.
|
|
243
|
+
* Don’t call Wavix APIs manually — `server.py` handles everything.
|
|
244
|
+
|
|
245
|
+
---
|
|
246
|
+
|
|
247
|
+
## Run bot.py (standalone mode)
|
|
248
|
+
|
|
249
|
+
Use `bot.py` if you want to run the Pipecat development runner and manage Wavix calls yourself.
|
|
250
|
+
|
|
251
|
+
### What it does
|
|
252
|
+
|
|
253
|
+
* Starts the Pipecat development runner
|
|
254
|
+
* Accepts a WebSocket connection
|
|
255
|
+
* Parses the Wavix handshake
|
|
256
|
+
* Builds the audio pipeline
|
|
257
|
+
|
|
258
|
+
### What it doesn’t do
|
|
259
|
+
|
|
260
|
+
* Doesn’t answer calls
|
|
261
|
+
* Doesn’t create streams
|
|
262
|
+
* Doesn’t replace `server.py`
|
|
263
|
+
|
|
264
|
+
### Run the bot
|
|
265
|
+
|
|
266
|
+
```bash
|
|
267
|
+
uv run bot.py --transport wavix --proxy your-public-hostname
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
Example:
|
|
271
|
+
|
|
272
|
+
```bash
|
|
273
|
+
uv run bot.py --transport wavix --proxy your-ngrok-url.ngrok-free.dev
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
### Expose your local server
|
|
277
|
+
|
|
278
|
+
Start ngrok in a separate terminal:
|
|
279
|
+
|
|
280
|
+
```bash
|
|
281
|
+
ngrok http 7860
|
|
282
|
+
```
|
|
283
|
+
|
|
284
|
+
Use the ngrok hostname as the `--proxy` value (don’t include `https://`, unless required).
|
|
285
|
+
|
|
286
|
+
---
|
|
287
|
+
|
|
288
|
+
## Set up Wavix (standalone mode)
|
|
289
|
+
|
|
290
|
+
In this mode, you must handle call control yourself.
|
|
291
|
+
|
|
292
|
+
### Typical flow
|
|
293
|
+
|
|
294
|
+
1. Get the `call_id` from Wavix webhooks
|
|
295
|
+
https://docs.wavix.com/api-reference/call-webhooks/on-call-event
|
|
296
|
+
|
|
297
|
+
2. Answer the call:
|
|
298
|
+
|
|
299
|
+
```bash
|
|
300
|
+
curl -L "https://api.wavix.com/v1/calls/$CALL_ID/answer" \
|
|
301
|
+
-H "Authorization: Bearer $WAVIX_API_KEY" \
|
|
302
|
+
-H "Content-Type: application/json" \
|
|
303
|
+
-d '{}'
|
|
304
|
+
```
|
|
305
|
+
|
|
306
|
+
3. Start streaming:
|
|
307
|
+
|
|
308
|
+
```bash
|
|
309
|
+
curl -L "https://api.wavix.com/v1/calls/$CALL_ID/streams" \
|
|
310
|
+
-H "Authorization: Bearer $WAVIX_API_KEY" \
|
|
311
|
+
-H "Content-Type: application/json" \
|
|
312
|
+
-d '{
|
|
313
|
+
"stream_url": "wss://your-public-hostname/ws",
|
|
314
|
+
"stream_type": "twoway",
|
|
315
|
+
"stream_channel": "inbound"
|
|
316
|
+
}'
|
|
317
|
+
```
|
|
318
|
+
|
|
319
|
+
---
|
|
320
|
+
|
|
321
|
+
## When to use each mode
|
|
322
|
+
|
|
323
|
+
Use `server.py` if you want:
|
|
324
|
+
|
|
325
|
+
* A complete, ready-to-run setup
|
|
326
|
+
* Automatic webhook handling
|
|
327
|
+
* Minimal configuration
|
|
328
|
+
|
|
329
|
+
Use `bot.py` if you want:
|
|
330
|
+
|
|
331
|
+
* Full control over call handling
|
|
332
|
+
* Integration with your own backend
|
|
333
|
+
* A development or testing setup
|
|
334
|
+
|
|
335
|
+
---
|
|
@@ -0,0 +1,306 @@
|
|
|
1
|
+
# pipecat-wavix
|
|
2
|
+
|
|
3
|
+
Stream real-time audio between Pipecat and Wavix using WebSockets.
|
|
4
|
+
|
|
5
|
+
`pipecat-wavix` converts audio between Pipecat frames and the Wavix media stream format so you can build voice-enabled applications quickly.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## What this project does
|
|
10
|
+
|
|
11
|
+
This repository contains the source code for the Wavix Frame Serializer for Pipecat.
|
|
12
|
+
|
|
13
|
+
It lets you stream audio between Pipecat and Wavix by converting audio data between their formats in real time.
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
## What’s included
|
|
18
|
+
|
|
19
|
+
This project includes:
|
|
20
|
+
|
|
21
|
+
* **WavixFrameSerializer**
|
|
22
|
+
Converts audio between Pipecat frames and the Wavix WebSocket media stream format.
|
|
23
|
+
|
|
24
|
+
* **bot.py**
|
|
25
|
+
A minimal example that runs a Pipecat development bot and connects to a Wavix media stream.
|
|
26
|
+
Use this if you want full control over call handling.
|
|
27
|
+
|
|
28
|
+
* **server.py**
|
|
29
|
+
A complete example that handles the full Wavix call flow, including webhooks, call answering, and media streaming.
|
|
30
|
+
Use this if you want a ready-to-run setup with minimal configuration.
|
|
31
|
+
|
|
32
|
+
---
|
|
33
|
+
|
|
34
|
+
## When to use this
|
|
35
|
+
|
|
36
|
+
Use this project if you want to:
|
|
37
|
+
|
|
38
|
+
* Build voice applications with Pipecat and Wavix
|
|
39
|
+
* Stream real-time audio over WebSockets
|
|
40
|
+
* Prototype or test telephony integration
|
|
41
|
+
|
|
42
|
+
---
|
|
43
|
+
|
|
44
|
+
## Wavix audio format
|
|
45
|
+
|
|
46
|
+
Wavix uses the following audio format:
|
|
47
|
+
|
|
48
|
+
* Format: PCM16
|
|
49
|
+
* Sample rate: 24 kHz
|
|
50
|
+
* Bit depth: 16-bit
|
|
51
|
+
* Frame size: 20 ms
|
|
52
|
+
* Channels: mono
|
|
53
|
+
* Endianness: little-endian
|
|
54
|
+
|
|
55
|
+
---
|
|
56
|
+
|
|
57
|
+
## Prerequisites
|
|
58
|
+
|
|
59
|
+
### Wavix account
|
|
60
|
+
|
|
61
|
+
Before you start, make sure you have:
|
|
62
|
+
|
|
63
|
+
* A Wavix account: https://docs.wavix.com/getting-started/create-account
|
|
64
|
+
* A Wavix phone number
|
|
65
|
+
|
|
66
|
+
### Environment variables
|
|
67
|
+
|
|
68
|
+
Set these environment variables:
|
|
69
|
+
|
|
70
|
+
* `WAVIX_API_KEY` – your Wavix API key
|
|
71
|
+
* `OPENAI_API_KEY` – your OpenAI API key
|
|
72
|
+
* `DEEPGRAM_API_KEY` – your Deepgram API key
|
|
73
|
+
* `CARTESIA_API_KEY` – your Cartesia API key
|
|
74
|
+
|
|
75
|
+
### System requirements
|
|
76
|
+
|
|
77
|
+
* Python 3.12
|
|
78
|
+
* `uv` package manager
|
|
79
|
+
* ngrok (for local development)
|
|
80
|
+
|
|
81
|
+
---
|
|
82
|
+
|
|
83
|
+
## Setup
|
|
84
|
+
|
|
85
|
+
Install the package:
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
pip install pipecat-wavix
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
If you use `uv`, add it to your `pyproject.toml`:
|
|
92
|
+
|
|
93
|
+
```toml
|
|
94
|
+
[project]
|
|
95
|
+
dependencies = [
|
|
96
|
+
"pipecat-wavix>=1.0.0"
|
|
97
|
+
]
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
Then install dependencies:
|
|
101
|
+
|
|
102
|
+
```bash
|
|
103
|
+
uv sync
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
---
|
|
107
|
+
|
|
108
|
+
## Use with a Pipecat pipeline
|
|
109
|
+
|
|
110
|
+
Import the serializer:
|
|
111
|
+
|
|
112
|
+
```python
|
|
113
|
+
from pipecat_wavix import WavixFrameSerializer
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
Configure it:
|
|
117
|
+
|
|
118
|
+
```python
|
|
119
|
+
WAVIX_SAMPLE_RATE = 24000
|
|
120
|
+
BOT_SAMPLE_RATE = 16000
|
|
121
|
+
|
|
122
|
+
serializer = WavixFrameSerializer(
|
|
123
|
+
stream_id=stream_id,
|
|
124
|
+
params=WavixFrameSerializer.InputParams(
|
|
125
|
+
wavix_sample_rate=WAVIX_SAMPLE_RATE,
|
|
126
|
+
sample_rate=BOT_SAMPLE_RATE,
|
|
127
|
+
audio_track="inbound",
|
|
128
|
+
),
|
|
129
|
+
)
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
Set up the transport:
|
|
133
|
+
|
|
134
|
+
```python
|
|
135
|
+
transport = FastAPIWebsocketTransport(
|
|
136
|
+
websocket=websocket,
|
|
137
|
+
params=FastAPIWebsocketParams(
|
|
138
|
+
audio_in_enabled=True,
|
|
139
|
+
audio_in_passthrough=True,
|
|
140
|
+
audio_in_sample_rate=BOT_SAMPLE_RATE,
|
|
141
|
+
audio_out_enabled=True,
|
|
142
|
+
audio_out_sample_rate=WAVIX_SAMPLE_RATE,
|
|
143
|
+
add_wav_header=False,
|
|
144
|
+
serializer=serializer,
|
|
145
|
+
audio_out_10ms_chunks=2,
|
|
146
|
+
fixed_audio_packet_size=960,
|
|
147
|
+
),
|
|
148
|
+
)
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
Outbound audio is automatically converted to Wavix’s required format: PCM16, 24 kHz, mono, little-endian, 20 ms frames.
|
|
152
|
+
|
|
153
|
+
---
|
|
154
|
+
|
|
155
|
+
## Run the example
|
|
156
|
+
|
|
157
|
+
### Option 1: run server.py (recommended)
|
|
158
|
+
|
|
159
|
+
Use `server.py` to handle the full Wavix call flow.
|
|
160
|
+
|
|
161
|
+
Run:
|
|
162
|
+
|
|
163
|
+
```bash
|
|
164
|
+
uv run server.py
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
The server:
|
|
168
|
+
|
|
169
|
+
* Starts a FastAPI app
|
|
170
|
+
* Opens an ngrok tunnel
|
|
171
|
+
* Exposes:
|
|
172
|
+
|
|
173
|
+
* `POST /wavix/inbound` (webhook)
|
|
174
|
+
* `GET /health` (health check)
|
|
175
|
+
* `WS /ws` (WebSocket for media stream)
|
|
176
|
+
|
|
177
|
+
When a call reaches your Wavix number, the server:
|
|
178
|
+
|
|
179
|
+
* Answers the call
|
|
180
|
+
* Starts bidirectional streaming to `/ws`
|
|
181
|
+
* Launches the bot from `bot.py`
|
|
182
|
+
|
|
183
|
+
### What you’ll see
|
|
184
|
+
|
|
185
|
+
The server prints:
|
|
186
|
+
|
|
187
|
+
* Local URL (for example, `http://localhost:7860`)
|
|
188
|
+
* Public ngrok URL
|
|
189
|
+
* Webhook URL (`https://.../wavix/inbound`)
|
|
190
|
+
* WebSocket URL (`wss://.../ws`)
|
|
191
|
+
|
|
192
|
+
### Configure Wavix
|
|
193
|
+
|
|
194
|
+
Set your Wavix number’s voice webhook to:
|
|
195
|
+
|
|
196
|
+
```text
|
|
197
|
+
https://your-public-url/wavix/inbound
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
To update your number:
|
|
201
|
+
|
|
202
|
+
1. Sign in to your Wavix account.
|
|
203
|
+
2. Go to **Numbers & trunks** > **My numbers**.
|
|
204
|
+
3. Select your number.
|
|
205
|
+
4. Choose **Edit number**.
|
|
206
|
+
5. Paste the webhook URL.
|
|
207
|
+
6. Select **Save**.
|
|
208
|
+
|
|
209
|
+
Then call your number. The server handles the rest.
|
|
210
|
+
|
|
211
|
+
### Important
|
|
212
|
+
|
|
213
|
+
* Don’t start ngrok manually in this mode.
|
|
214
|
+
* Don’t call Wavix APIs manually — `server.py` handles everything.
|
|
215
|
+
|
|
216
|
+
---
|
|
217
|
+
|
|
218
|
+
## Run bot.py (standalone mode)
|
|
219
|
+
|
|
220
|
+
Use `bot.py` if you want to run the Pipecat development runner and manage Wavix calls yourself.
|
|
221
|
+
|
|
222
|
+
### What it does
|
|
223
|
+
|
|
224
|
+
* Starts the Pipecat development runner
|
|
225
|
+
* Accepts a WebSocket connection
|
|
226
|
+
* Parses the Wavix handshake
|
|
227
|
+
* Builds the audio pipeline
|
|
228
|
+
|
|
229
|
+
### What it doesn’t do
|
|
230
|
+
|
|
231
|
+
* Doesn’t answer calls
|
|
232
|
+
* Doesn’t create streams
|
|
233
|
+
* Doesn’t replace `server.py`
|
|
234
|
+
|
|
235
|
+
### Run the bot
|
|
236
|
+
|
|
237
|
+
```bash
|
|
238
|
+
uv run bot.py --transport wavix --proxy your-public-hostname
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
Example:
|
|
242
|
+
|
|
243
|
+
```bash
|
|
244
|
+
uv run bot.py --transport wavix --proxy your-ngrok-url.ngrok-free.dev
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
### Expose your local server
|
|
248
|
+
|
|
249
|
+
Start ngrok in a separate terminal:
|
|
250
|
+
|
|
251
|
+
```bash
|
|
252
|
+
ngrok http 7860
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
Use the ngrok hostname as the `--proxy` value (don’t include `https://`, unless required).
|
|
256
|
+
|
|
257
|
+
---
|
|
258
|
+
|
|
259
|
+
## Set up Wavix (standalone mode)
|
|
260
|
+
|
|
261
|
+
In this mode, you must handle call control yourself.
|
|
262
|
+
|
|
263
|
+
### Typical flow
|
|
264
|
+
|
|
265
|
+
1. Get the `call_id` from Wavix webhooks
|
|
266
|
+
https://docs.wavix.com/api-reference/call-webhooks/on-call-event
|
|
267
|
+
|
|
268
|
+
2. Answer the call:
|
|
269
|
+
|
|
270
|
+
```bash
|
|
271
|
+
curl -L "https://api.wavix.com/v1/calls/$CALL_ID/answer" \
|
|
272
|
+
-H "Authorization: Bearer $WAVIX_API_KEY" \
|
|
273
|
+
-H "Content-Type: application/json" \
|
|
274
|
+
-d '{}'
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
3. Start streaming:
|
|
278
|
+
|
|
279
|
+
```bash
|
|
280
|
+
curl -L "https://api.wavix.com/v1/calls/$CALL_ID/streams" \
|
|
281
|
+
-H "Authorization: Bearer $WAVIX_API_KEY" \
|
|
282
|
+
-H "Content-Type: application/json" \
|
|
283
|
+
-d '{
|
|
284
|
+
"stream_url": "wss://your-public-hostname/ws",
|
|
285
|
+
"stream_type": "twoway",
|
|
286
|
+
"stream_channel": "inbound"
|
|
287
|
+
}'
|
|
288
|
+
```
|
|
289
|
+
|
|
290
|
+
---
|
|
291
|
+
|
|
292
|
+
## When to use each mode
|
|
293
|
+
|
|
294
|
+
Use `server.py` if you want:
|
|
295
|
+
|
|
296
|
+
* A complete, ready-to-run setup
|
|
297
|
+
* Automatic webhook handling
|
|
298
|
+
* Minimal configuration
|
|
299
|
+
|
|
300
|
+
Use `bot.py` if you want:
|
|
301
|
+
|
|
302
|
+
* Full control over call handling
|
|
303
|
+
* Integration with your own backend
|
|
304
|
+
* A development or testing setup
|
|
305
|
+
|
|
306
|
+
---
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=69", "wheel", "build"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "pipecat-wavix"
|
|
7
|
+
version = "1.0.0"
|
|
8
|
+
description = "Wavix WebSocket serializer for Pipecat"
|
|
9
|
+
requires-python = ">=3.10"
|
|
10
|
+
readme = "README.md"
|
|
11
|
+
authors = [
|
|
12
|
+
{name = "Wavix", email="support@wavix.com"}
|
|
13
|
+
]
|
|
14
|
+
|
|
15
|
+
keywords = ["wavix", "pipecat", "voice", "telephony", "websocket", "audio", "serializer"]
|
|
16
|
+
classifiers = [
|
|
17
|
+
"Development Status :: 5 - Production/Stable",
|
|
18
|
+
"Intended Audience :: Developers",
|
|
19
|
+
"License :: OSI Approved :: MIT License",
|
|
20
|
+
"Programming Language :: Python :: 3",
|
|
21
|
+
"Programming Language :: Python :: 3.10",
|
|
22
|
+
"Programming Language :: Python :: 3.11",
|
|
23
|
+
"Programming Language :: Python :: 3.12",
|
|
24
|
+
"Operating System :: OS Independent",
|
|
25
|
+
"Topic :: Communications :: Telephony",
|
|
26
|
+
"Topic :: Software Development :: Libraries :: Python Modules"
|
|
27
|
+
]
|
|
28
|
+
|
|
29
|
+
dependencies = [
|
|
30
|
+
"pipecat-ai[deepgram,runner,websocket]>=0.0.105",
|
|
31
|
+
"loguru>=0.7.0",
|
|
32
|
+
"dotenv>=0.9.9",
|
|
33
|
+
"fastapi>=0.135.1",
|
|
34
|
+
"pyngrok>=7.5.1",
|
|
35
|
+
]
|
|
36
|
+
|
|
37
|
+
[tool.hatch.build.targets.wheel]
|
|
38
|
+
packages = ["src/pipecat_wavix"]
|
|
39
|
+
|
|
40
|
+
[project.urls]
|
|
41
|
+
Homepage = "https://github.com/wavix/pipecat-wavix"
|
|
42
|
+
Repository = "https://github.com/wavix/pipecat-wavix"
|
|
43
|
+
Issues = "https://github.com/wavix/pipecat-wavix/issues"
|
|
44
|
+
|
|
45
|
+
[tool.setuptools]
|
|
46
|
+
package-dir = {"" = "src"}
|
|
47
|
+
|
|
48
|
+
[tool.setuptools.packages.find]
|
|
49
|
+
where = ["src"]
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"""
|
|
2
|
+
pipecat-wavix
|
|
3
|
+
|
|
4
|
+
Wavix WebSocket serializer for Pipecat.
|
|
5
|
+
|
|
6
|
+
This package provides utilities to convert between Pipecat audio frames
|
|
7
|
+
and the Wavix WebSocket media stream protocol.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
from .wavix_serializer import WavixFrameSerializer
|
|
11
|
+
|
|
12
|
+
__all__ = ["WavixFrameSerializer"]
|
|
13
|
+
__version__ = "1.0.0"
|
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
"""
|
|
2
|
+
wavix_serializer.py
|
|
3
|
+
|
|
4
|
+
Single-file Wavix integration for Pipecat.
|
|
5
|
+
|
|
6
|
+
This file contains the Wavix websocket serializer used by Pipecat.
|
|
7
|
+
|
|
8
|
+
Inbound:
|
|
9
|
+
websocket JSON -> base64 PCM -> InputAudioRawFrame
|
|
10
|
+
|
|
11
|
+
Outbound:
|
|
12
|
+
OutputAudioRawFrame -> base64 PCM -> websocket JSON
|
|
13
|
+
|
|
14
|
+
Wavix media contract:
|
|
15
|
+
- format: pcm16
|
|
16
|
+
- sample rate: 24 kHz
|
|
17
|
+
- bit depth: 16-bit
|
|
18
|
+
- frame size: 20 ms
|
|
19
|
+
- channels: mono
|
|
20
|
+
- endianness: little-endian
|
|
21
|
+
"""
|
|
22
|
+
|
|
23
|
+
from __future__ import annotations
|
|
24
|
+
|
|
25
|
+
import base64
|
|
26
|
+
import json
|
|
27
|
+
from typing import Optional
|
|
28
|
+
|
|
29
|
+
from loguru import logger
|
|
30
|
+
|
|
31
|
+
from pipecat.audio.utils import create_stream_resampler
|
|
32
|
+
from pipecat.frames.frames import (
|
|
33
|
+
AudioRawFrame,
|
|
34
|
+
EndFrame,
|
|
35
|
+
Frame,
|
|
36
|
+
InputAudioRawFrame,
|
|
37
|
+
InterruptionFrame,
|
|
38
|
+
OutputTransportMessageFrame,
|
|
39
|
+
OutputTransportMessageUrgentFrame,
|
|
40
|
+
StartFrame,
|
|
41
|
+
)
|
|
42
|
+
from pipecat.serializers.base_serializer import FrameSerializer
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
class WavixFrameSerializer(FrameSerializer):
|
|
46
|
+
"""
|
|
47
|
+
Serializer for Wavix websocket messages.
|
|
48
|
+
|
|
49
|
+
Wire format:
|
|
50
|
+
- JSON websocket messages
|
|
51
|
+
- audio payload is base64-encoded PCM16
|
|
52
|
+
- Wavix wire sample rate is 24 kHz
|
|
53
|
+
- mono audio
|
|
54
|
+
|
|
55
|
+
Inbound media:
|
|
56
|
+
{
|
|
57
|
+
"event": "media",
|
|
58
|
+
"stream_id": "...",
|
|
59
|
+
"media": {
|
|
60
|
+
"payload": "<base64 pcm16>"
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
Outbound media:
|
|
65
|
+
same structure as above
|
|
66
|
+
"""
|
|
67
|
+
|
|
68
|
+
WAVIX_SAMPLE_RATE: int = 24000
|
|
69
|
+
NUM_CHANNELS: int = 1
|
|
70
|
+
BYTES_PER_SAMPLE: int = 2
|
|
71
|
+
FRAME_DURATION_MS: int = 20
|
|
72
|
+
FRAME_BYTES: int = (
|
|
73
|
+
WAVIX_SAMPLE_RATE * FRAME_DURATION_MS // 1000 * NUM_CHANNELS * BYTES_PER_SAMPLE
|
|
74
|
+
)
|
|
75
|
+
|
|
76
|
+
class InputParams(FrameSerializer.InputParams):
|
|
77
|
+
"""
|
|
78
|
+
Serializer config.
|
|
79
|
+
|
|
80
|
+
wavix_sample_rate:
|
|
81
|
+
The websocket wire sample rate expected by Wavix.
|
|
82
|
+
sample_rate:
|
|
83
|
+
The internal Pipecat input sample rate.
|
|
84
|
+
This is typically 16000 for STT + VAD.
|
|
85
|
+
audio_track:
|
|
86
|
+
Optional track filter for inbound media.
|
|
87
|
+
"""
|
|
88
|
+
|
|
89
|
+
wavix_sample_rate: int = 24000
|
|
90
|
+
sample_rate: Optional[int] = None
|
|
91
|
+
audio_track: Optional[str] = "inbound"
|
|
92
|
+
|
|
93
|
+
def __init__(
|
|
94
|
+
self,
|
|
95
|
+
stream_id: str,
|
|
96
|
+
params: Optional["WavixFrameSerializer.InputParams"] = None,
|
|
97
|
+
) -> None:
|
|
98
|
+
if params is None:
|
|
99
|
+
params = WavixFrameSerializer.InputParams()
|
|
100
|
+
|
|
101
|
+
super().__init__(params)
|
|
102
|
+
|
|
103
|
+
self._stream_id = stream_id
|
|
104
|
+
self._sample_rate = params.sample_rate
|
|
105
|
+
self._wavix_sample_rate = params.wavix_sample_rate
|
|
106
|
+
self._audio_track = params.audio_track
|
|
107
|
+
|
|
108
|
+
# Audio is transmitted on the wire as little-endian PCM16 mono at 24 kHz.
|
|
109
|
+
# We resample inbound to the pipeline rate and outbound back to the Wavix rate.
|
|
110
|
+
self._input_resampler = create_stream_resampler()
|
|
111
|
+
self._output_resampler = create_stream_resampler()
|
|
112
|
+
|
|
113
|
+
async def setup(self, frame: StartFrame) -> None:
|
|
114
|
+
"""
|
|
115
|
+
Initialize serializer sample rate after pipeline startup.
|
|
116
|
+
|
|
117
|
+
If sample_rate is explicitly provided in params, use it.
|
|
118
|
+
Otherwise use StartFrame.audio_in_sample_rate.
|
|
119
|
+
"""
|
|
120
|
+
self._sample_rate = self._params.sample_rate or frame.audio_in_sample_rate
|
|
121
|
+
|
|
122
|
+
logger.debug(
|
|
123
|
+
"Serializer setup: internal_sample_rate={} wavix_sample_rate={}",
|
|
124
|
+
self._sample_rate,
|
|
125
|
+
self._wavix_sample_rate,
|
|
126
|
+
)
|
|
127
|
+
|
|
128
|
+
async def serialize(self, frame: Frame) -> str | bytes | None:
|
|
129
|
+
"""
|
|
130
|
+
Convert Pipecat frames -> Wavix websocket messages.
|
|
131
|
+
|
|
132
|
+
Outbound audio is normalized to Wavix's required format:
|
|
133
|
+
PCM16, 24 kHz, mono, little-endian, 20 ms frames.
|
|
134
|
+
"""
|
|
135
|
+
if isinstance(frame, StartFrame):
|
|
136
|
+
await self.setup(frame)
|
|
137
|
+
return None
|
|
138
|
+
|
|
139
|
+
if isinstance(frame, EndFrame):
|
|
140
|
+
return None
|
|
141
|
+
|
|
142
|
+
if self._sample_rate is None:
|
|
143
|
+
logger.warning("Sample rate not set up yet, cannot serialize audio frames.")
|
|
144
|
+
return None
|
|
145
|
+
|
|
146
|
+
if isinstance(frame, InterruptionFrame):
|
|
147
|
+
return json.dumps({"event": "clear", "stream_id": self._stream_id})
|
|
148
|
+
|
|
149
|
+
if isinstance(frame, AudioRawFrame):
|
|
150
|
+
audio = frame.audio
|
|
151
|
+
if not audio:
|
|
152
|
+
return None
|
|
153
|
+
|
|
154
|
+
if frame.sample_rate != self._wavix_sample_rate:
|
|
155
|
+
audio = await self._output_resampler.resample(
|
|
156
|
+
audio,
|
|
157
|
+
frame.sample_rate,
|
|
158
|
+
self._wavix_sample_rate,
|
|
159
|
+
)
|
|
160
|
+
if not audio:
|
|
161
|
+
return None
|
|
162
|
+
|
|
163
|
+
if frame.num_channels != self.NUM_CHANNELS:
|
|
164
|
+
logger.warning(
|
|
165
|
+
"Outbound channel mismatch: got {}, expected {}",
|
|
166
|
+
frame.num_channels,
|
|
167
|
+
self.NUM_CHANNELS,
|
|
168
|
+
)
|
|
169
|
+
return None
|
|
170
|
+
|
|
171
|
+
chunk = bytes(audio)
|
|
172
|
+
if len(chunk) != self.FRAME_BYTES:
|
|
173
|
+
logger.warning(
|
|
174
|
+
"Outbound frame size mismatch got={} expected={} frame_ms={}",
|
|
175
|
+
len(chunk),
|
|
176
|
+
self.FRAME_BYTES,
|
|
177
|
+
self.FRAME_DURATION_MS,
|
|
178
|
+
)
|
|
179
|
+
|
|
180
|
+
payload = base64.b64encode(chunk).decode("utf-8")
|
|
181
|
+
if not payload:
|
|
182
|
+
return None
|
|
183
|
+
|
|
184
|
+
return json.dumps(
|
|
185
|
+
{
|
|
186
|
+
"event": "media",
|
|
187
|
+
"stream_id": self._stream_id,
|
|
188
|
+
"media": {"payload": payload},
|
|
189
|
+
}
|
|
190
|
+
)
|
|
191
|
+
|
|
192
|
+
if isinstance(frame, (OutputTransportMessageFrame, OutputTransportMessageUrgentFrame)):
|
|
193
|
+
if self.should_ignore_frame(frame):
|
|
194
|
+
return None
|
|
195
|
+
return json.dumps(frame.message)
|
|
196
|
+
|
|
197
|
+
return None
|
|
198
|
+
|
|
199
|
+
async def deserialize(self, data: str | bytes) -> Frame | None:
|
|
200
|
+
"""
|
|
201
|
+
Convert inbound Wavix websocket JSON -> Pipecat InputAudioRawFrame.
|
|
202
|
+
|
|
203
|
+
Inbound Wavix audio arrives as 24 kHz PCM16 mono.
|
|
204
|
+
If internal Pipecat input rate is 16 kHz, we resample here.
|
|
205
|
+
"""
|
|
206
|
+
raw_message = data.decode("utf-8", errors="replace") if isinstance(data, bytes) else data
|
|
207
|
+
|
|
208
|
+
try:
|
|
209
|
+
message = json.loads(raw_message)
|
|
210
|
+
except (json.JSONDecodeError, ValueError) as exc:
|
|
211
|
+
logger.warning("[WavixFrameSerializer] Unparsable WebSocket message: {}", exc)
|
|
212
|
+
return None
|
|
213
|
+
|
|
214
|
+
event = message.get("event")
|
|
215
|
+
|
|
216
|
+
if event == "media":
|
|
217
|
+
media = message.get("media", {})
|
|
218
|
+
track = media.get("track", "inbound")
|
|
219
|
+
|
|
220
|
+
if self._audio_track and track != self._audio_track:
|
|
221
|
+
return None
|
|
222
|
+
|
|
223
|
+
payload_b64 = media.get("payload", "")
|
|
224
|
+
if not payload_b64:
|
|
225
|
+
return None
|
|
226
|
+
|
|
227
|
+
try:
|
|
228
|
+
pcm_bytes = base64.b64decode(payload_b64)
|
|
229
|
+
except Exception as exc:
|
|
230
|
+
logger.warning("[WavixFrameSerializer] base64 decode error: {}", exc)
|
|
231
|
+
return None
|
|
232
|
+
|
|
233
|
+
if not pcm_bytes:
|
|
234
|
+
return None
|
|
235
|
+
|
|
236
|
+
if len(pcm_bytes) != self.FRAME_BYTES:
|
|
237
|
+
logger.warning(
|
|
238
|
+
"[WavixFrameSerializer] inbound frame size mismatch got={} expected={} frame_ms={}",
|
|
239
|
+
len(pcm_bytes),
|
|
240
|
+
self.FRAME_BYTES,
|
|
241
|
+
self.FRAME_DURATION_MS,
|
|
242
|
+
)
|
|
243
|
+
|
|
244
|
+
if self._sample_rate is None:
|
|
245
|
+
logger.warning("[WavixFrameSerializer] Internal sample rate is not initialized")
|
|
246
|
+
return None
|
|
247
|
+
|
|
248
|
+
if self._wavix_sample_rate != self._sample_rate:
|
|
249
|
+
pcm_bytes = await self._input_resampler.resample(
|
|
250
|
+
pcm_bytes,
|
|
251
|
+
self._wavix_sample_rate,
|
|
252
|
+
self._sample_rate,
|
|
253
|
+
)
|
|
254
|
+
|
|
255
|
+
if pcm_bytes is None or len(pcm_bytes) == 0:
|
|
256
|
+
return None
|
|
257
|
+
|
|
258
|
+
return InputAudioRawFrame(
|
|
259
|
+
audio=pcm_bytes,
|
|
260
|
+
num_channels=self.NUM_CHANNELS,
|
|
261
|
+
sample_rate=self._sample_rate,
|
|
262
|
+
)
|
|
263
|
+
|
|
264
|
+
if event in {"connected", "start", "stop", "mark"}:
|
|
265
|
+
return None
|
|
266
|
+
|
|
267
|
+
logger.debug("[WavixFrameSerializer] Unknown event ignored: {!r}", event)
|
|
268
|
+
return None
|
|
@@ -0,0 +1,335 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: pipecat-wavix
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Wavix WebSocket serializer for Pipecat
|
|
5
|
+
Author-email: Wavix <support@wavix.com>
|
|
6
|
+
Project-URL: Homepage, https://github.com/wavix/pipecat-wavix
|
|
7
|
+
Project-URL: Repository, https://github.com/wavix/pipecat-wavix
|
|
8
|
+
Project-URL: Issues, https://github.com/wavix/pipecat-wavix/issues
|
|
9
|
+
Keywords: wavix,pipecat,voice,telephony,websocket,audio,serializer
|
|
10
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
+
Classifier: Operating System :: OS Independent
|
|
18
|
+
Classifier: Topic :: Communications :: Telephony
|
|
19
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
20
|
+
Requires-Python: >=3.10
|
|
21
|
+
Description-Content-Type: text/markdown
|
|
22
|
+
License-File: LICENSE
|
|
23
|
+
Requires-Dist: pipecat-ai[deepgram,runner,websocket]>=0.0.105
|
|
24
|
+
Requires-Dist: loguru>=0.7.0
|
|
25
|
+
Requires-Dist: dotenv>=0.9.9
|
|
26
|
+
Requires-Dist: fastapi>=0.135.1
|
|
27
|
+
Requires-Dist: pyngrok>=7.5.1
|
|
28
|
+
Dynamic: license-file
|
|
29
|
+
|
|
30
|
+
# pipecat-wavix
|
|
31
|
+
|
|
32
|
+
Stream real-time audio between Pipecat and Wavix using WebSockets.
|
|
33
|
+
|
|
34
|
+
`pipecat-wavix` converts audio between Pipecat frames and the Wavix media stream format so you can build voice-enabled applications quickly.
|
|
35
|
+
|
|
36
|
+
---
|
|
37
|
+
|
|
38
|
+
## What this project does
|
|
39
|
+
|
|
40
|
+
This repository contains the source code for the Wavix Frame Serializer for Pipecat.
|
|
41
|
+
|
|
42
|
+
It lets you stream audio between Pipecat and Wavix by converting audio data between their formats in real time.
|
|
43
|
+
|
|
44
|
+
---
|
|
45
|
+
|
|
46
|
+
## What’s included
|
|
47
|
+
|
|
48
|
+
This project includes:
|
|
49
|
+
|
|
50
|
+
* **WavixFrameSerializer**
|
|
51
|
+
Converts audio between Pipecat frames and the Wavix WebSocket media stream format.
|
|
52
|
+
|
|
53
|
+
* **bot.py**
|
|
54
|
+
A minimal example that runs a Pipecat development bot and connects to a Wavix media stream.
|
|
55
|
+
Use this if you want full control over call handling.
|
|
56
|
+
|
|
57
|
+
* **server.py**
|
|
58
|
+
A complete example that handles the full Wavix call flow, including webhooks, call answering, and media streaming.
|
|
59
|
+
Use this if you want a ready-to-run setup with minimal configuration.
|
|
60
|
+
|
|
61
|
+
---
|
|
62
|
+
|
|
63
|
+
## When to use this
|
|
64
|
+
|
|
65
|
+
Use this project if you want to:
|
|
66
|
+
|
|
67
|
+
* Build voice applications with Pipecat and Wavix
|
|
68
|
+
* Stream real-time audio over WebSockets
|
|
69
|
+
* Prototype or test telephony integration
|
|
70
|
+
|
|
71
|
+
---
|
|
72
|
+
|
|
73
|
+
## Wavix audio format
|
|
74
|
+
|
|
75
|
+
Wavix uses the following audio format:
|
|
76
|
+
|
|
77
|
+
* Format: PCM16
|
|
78
|
+
* Sample rate: 24 kHz
|
|
79
|
+
* Bit depth: 16-bit
|
|
80
|
+
* Frame size: 20 ms
|
|
81
|
+
* Channels: mono
|
|
82
|
+
* Endianness: little-endian
|
|
83
|
+
|
|
84
|
+
---
|
|
85
|
+
|
|
86
|
+
## Prerequisites
|
|
87
|
+
|
|
88
|
+
### Wavix account
|
|
89
|
+
|
|
90
|
+
Before you start, make sure you have:
|
|
91
|
+
|
|
92
|
+
* A Wavix account: https://docs.wavix.com/getting-started/create-account
|
|
93
|
+
* A Wavix phone number
|
|
94
|
+
|
|
95
|
+
### Environment variables
|
|
96
|
+
|
|
97
|
+
Set these environment variables:
|
|
98
|
+
|
|
99
|
+
* `WAVIX_API_KEY` – your Wavix API key
|
|
100
|
+
* `OPENAI_API_KEY` – your OpenAI API key
|
|
101
|
+
* `DEEPGRAM_API_KEY` – your Deepgram API key
|
|
102
|
+
* `CARTESIA_API_KEY` – your Cartesia API key
|
|
103
|
+
|
|
104
|
+
### System requirements
|
|
105
|
+
|
|
106
|
+
* Python 3.12
|
|
107
|
+
* `uv` package manager
|
|
108
|
+
* ngrok (for local development)
|
|
109
|
+
|
|
110
|
+
---
|
|
111
|
+
|
|
112
|
+
## Setup
|
|
113
|
+
|
|
114
|
+
Install the package:
|
|
115
|
+
|
|
116
|
+
```bash
|
|
117
|
+
pip install pipecat-wavix
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
If you use `uv`, add it to your `pyproject.toml`:
|
|
121
|
+
|
|
122
|
+
```toml
|
|
123
|
+
[project]
|
|
124
|
+
dependencies = [
|
|
125
|
+
"pipecat-wavix>=1.0.0"
|
|
126
|
+
]
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
Then install dependencies:
|
|
130
|
+
|
|
131
|
+
```bash
|
|
132
|
+
uv sync
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
---
|
|
136
|
+
|
|
137
|
+
## Use with a Pipecat pipeline
|
|
138
|
+
|
|
139
|
+
Import the serializer:
|
|
140
|
+
|
|
141
|
+
```python
|
|
142
|
+
from pipecat_wavix import WavixFrameSerializer
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
Configure it:
|
|
146
|
+
|
|
147
|
+
```python
|
|
148
|
+
WAVIX_SAMPLE_RATE = 24000
|
|
149
|
+
BOT_SAMPLE_RATE = 16000
|
|
150
|
+
|
|
151
|
+
serializer = WavixFrameSerializer(
|
|
152
|
+
stream_id=stream_id,
|
|
153
|
+
params=WavixFrameSerializer.InputParams(
|
|
154
|
+
wavix_sample_rate=WAVIX_SAMPLE_RATE,
|
|
155
|
+
sample_rate=BOT_SAMPLE_RATE,
|
|
156
|
+
audio_track="inbound",
|
|
157
|
+
),
|
|
158
|
+
)
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
Set up the transport:
|
|
162
|
+
|
|
163
|
+
```python
|
|
164
|
+
transport = FastAPIWebsocketTransport(
|
|
165
|
+
websocket=websocket,
|
|
166
|
+
params=FastAPIWebsocketParams(
|
|
167
|
+
audio_in_enabled=True,
|
|
168
|
+
audio_in_passthrough=True,
|
|
169
|
+
audio_in_sample_rate=BOT_SAMPLE_RATE,
|
|
170
|
+
audio_out_enabled=True,
|
|
171
|
+
audio_out_sample_rate=WAVIX_SAMPLE_RATE,
|
|
172
|
+
add_wav_header=False,
|
|
173
|
+
serializer=serializer,
|
|
174
|
+
audio_out_10ms_chunks=2,
|
|
175
|
+
fixed_audio_packet_size=960,
|
|
176
|
+
),
|
|
177
|
+
)
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
Outbound audio is automatically converted to Wavix’s required format: PCM16, 24 kHz, mono, little-endian, 20 ms frames.
|
|
181
|
+
|
|
182
|
+
---
|
|
183
|
+
|
|
184
|
+
## Run the example
|
|
185
|
+
|
|
186
|
+
### Option 1: run server.py (recommended)
|
|
187
|
+
|
|
188
|
+
Use `server.py` to handle the full Wavix call flow.
|
|
189
|
+
|
|
190
|
+
Run:
|
|
191
|
+
|
|
192
|
+
```bash
|
|
193
|
+
uv run server.py
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
The server:
|
|
197
|
+
|
|
198
|
+
* Starts a FastAPI app
|
|
199
|
+
* Opens an ngrok tunnel
|
|
200
|
+
* Exposes:
|
|
201
|
+
|
|
202
|
+
* `POST /wavix/inbound` (webhook)
|
|
203
|
+
* `GET /health` (health check)
|
|
204
|
+
* `WS /ws` (WebSocket for media stream)
|
|
205
|
+
|
|
206
|
+
When a call reaches your Wavix number, the server:
|
|
207
|
+
|
|
208
|
+
* Answers the call
|
|
209
|
+
* Starts bidirectional streaming to `/ws`
|
|
210
|
+
* Launches the bot from `bot.py`
|
|
211
|
+
|
|
212
|
+
### What you’ll see
|
|
213
|
+
|
|
214
|
+
The server prints:
|
|
215
|
+
|
|
216
|
+
* Local URL (for example, `http://localhost:7860`)
|
|
217
|
+
* Public ngrok URL
|
|
218
|
+
* Webhook URL (`https://.../wavix/inbound`)
|
|
219
|
+
* WebSocket URL (`wss://.../ws`)
|
|
220
|
+
|
|
221
|
+
### Configure Wavix
|
|
222
|
+
|
|
223
|
+
Set your Wavix number’s voice webhook to:
|
|
224
|
+
|
|
225
|
+
```text
|
|
226
|
+
https://your-public-url/wavix/inbound
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
To update your number:
|
|
230
|
+
|
|
231
|
+
1. Sign in to your Wavix account.
|
|
232
|
+
2. Go to **Numbers & trunks** > **My numbers**.
|
|
233
|
+
3. Select your number.
|
|
234
|
+
4. Choose **Edit number**.
|
|
235
|
+
5. Paste the webhook URL.
|
|
236
|
+
6. Select **Save**.
|
|
237
|
+
|
|
238
|
+
Then call your number. The server handles the rest.
|
|
239
|
+
|
|
240
|
+
### Important
|
|
241
|
+
|
|
242
|
+
* Don’t start ngrok manually in this mode.
|
|
243
|
+
* Don’t call Wavix APIs manually — `server.py` handles everything.
|
|
244
|
+
|
|
245
|
+
---
|
|
246
|
+
|
|
247
|
+
## Run bot.py (standalone mode)
|
|
248
|
+
|
|
249
|
+
Use `bot.py` if you want to run the Pipecat development runner and manage Wavix calls yourself.
|
|
250
|
+
|
|
251
|
+
### What it does
|
|
252
|
+
|
|
253
|
+
* Starts the Pipecat development runner
|
|
254
|
+
* Accepts a WebSocket connection
|
|
255
|
+
* Parses the Wavix handshake
|
|
256
|
+
* Builds the audio pipeline
|
|
257
|
+
|
|
258
|
+
### What it doesn’t do
|
|
259
|
+
|
|
260
|
+
* Doesn’t answer calls
|
|
261
|
+
* Doesn’t create streams
|
|
262
|
+
* Doesn’t replace `server.py`
|
|
263
|
+
|
|
264
|
+
### Run the bot
|
|
265
|
+
|
|
266
|
+
```bash
|
|
267
|
+
uv run bot.py --transport wavix --proxy your-public-hostname
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
Example:
|
|
271
|
+
|
|
272
|
+
```bash
|
|
273
|
+
uv run bot.py --transport wavix --proxy your-ngrok-url.ngrok-free.dev
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
### Expose your local server
|
|
277
|
+
|
|
278
|
+
Start ngrok in a separate terminal:
|
|
279
|
+
|
|
280
|
+
```bash
|
|
281
|
+
ngrok http 7860
|
|
282
|
+
```
|
|
283
|
+
|
|
284
|
+
Use the ngrok hostname as the `--proxy` value (don’t include `https://`, unless required).
|
|
285
|
+
|
|
286
|
+
---
|
|
287
|
+
|
|
288
|
+
## Set up Wavix (standalone mode)
|
|
289
|
+
|
|
290
|
+
In this mode, you must handle call control yourself.
|
|
291
|
+
|
|
292
|
+
### Typical flow
|
|
293
|
+
|
|
294
|
+
1. Get the `call_id` from Wavix webhooks
|
|
295
|
+
https://docs.wavix.com/api-reference/call-webhooks/on-call-event
|
|
296
|
+
|
|
297
|
+
2. Answer the call:
|
|
298
|
+
|
|
299
|
+
```bash
|
|
300
|
+
curl -L "https://api.wavix.com/v1/calls/$CALL_ID/answer" \
|
|
301
|
+
-H "Authorization: Bearer $WAVIX_API_KEY" \
|
|
302
|
+
-H "Content-Type: application/json" \
|
|
303
|
+
-d '{}'
|
|
304
|
+
```
|
|
305
|
+
|
|
306
|
+
3. Start streaming:
|
|
307
|
+
|
|
308
|
+
```bash
|
|
309
|
+
curl -L "https://api.wavix.com/v1/calls/$CALL_ID/streams" \
|
|
310
|
+
-H "Authorization: Bearer $WAVIX_API_KEY" \
|
|
311
|
+
-H "Content-Type: application/json" \
|
|
312
|
+
-d '{
|
|
313
|
+
"stream_url": "wss://your-public-hostname/ws",
|
|
314
|
+
"stream_type": "twoway",
|
|
315
|
+
"stream_channel": "inbound"
|
|
316
|
+
}'
|
|
317
|
+
```
|
|
318
|
+
|
|
319
|
+
---
|
|
320
|
+
|
|
321
|
+
## When to use each mode
|
|
322
|
+
|
|
323
|
+
Use `server.py` if you want:
|
|
324
|
+
|
|
325
|
+
* A complete, ready-to-run setup
|
|
326
|
+
* Automatic webhook handling
|
|
327
|
+
* Minimal configuration
|
|
328
|
+
|
|
329
|
+
Use `bot.py` if you want:
|
|
330
|
+
|
|
331
|
+
* Full control over call handling
|
|
332
|
+
* Integration with your own backend
|
|
333
|
+
* A development or testing setup
|
|
334
|
+
|
|
335
|
+
---
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
MANIFEST.in
|
|
3
|
+
README.md
|
|
4
|
+
pyproject.toml
|
|
5
|
+
src/pipecat_wavix/__init__.py
|
|
6
|
+
src/pipecat_wavix/wavix_serializer.py
|
|
7
|
+
src/pipecat_wavix.egg-info/PKG-INFO
|
|
8
|
+
src/pipecat_wavix.egg-info/SOURCES.txt
|
|
9
|
+
src/pipecat_wavix.egg-info/dependency_links.txt
|
|
10
|
+
src/pipecat_wavix.egg-info/requires.txt
|
|
11
|
+
src/pipecat_wavix.egg-info/top_level.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
pipecat_wavix
|