cartesia 0.1.1__py2.py3-none-any.whl → 1.0.0__py2.py3-none-any.whl

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.
@@ -1,189 +0,0 @@
1
- Metadata-Version: 2.1
2
- Name: cartesia
3
- Version: 0.1.1
4
- Summary: The official Python library for the Cartesia API.
5
- Home-page:
6
- Author: Cartesia, Inc.
7
- Author-email: support@cartesia.ai
8
- Classifier: Programming Language :: Python
9
- Classifier: Programming Language :: Python :: 3
10
- Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
11
- Requires-Python: >=3.8.0
12
- Description-Content-Type: text/markdown
13
- Requires-Dist: aiohttp
14
- Requires-Dist: httpx
15
- Requires-Dist: pytest-asyncio
16
- Requires-Dist: requests
17
- Requires-Dist: websockets
18
- Provides-Extra: all
19
- Requires-Dist: pytest >=8.0.2 ; extra == 'all'
20
- Requires-Dist: pytest-cov >=4.1.0 ; extra == 'all'
21
- Requires-Dist: twine ; extra == 'all'
22
- Requires-Dist: setuptools ; extra == 'all'
23
- Requires-Dist: wheel ; extra == 'all'
24
- Requires-Dist: numpy ; extra == 'all'
25
- Provides-Extra: dev
26
- Requires-Dist: pytest >=8.0.2 ; extra == 'dev'
27
- Requires-Dist: pytest-cov >=4.1.0 ; extra == 'dev'
28
- Requires-Dist: twine ; extra == 'dev'
29
- Requires-Dist: setuptools ; extra == 'dev'
30
- Requires-Dist: wheel ; extra == 'dev'
31
- Requires-Dist: numpy ; extra == 'dev'
32
-
33
-
34
- # Cartesia Python API Library
35
- The official Cartesia Python library which provides convenient access to the Cartesia REST and Websocket API from any Python 3.8+ application.
36
-
37
- **Note:** This API is still in alpha. Please expect breaking changes and report any issues you encounter.
38
-
39
- ## Installation
40
- ```bash
41
- pip install cartesia
42
-
43
- # pip install in editable mode w/ dev dependencies
44
- pip install -e '.[dev]'
45
- ```
46
-
47
- ## Usage
48
- ```python
49
- from cartesia.tts import CartesiaTTS
50
- import pyaudio
51
- import os
52
-
53
- client = CartesiaTTS(api_key=os.environ.get("CARTESIA_API_KEY"))
54
- voices = client.get_voices()
55
- voice = client.get_voice_embedding(voice_id=voices["Ted"]["id"])
56
- transcript = "Hello! Welcome to Cartesia"
57
- model_id = "genial-planet-1346" # (Optional) We'll specify a default if you don't have a specific model in mind
58
-
59
- p = pyaudio.PyAudio()
60
-
61
- stream = None
62
-
63
- # Generate and stream audio
64
- for output in client.generate(transcript=transcript, voice=voice, model_id=model_id, stream=True):
65
- buffer = output["audio"]
66
- rate = output["sampling_rate"]
67
-
68
- if not stream:
69
- stream = p.open(format=pyaudio.paFloat32,
70
- channels=1,
71
- rate=rate,
72
- output=True)
73
-
74
- # Write the audio data to the stream
75
- stream.write(buffer)
76
-
77
- stream.stop_stream()
78
- stream.close()
79
- p.terminate()
80
- ```
81
-
82
- You can also use the async client if you want to make asynchronous API calls:
83
- ```python
84
- from cartesia.tts import AsyncCartesiaTTS
85
- import asyncio
86
- import pyaudio
87
- import os
88
-
89
- async def write_stream():
90
- client = AsyncCartesiaTTS(api_key=os.environ.get("CARTESIA_API_KEY"))
91
- voices = client.get_voices()
92
- voice = client.get_voice_embedding(voice_id=voices["Ted"]["id"])
93
- transcript = "Hello! Welcome to Cartesia"
94
- model_id = "genial-planet-1346" # (Optional) We'll specify a default if you don't have a specific model in mind
95
-
96
- p = pyaudio.PyAudio()
97
-
98
- stream = None
99
-
100
- # Generate and stream audio
101
- async for output in await client.generate(transcript=transcript, voice=voice, model_id=model_id, stream=True):
102
- buffer = output["audio"]
103
- rate = output["sampling_rate"]
104
-
105
- if not stream:
106
- stream = p.open(format=pyaudio.paFloat32,
107
- channels=1,
108
- rate=rate,
109
- output=True)
110
-
111
- # Write the audio data to the stream
112
- stream.write(buffer)
113
-
114
- stream.stop_stream()
115
- stream.close()
116
- p.terminate()
117
-
118
- asyncio.run(write_stream())
119
- ```
120
-
121
- If you are using Jupyter Notebook or JupyterLab, you can use IPython.display.Audio to play the generated audio directly in the notebook.
122
- Additionally, in these notebook examples we show how to use the client as a context manager (though this is not required).
123
-
124
- ```python
125
- from IPython.display import Audio
126
- import io
127
- import os
128
- import numpy as np
129
-
130
- from cartesia.tts import CartesiaTTS
131
-
132
- with CartesiaTTS(api_key=os.environ.get("CARTESIA_API_KEY")) as client:
133
- voices = client.get_voices()
134
- voice = client.get_voice_embedding(voice_id=voices["Ted"]["id"])
135
- transcript = "Hello! Welcome to Cartesia"
136
-
137
- # Create a BytesIO object to store the audio data
138
- audio_data = io.BytesIO()
139
-
140
- # Generate and stream audio
141
- for output in client.generate(transcript=transcript, voice=voice, stream=True):
142
- buffer = output["audio"]
143
- audio_data.write(buffer)
144
-
145
- # Set the cursor position to the beginning of the BytesIO object
146
- audio_data.seek(0)
147
-
148
- # Create an Audio object from the BytesIO data
149
- audio = Audio(np.frombuffer(audio_data.read(), dtype=np.float32), rate=output["sampling_rate"])
150
-
151
- # Display the Audio object
152
- display(audio)
153
- ```
154
-
155
- Below is the same example using the async client:
156
- ```python
157
- from IPython.display import Audio
158
- import io
159
- import os
160
- import numpy as np
161
-
162
- from cartesia.tts import AsyncCartesiaTTS
163
-
164
- async with AsyncCartesiaTTS(api_key=os.environ.get("CARTESIA_API_KEY")) as client:
165
- voices = client.get_voices()
166
- voice = client.get_voice_embedding(voice_id=voices["Ted"]["id"])
167
- transcript = "Hello! Welcome to Cartesia"
168
-
169
- # Create a BytesIO object to store the audio data
170
- audio_data = io.BytesIO()
171
-
172
- # Generate and stream audio
173
- async for output in await client.generate(transcript=transcript, voice=voice, stream=True):
174
- buffer = output["audio"]
175
- audio_data.write(buffer)
176
-
177
- # Set the cursor position to the beginning of the BytesIO object
178
- audio_data.seek(0)
179
-
180
- # Create an Audio object from the BytesIO data
181
- audio = Audio(np.frombuffer(audio_data.read(), dtype=np.float32), rate=output["sampling_rate"])
182
-
183
- # Display the Audio object
184
- display(audio)
185
- ```
186
-
187
- To avoid storing your API key in the source code, we recommend doing one of the following:
188
- 1. Use [`python-dotenv`](https://pypi.org/project/python-dotenv/) to add `CARTESIA_API_KEY="my-api-key"` to your .env file.
189
- 1. Set the `CARTESIA_API_KEY` environment variable, preferably to a secure shell init file (e.g. `~/.zshrc`, `~/.bashrc`)
@@ -1,9 +0,0 @@
1
- cartesia/__init__.py,sha256=uIc9xGNPs8_A6eAvbTUY1geazunYoEZVWFKhCwC9TRA,102
2
- cartesia/_types.py,sha256=602535A2Qpk-546dxRNPj3uvznJmBQcOa4Kkv0nSQKQ,1054
3
- cartesia/tts.py,sha256=vCrcBqkFCmmv16uNPlzqmARNLdKUN6XC2yxwEuxdOHc,25881
4
- cartesia/utils.py,sha256=nuwWRfu3MOVTxIQMLjYf6WLaxSlnu_GdE3QjTV0zisQ,3339
5
- cartesia/version.py,sha256=rnObPjuBcEStqSO0S6gsdS_ot8ITOQjVj_-P1LUUYpg,22
6
- cartesia-0.1.1.dist-info/METADATA,sha256=VLtJRjJPczIafLgiHMjpNf3c4lkMArXf6FlLAa1ojm8,6038
7
- cartesia-0.1.1.dist-info/WHEEL,sha256=DZajD4pwLWue70CAfc7YaxT1wLUciNBvN_TTcvXpltE,110
8
- cartesia-0.1.1.dist-info/top_level.txt,sha256=rTX4HnnCegMxl1FK9czpVC7GAvf3SwDzPG65qP-BS4w,9
9
- cartesia-0.1.1.dist-info/RECORD,,