pipecat-kalpa 0.1.1__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.
- pipecat_kalpa-0.1.1/.env.example +7 -0
- pipecat_kalpa-0.1.1/.gitignore +12 -0
- pipecat_kalpa-0.1.1/CHANGELOG.md +13 -0
- pipecat_kalpa-0.1.1/LICENSE +25 -0
- pipecat_kalpa-0.1.1/PKG-INFO +170 -0
- pipecat_kalpa-0.1.1/README.md +141 -0
- pipecat_kalpa-0.1.1/examples/voice.py +101 -0
- pipecat_kalpa-0.1.1/pyproject.toml +73 -0
- pipecat_kalpa-0.1.1/src/pipecat_kalpa/__init__.py +5 -0
- pipecat_kalpa-0.1.1/src/pipecat_kalpa/py.typed +0 -0
- pipecat_kalpa-0.1.1/src/pipecat_kalpa/tts.py +848 -0
- pipecat_kalpa-0.1.1/tests/test_tts.py +782 -0
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.1.1
|
|
4
|
+
|
|
5
|
+
- Publish the integration on PyPI with GitHub Actions trusted publishing.
|
|
6
|
+
- Update installation instructions and make the README links work on PyPI.
|
|
7
|
+
- No changes to the text-to-speech services since 0.1.0.
|
|
8
|
+
|
|
9
|
+
## 0.1.0
|
|
10
|
+
|
|
11
|
+
- Add WebSocket and HTTP text-to-speech services for Kalpa.
|
|
12
|
+
- Support interruption handling and runtime voice and model settings.
|
|
13
|
+
- Include a browser voice example and automated tests.
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
BSD 2-Clause License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024–2026, Daily
|
|
4
|
+
Copyright (c) 2026, Kalpa Labs
|
|
5
|
+
|
|
6
|
+
Redistribution and use in source and binary forms, with or without
|
|
7
|
+
modification, are permitted provided that the following conditions are met:
|
|
8
|
+
|
|
9
|
+
1. Redistributions of source code must retain the above copyright notice, this
|
|
10
|
+
list of conditions and the following disclaimer.
|
|
11
|
+
|
|
12
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
13
|
+
this list of conditions and the following disclaimer in the documentation
|
|
14
|
+
and/or other materials provided with the distribution.
|
|
15
|
+
|
|
16
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
17
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
18
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
19
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
20
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
21
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
22
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
23
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
24
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
25
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: pipecat-kalpa
|
|
3
|
+
Version: 0.1.1
|
|
4
|
+
Summary: Kalpa text-to-speech services for Pipecat
|
|
5
|
+
Project-URL: Homepage, https://kalpalabs.ai
|
|
6
|
+
Project-URL: Documentation, https://github.com/kalpalabs/pipecat-kalpa#readme
|
|
7
|
+
Project-URL: Repository, https://github.com/kalpalabs/pipecat-kalpa
|
|
8
|
+
Project-URL: Issues, https://github.com/kalpalabs/pipecat-kalpa/issues
|
|
9
|
+
Project-URL: Changelog, https://github.com/kalpalabs/pipecat-kalpa/blob/main/CHANGELOG.md
|
|
10
|
+
Author: Kalpa Labs
|
|
11
|
+
License-Expression: BSD-2-Clause
|
|
12
|
+
License-File: LICENSE
|
|
13
|
+
Keywords: kalpa,pipecat,speech,tts
|
|
14
|
+
Classifier: Development Status :: 4 - Beta
|
|
15
|
+
Classifier: Intended Audience :: Developers
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
20
|
+
Classifier: Topic :: Multimedia :: Sound/Audio :: Speech
|
|
21
|
+
Requires-Python: >=3.11
|
|
22
|
+
Requires-Dist: aiohttp<4,>=3.14
|
|
23
|
+
Requires-Dist: loguru<0.8,>=0.7.3
|
|
24
|
+
Requires-Dist: pipecat-ai<1.14.0,>=1.13.0
|
|
25
|
+
Requires-Dist: websockets>=13.1
|
|
26
|
+
Provides-Extra: examples
|
|
27
|
+
Requires-Dist: pipecat-ai[deepgram,openai,runner,webrtc]<1.14.0,>=1.13.0; extra == 'examples'
|
|
28
|
+
Description-Content-Type: text/markdown
|
|
29
|
+
|
|
30
|
+
# Kalpa for Pipecat
|
|
31
|
+
|
|
32
|
+
Kalpa text-to-speech services for [Pipecat](https://pipecat.ai), maintained by
|
|
33
|
+
[Kalpa Labs](https://kalpalabs.ai), the company providing the Kalpa API.
|
|
34
|
+
|
|
35
|
+
This community integration provides `KalpaTTSService` for WebSocket streaming
|
|
36
|
+
and `KalpaHttpTTSService` for HTTP streaming. See the
|
|
37
|
+
[Kalpa speech documentation](https://docs.kalpalabs.ai/text-to-speech) for
|
|
38
|
+
available voices, models, and languages.
|
|
39
|
+
|
|
40
|
+
## Demo
|
|
41
|
+
|
|
42
|
+
[Watch the Pipecat + Kalpa TTS 1 demo](https://github.com/kalpalabs/pipecat-kalpa/releases/download/v0.1.0/kalpa-pipecat-live-demo.mp4).
|
|
43
|
+
The browser conversation includes English and Hindi speech, a spoken
|
|
44
|
+
interruption, and timestamped Pipecat events.
|
|
45
|
+
|
|
46
|
+
## Installation
|
|
47
|
+
|
|
48
|
+
Requires Python 3.11 or later and Pipecat 1.13.x.
|
|
49
|
+
Automated compatibility tests pass with Pipecat 1.13.0 on Python 3.12.
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
uv add pipecat-kalpa
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## Usage
|
|
56
|
+
|
|
57
|
+
Get an API key from the [Kalpa dashboard](https://kalpalabs.ai/dashboard/keys/) and set
|
|
58
|
+
`KALPA_API_KEY` in your environment. See
|
|
59
|
+
[authentication](https://docs.kalpalabs.ai/authentication) for details.
|
|
60
|
+
|
|
61
|
+
```python
|
|
62
|
+
import os
|
|
63
|
+
|
|
64
|
+
from pipecat.pipeline.pipeline import Pipeline
|
|
65
|
+
from pipecat_kalpa import KalpaTTSService
|
|
66
|
+
|
|
67
|
+
tts = KalpaTTSService(api_key=os.environ["KALPA_API_KEY"])
|
|
68
|
+
|
|
69
|
+
# Add Kalpa to an existing voice pipeline.
|
|
70
|
+
pipeline = Pipeline(
|
|
71
|
+
[
|
|
72
|
+
transport.input(),
|
|
73
|
+
stt,
|
|
74
|
+
user_aggregator,
|
|
75
|
+
llm,
|
|
76
|
+
tts,
|
|
77
|
+
transport.output(),
|
|
78
|
+
assistant_aggregator,
|
|
79
|
+
]
|
|
80
|
+
)
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
`transport`, `stt`, `llm`, and the context aggregators are the other components
|
|
84
|
+
of your application. A complete runnable example is provided below.
|
|
85
|
+
|
|
86
|
+
Use `KalpaTTSService` to send a reply's text as it arrives over one WebSocket
|
|
87
|
+
connection. For HTTP streaming, replace it with
|
|
88
|
+
`KalpaHttpTTSService(api_key=os.environ["KALPA_API_KEY"])`.
|
|
89
|
+
|
|
90
|
+
## Configuration
|
|
91
|
+
|
|
92
|
+
Both services require `api_key`. Pass voice and model overrides with
|
|
93
|
+
`settings=KalpaTTSService.Settings(...)` or
|
|
94
|
+
`settings=KalpaHttpTTSService.Settings(...)`:
|
|
95
|
+
|
|
96
|
+
```python
|
|
97
|
+
tts = KalpaTTSService(
|
|
98
|
+
api_key=os.environ["KALPA_API_KEY"],
|
|
99
|
+
settings=KalpaTTSService.Settings(
|
|
100
|
+
voice="18c26f49-9f9c-400c-bec9-7467f28e1db5",
|
|
101
|
+
model="kalpa-tts-1",
|
|
102
|
+
),
|
|
103
|
+
)
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
| Setting | Default | Description |
|
|
107
|
+
| --- | --- | --- |
|
|
108
|
+
| `voice` | `18c26f49-9f9c-400c-bec9-7467f28e1db5` | Arjun. Use a voice ID from `GET /v1/voices`. |
|
|
109
|
+
| `model` | `kalpa-tts-1` | A model ID from `GET /v1/models`. |
|
|
110
|
+
| `language` | `None` | Guides Pipecat sentence splitting; it is not sent to Kalpa. |
|
|
111
|
+
|
|
112
|
+
Voice and model changes can be sent during a session with
|
|
113
|
+
`TTSUpdateSettingsFrame`. The WebSocket service reconnects to apply them.
|
|
114
|
+
|
|
115
|
+
| Constructor argument | Service | Default |
|
|
116
|
+
| --- | --- | --- |
|
|
117
|
+
| `base_url` | WebSocket | `wss://api.kalpalabs.ai` |
|
|
118
|
+
| `base_url` | HTTP | `https://api.kalpalabs.ai` |
|
|
119
|
+
| `text_aggregation_mode` | WebSocket | `TextAggregationMode.TOKEN` |
|
|
120
|
+
| `aiohttp_session` | HTTP | `None`; the service creates and closes its own session |
|
|
121
|
+
|
|
122
|
+
The services produce 24 kHz mono, 16-bit PCM audio. Pipecat's output transport
|
|
123
|
+
resamples it when your pipeline uses a different output rate. Do not pass
|
|
124
|
+
`sample_rate` to these services.
|
|
125
|
+
|
|
126
|
+
## Run the voice example
|
|
127
|
+
|
|
128
|
+
The example uses Deepgram for speech recognition, OpenAI for generating
|
|
129
|
+
replies, and Kalpa for speech output. It connects to your browser over WebRTC.
|
|
130
|
+
|
|
131
|
+
```bash
|
|
132
|
+
git clone https://github.com/kalpalabs/pipecat-kalpa.git
|
|
133
|
+
cd pipecat-kalpa
|
|
134
|
+
uv sync --extra examples
|
|
135
|
+
cp .env.example .env
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
Set `KALPA_API_KEY`, `DEEPGRAM_API_KEY`, and `OPENAI_API_KEY` in `.env`, then run:
|
|
139
|
+
|
|
140
|
+
```bash
|
|
141
|
+
uv run --extra examples python examples/voice.py --transport webrtc
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
Open the address printed by the runner, enable microphone access, and connect.
|
|
145
|
+
Speak while the assistant is talking to interrupt its reply.
|
|
146
|
+
|
|
147
|
+
Set `KALPA_TTS_TRANSPORT=http` to run the same example with HTTP streaming:
|
|
148
|
+
|
|
149
|
+
```bash
|
|
150
|
+
KALPA_TTS_TRANSPORT=http uv run --extra examples python examples/voice.py --transport webrtc
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
`KALPA_VOICE_ID` optionally overrides the example's voice.
|
|
154
|
+
|
|
155
|
+
## Development
|
|
156
|
+
|
|
157
|
+
```bash
|
|
158
|
+
uv sync
|
|
159
|
+
uv run pytest
|
|
160
|
+
uv run ruff check .
|
|
161
|
+
uv run ruff format --check .
|
|
162
|
+
uv build
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
Tests use local fake API servers and do not need API keys. Report issues on
|
|
166
|
+
the [integration repository](https://github.com/kalpalabs/pipecat-kalpa/issues).
|
|
167
|
+
|
|
168
|
+
## License
|
|
169
|
+
|
|
170
|
+
BSD-2-Clause. See [LICENSE](https://github.com/kalpalabs/pipecat-kalpa/blob/main/LICENSE).
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
# Kalpa for Pipecat
|
|
2
|
+
|
|
3
|
+
Kalpa text-to-speech services for [Pipecat](https://pipecat.ai), maintained by
|
|
4
|
+
[Kalpa Labs](https://kalpalabs.ai), the company providing the Kalpa API.
|
|
5
|
+
|
|
6
|
+
This community integration provides `KalpaTTSService` for WebSocket streaming
|
|
7
|
+
and `KalpaHttpTTSService` for HTTP streaming. See the
|
|
8
|
+
[Kalpa speech documentation](https://docs.kalpalabs.ai/text-to-speech) for
|
|
9
|
+
available voices, models, and languages.
|
|
10
|
+
|
|
11
|
+
## Demo
|
|
12
|
+
|
|
13
|
+
[Watch the Pipecat + Kalpa TTS 1 demo](https://github.com/kalpalabs/pipecat-kalpa/releases/download/v0.1.0/kalpa-pipecat-live-demo.mp4).
|
|
14
|
+
The browser conversation includes English and Hindi speech, a spoken
|
|
15
|
+
interruption, and timestamped Pipecat events.
|
|
16
|
+
|
|
17
|
+
## Installation
|
|
18
|
+
|
|
19
|
+
Requires Python 3.11 or later and Pipecat 1.13.x.
|
|
20
|
+
Automated compatibility tests pass with Pipecat 1.13.0 on Python 3.12.
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
uv add pipecat-kalpa
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Usage
|
|
27
|
+
|
|
28
|
+
Get an API key from the [Kalpa dashboard](https://kalpalabs.ai/dashboard/keys/) and set
|
|
29
|
+
`KALPA_API_KEY` in your environment. See
|
|
30
|
+
[authentication](https://docs.kalpalabs.ai/authentication) for details.
|
|
31
|
+
|
|
32
|
+
```python
|
|
33
|
+
import os
|
|
34
|
+
|
|
35
|
+
from pipecat.pipeline.pipeline import Pipeline
|
|
36
|
+
from pipecat_kalpa import KalpaTTSService
|
|
37
|
+
|
|
38
|
+
tts = KalpaTTSService(api_key=os.environ["KALPA_API_KEY"])
|
|
39
|
+
|
|
40
|
+
# Add Kalpa to an existing voice pipeline.
|
|
41
|
+
pipeline = Pipeline(
|
|
42
|
+
[
|
|
43
|
+
transport.input(),
|
|
44
|
+
stt,
|
|
45
|
+
user_aggregator,
|
|
46
|
+
llm,
|
|
47
|
+
tts,
|
|
48
|
+
transport.output(),
|
|
49
|
+
assistant_aggregator,
|
|
50
|
+
]
|
|
51
|
+
)
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
`transport`, `stt`, `llm`, and the context aggregators are the other components
|
|
55
|
+
of your application. A complete runnable example is provided below.
|
|
56
|
+
|
|
57
|
+
Use `KalpaTTSService` to send a reply's text as it arrives over one WebSocket
|
|
58
|
+
connection. For HTTP streaming, replace it with
|
|
59
|
+
`KalpaHttpTTSService(api_key=os.environ["KALPA_API_KEY"])`.
|
|
60
|
+
|
|
61
|
+
## Configuration
|
|
62
|
+
|
|
63
|
+
Both services require `api_key`. Pass voice and model overrides with
|
|
64
|
+
`settings=KalpaTTSService.Settings(...)` or
|
|
65
|
+
`settings=KalpaHttpTTSService.Settings(...)`:
|
|
66
|
+
|
|
67
|
+
```python
|
|
68
|
+
tts = KalpaTTSService(
|
|
69
|
+
api_key=os.environ["KALPA_API_KEY"],
|
|
70
|
+
settings=KalpaTTSService.Settings(
|
|
71
|
+
voice="18c26f49-9f9c-400c-bec9-7467f28e1db5",
|
|
72
|
+
model="kalpa-tts-1",
|
|
73
|
+
),
|
|
74
|
+
)
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
| Setting | Default | Description |
|
|
78
|
+
| --- | --- | --- |
|
|
79
|
+
| `voice` | `18c26f49-9f9c-400c-bec9-7467f28e1db5` | Arjun. Use a voice ID from `GET /v1/voices`. |
|
|
80
|
+
| `model` | `kalpa-tts-1` | A model ID from `GET /v1/models`. |
|
|
81
|
+
| `language` | `None` | Guides Pipecat sentence splitting; it is not sent to Kalpa. |
|
|
82
|
+
|
|
83
|
+
Voice and model changes can be sent during a session with
|
|
84
|
+
`TTSUpdateSettingsFrame`. The WebSocket service reconnects to apply them.
|
|
85
|
+
|
|
86
|
+
| Constructor argument | Service | Default |
|
|
87
|
+
| --- | --- | --- |
|
|
88
|
+
| `base_url` | WebSocket | `wss://api.kalpalabs.ai` |
|
|
89
|
+
| `base_url` | HTTP | `https://api.kalpalabs.ai` |
|
|
90
|
+
| `text_aggregation_mode` | WebSocket | `TextAggregationMode.TOKEN` |
|
|
91
|
+
| `aiohttp_session` | HTTP | `None`; the service creates and closes its own session |
|
|
92
|
+
|
|
93
|
+
The services produce 24 kHz mono, 16-bit PCM audio. Pipecat's output transport
|
|
94
|
+
resamples it when your pipeline uses a different output rate. Do not pass
|
|
95
|
+
`sample_rate` to these services.
|
|
96
|
+
|
|
97
|
+
## Run the voice example
|
|
98
|
+
|
|
99
|
+
The example uses Deepgram for speech recognition, OpenAI for generating
|
|
100
|
+
replies, and Kalpa for speech output. It connects to your browser over WebRTC.
|
|
101
|
+
|
|
102
|
+
```bash
|
|
103
|
+
git clone https://github.com/kalpalabs/pipecat-kalpa.git
|
|
104
|
+
cd pipecat-kalpa
|
|
105
|
+
uv sync --extra examples
|
|
106
|
+
cp .env.example .env
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
Set `KALPA_API_KEY`, `DEEPGRAM_API_KEY`, and `OPENAI_API_KEY` in `.env`, then run:
|
|
110
|
+
|
|
111
|
+
```bash
|
|
112
|
+
uv run --extra examples python examples/voice.py --transport webrtc
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
Open the address printed by the runner, enable microphone access, and connect.
|
|
116
|
+
Speak while the assistant is talking to interrupt its reply.
|
|
117
|
+
|
|
118
|
+
Set `KALPA_TTS_TRANSPORT=http` to run the same example with HTTP streaming:
|
|
119
|
+
|
|
120
|
+
```bash
|
|
121
|
+
KALPA_TTS_TRANSPORT=http uv run --extra examples python examples/voice.py --transport webrtc
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
`KALPA_VOICE_ID` optionally overrides the example's voice.
|
|
125
|
+
|
|
126
|
+
## Development
|
|
127
|
+
|
|
128
|
+
```bash
|
|
129
|
+
uv sync
|
|
130
|
+
uv run pytest
|
|
131
|
+
uv run ruff check .
|
|
132
|
+
uv run ruff format --check .
|
|
133
|
+
uv build
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
Tests use local fake API servers and do not need API keys. Report issues on
|
|
137
|
+
the [integration repository](https://github.com/kalpalabs/pipecat-kalpa/issues).
|
|
138
|
+
|
|
139
|
+
## License
|
|
140
|
+
|
|
141
|
+
BSD-2-Clause. See [LICENSE](https://github.com/kalpalabs/pipecat-kalpa/blob/main/LICENSE).
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"""Run a browser voice conversation with Kalpa speech output."""
|
|
2
|
+
|
|
3
|
+
import os
|
|
4
|
+
|
|
5
|
+
from dotenv import load_dotenv
|
|
6
|
+
from loguru import logger
|
|
7
|
+
from pipecat.audio.vad.silero import SileroVADAnalyzer
|
|
8
|
+
from pipecat.frames.frames import LLMRunFrame
|
|
9
|
+
from pipecat.pipeline.pipeline import Pipeline
|
|
10
|
+
from pipecat.pipeline.worker import PipelineParams, PipelineWorker
|
|
11
|
+
from pipecat.processors.aggregators.llm_context import LLMContext
|
|
12
|
+
from pipecat.processors.aggregators.llm_response_universal import (
|
|
13
|
+
LLMContextAggregatorPair,
|
|
14
|
+
LLMUserAggregatorParams,
|
|
15
|
+
)
|
|
16
|
+
from pipecat.runner.types import RunnerArguments
|
|
17
|
+
from pipecat.runner.utils import create_transport
|
|
18
|
+
from pipecat.services.deepgram.stt import DeepgramSTTService
|
|
19
|
+
from pipecat.services.openai.responses.llm import OpenAIResponsesLLMService
|
|
20
|
+
from pipecat.transports.base_transport import TransportParams
|
|
21
|
+
from pipecat.workers.runner import WorkerRunner
|
|
22
|
+
|
|
23
|
+
from pipecat_kalpa import KalpaHttpTTSService, KalpaTTSService
|
|
24
|
+
|
|
25
|
+
load_dotenv()
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
async def bot(runner_args: RunnerArguments):
|
|
29
|
+
transport = await create_transport(
|
|
30
|
+
runner_args,
|
|
31
|
+
{
|
|
32
|
+
"webrtc": lambda: TransportParams(
|
|
33
|
+
audio_in_enabled=True,
|
|
34
|
+
audio_out_enabled=True,
|
|
35
|
+
),
|
|
36
|
+
},
|
|
37
|
+
)
|
|
38
|
+
tts_transport = os.getenv("KALPA_TTS_TRANSPORT", "websocket")
|
|
39
|
+
service_classes = {"websocket": KalpaTTSService, "http": KalpaHttpTTSService}
|
|
40
|
+
if tts_transport not in service_classes:
|
|
41
|
+
raise ValueError("KALPA_TTS_TRANSPORT must be 'websocket' or 'http'")
|
|
42
|
+
service_class = service_classes[tts_transport]
|
|
43
|
+
voice = os.getenv("KALPA_VOICE_ID")
|
|
44
|
+
tts = service_class(
|
|
45
|
+
api_key=os.environ["KALPA_API_KEY"],
|
|
46
|
+
settings=service_class.Settings(voice=voice) if voice else None,
|
|
47
|
+
)
|
|
48
|
+
stt = DeepgramSTTService(api_key=os.environ["DEEPGRAM_API_KEY"])
|
|
49
|
+
llm = OpenAIResponsesLLMService(
|
|
50
|
+
api_key=os.environ["OPENAI_API_KEY"],
|
|
51
|
+
settings=OpenAIResponsesLLMService.Settings(
|
|
52
|
+
system_instruction=(
|
|
53
|
+
"You are a helpful assistant in a voice conversation. "
|
|
54
|
+
"Keep replies brief and suitable for speaking aloud."
|
|
55
|
+
),
|
|
56
|
+
),
|
|
57
|
+
)
|
|
58
|
+
context = LLMContext()
|
|
59
|
+
user_aggregator, assistant_aggregator = LLMContextAggregatorPair(
|
|
60
|
+
context,
|
|
61
|
+
user_params=LLMUserAggregatorParams(vad_analyzer=SileroVADAnalyzer()),
|
|
62
|
+
)
|
|
63
|
+
pipeline = Pipeline(
|
|
64
|
+
[
|
|
65
|
+
transport.input(),
|
|
66
|
+
stt,
|
|
67
|
+
user_aggregator,
|
|
68
|
+
llm,
|
|
69
|
+
tts,
|
|
70
|
+
transport.output(),
|
|
71
|
+
assistant_aggregator,
|
|
72
|
+
]
|
|
73
|
+
)
|
|
74
|
+
worker = PipelineWorker(
|
|
75
|
+
pipeline,
|
|
76
|
+
params=PipelineParams(enable_metrics=True, enable_usage_metrics=True),
|
|
77
|
+
idle_timeout_secs=runner_args.pipeline_idle_timeout_secs,
|
|
78
|
+
)
|
|
79
|
+
runner = WorkerRunner(handle_sigint=runner_args.handle_sigint)
|
|
80
|
+
await runner.add_workers(worker)
|
|
81
|
+
|
|
82
|
+
@transport.event_handler("on_client_connected")
|
|
83
|
+
async def on_client_connected(transport, client):
|
|
84
|
+
logger.info("Client connected")
|
|
85
|
+
context.add_message(
|
|
86
|
+
{"role": "developer", "content": "Briefly introduce yourself to the user."}
|
|
87
|
+
)
|
|
88
|
+
await worker.queue_frames([LLMRunFrame()])
|
|
89
|
+
|
|
90
|
+
@transport.event_handler("on_client_disconnected")
|
|
91
|
+
async def on_client_disconnected(transport, client):
|
|
92
|
+
logger.info("Client disconnected")
|
|
93
|
+
await runner.cancel()
|
|
94
|
+
|
|
95
|
+
await runner.run()
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
if __name__ == "__main__":
|
|
99
|
+
from pipecat.runner.run import main
|
|
100
|
+
|
|
101
|
+
main()
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling>=1.27,<2"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "pipecat-kalpa"
|
|
7
|
+
version = "0.1.1"
|
|
8
|
+
description = "Kalpa text-to-speech services for Pipecat"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.11"
|
|
11
|
+
license = "BSD-2-Clause"
|
|
12
|
+
license-files = ["LICENSE"]
|
|
13
|
+
authors = [{ name = "Kalpa Labs" }]
|
|
14
|
+
keywords = ["pipecat", "kalpa", "tts", "speech"]
|
|
15
|
+
classifiers = [
|
|
16
|
+
"Development Status :: 4 - Beta",
|
|
17
|
+
"Intended Audience :: Developers",
|
|
18
|
+
"Programming Language :: Python :: 3",
|
|
19
|
+
"Programming Language :: Python :: 3.11",
|
|
20
|
+
"Programming Language :: Python :: 3.12",
|
|
21
|
+
"Programming Language :: Python :: 3.13",
|
|
22
|
+
"Topic :: Multimedia :: Sound/Audio :: Speech",
|
|
23
|
+
]
|
|
24
|
+
dependencies = [
|
|
25
|
+
"aiohttp>=3.14,<4",
|
|
26
|
+
"loguru>=0.7.3,<0.8",
|
|
27
|
+
"pipecat-ai>=1.13.0,<1.14.0",
|
|
28
|
+
"websockets>=13.1",
|
|
29
|
+
]
|
|
30
|
+
|
|
31
|
+
[project.optional-dependencies]
|
|
32
|
+
examples = ["pipecat-ai[deepgram,openai,runner,webrtc]>=1.13.0,<1.14.0"]
|
|
33
|
+
|
|
34
|
+
[project.urls]
|
|
35
|
+
Homepage = "https://kalpalabs.ai"
|
|
36
|
+
Documentation = "https://github.com/kalpalabs/pipecat-kalpa#readme"
|
|
37
|
+
Repository = "https://github.com/kalpalabs/pipecat-kalpa"
|
|
38
|
+
Issues = "https://github.com/kalpalabs/pipecat-kalpa/issues"
|
|
39
|
+
Changelog = "https://github.com/kalpalabs/pipecat-kalpa/blob/main/CHANGELOG.md"
|
|
40
|
+
|
|
41
|
+
[dependency-groups]
|
|
42
|
+
dev = [
|
|
43
|
+
"pytest>=8.3,<10",
|
|
44
|
+
"pytest-aiohttp>=1.1,<2",
|
|
45
|
+
"pytest-asyncio>=1.0,<2",
|
|
46
|
+
"ruff>=0.14,<1",
|
|
47
|
+
]
|
|
48
|
+
|
|
49
|
+
[tool.hatch.build.targets.wheel]
|
|
50
|
+
packages = ["src/pipecat_kalpa"]
|
|
51
|
+
|
|
52
|
+
[tool.hatch.build.targets.sdist]
|
|
53
|
+
include = ["src", "tests", "examples", ".env.example", "README.md", "CHANGELOG.md", "LICENSE", "pyproject.toml"]
|
|
54
|
+
|
|
55
|
+
[tool.pytest.ini_options]
|
|
56
|
+
testpaths = ["tests"]
|
|
57
|
+
asyncio_default_fixture_loop_scope = "function"
|
|
58
|
+
filterwarnings = ["ignore:'audioop' is deprecated:DeprecationWarning"]
|
|
59
|
+
|
|
60
|
+
[tool.ruff]
|
|
61
|
+
line-length = 100
|
|
62
|
+
target-version = "py311"
|
|
63
|
+
|
|
64
|
+
[tool.ruff.lint]
|
|
65
|
+
select = ["ASYNC", "B", "D", "F", "I", "RUF006", "UP"]
|
|
66
|
+
ignore = ["ASYNC109", "B904", "D105"]
|
|
67
|
+
|
|
68
|
+
[tool.ruff.lint.pydocstyle]
|
|
69
|
+
convention = "google"
|
|
70
|
+
|
|
71
|
+
[tool.ruff.lint.per-file-ignores]
|
|
72
|
+
"tests/*" = ["D"]
|
|
73
|
+
"examples/*" = ["D"]
|
|
File without changes
|