langchain-camb 0.1.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.
- langchain_camb-0.1.0/.gitignore +54 -0
- langchain_camb-0.1.0/PKG-INFO +307 -0
- langchain_camb-0.1.0/README.md +274 -0
- langchain_camb-0.1.0/examples/01_basic_tts.py +64 -0
- langchain_camb-0.1.0/examples/02_translation.py +76 -0
- langchain_camb-0.1.0/examples/03_translated_tts.py +60 -0
- langchain_camb-0.1.0/examples/04_langchain_agent.py +92 -0
- langchain_camb-0.1.0/examples/05_voice_assistant.py +69 -0
- langchain_camb-0.1.0/examples/06_podcast_translator.py +83 -0
- langchain_camb-0.1.0/examples/07_sound_generator.py +70 -0
- langchain_camb-0.1.0/examples/08_async_batch_processing.py +83 -0
- langchain_camb-0.1.0/examples/09_customer_support_bot.py +126 -0
- langchain_camb-0.1.0/examples/10_voice_cloning.py +59 -0
- langchain_camb-0.1.0/examples/quick_test.py +121 -0
- langchain_camb-0.1.0/langchain_camb/__init__.py +81 -0
- langchain_camb-0.1.0/langchain_camb/toolkits/__init__.py +5 -0
- langchain_camb-0.1.0/langchain_camb/toolkits/camb_toolkit.py +148 -0
- langchain_camb-0.1.0/langchain_camb/tools/__init__.py +40 -0
- langchain_camb-0.1.0/langchain_camb/tools/audio_separation.py +189 -0
- langchain_camb-0.1.0/langchain_camb/tools/base.py +161 -0
- langchain_camb-0.1.0/langchain_camb/tools/text_to_sound.py +156 -0
- langchain_camb-0.1.0/langchain_camb/tools/transcription.py +189 -0
- langchain_camb-0.1.0/langchain_camb/tools/translated_tts.py +340 -0
- langchain_camb-0.1.0/langchain_camb/tools/translation.py +150 -0
- langchain_camb-0.1.0/langchain_camb/tools/tts.py +182 -0
- langchain_camb-0.1.0/langchain_camb/tools/voice_clone.py +152 -0
- langchain_camb-0.1.0/langchain_camb/tools/voice_list.py +108 -0
- langchain_camb-0.1.0/langchain_camb/version.py +3 -0
- langchain_camb-0.1.0/pyproject.toml +81 -0
- langchain_camb-0.1.0/tests/__init__.py +1 -0
- langchain_camb-0.1.0/tests/integration/__init__.py +1 -0
- langchain_camb-0.1.0/tests/integration/test_integration.py +182 -0
- langchain_camb-0.1.0/tests/integration_tests/__init__.py +1 -0
- langchain_camb-0.1.0/tests/integration_tests/test_tools_standard.py +87 -0
- langchain_camb-0.1.0/tests/unit/__init__.py +1 -0
- langchain_camb-0.1.0/tests/unit/test_toolkit.py +141 -0
- langchain_camb-0.1.0/tests/unit/test_tools.py +278 -0
- langchain_camb-0.1.0/tests/unit_tests/__init__.py +1 -0
- langchain_camb-0.1.0/tests/unit_tests/test_tools_standard.py +172 -0
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# Python
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*$py.class
|
|
5
|
+
*.so
|
|
6
|
+
.Python
|
|
7
|
+
build/
|
|
8
|
+
develop-eggs/
|
|
9
|
+
dist/
|
|
10
|
+
downloads/
|
|
11
|
+
eggs/
|
|
12
|
+
.eggs/
|
|
13
|
+
lib/
|
|
14
|
+
lib64/
|
|
15
|
+
parts/
|
|
16
|
+
sdist/
|
|
17
|
+
var/
|
|
18
|
+
wheels/
|
|
19
|
+
*.egg-info/
|
|
20
|
+
.installed.cfg
|
|
21
|
+
*.egg
|
|
22
|
+
|
|
23
|
+
# Virtual environments
|
|
24
|
+
.venv/
|
|
25
|
+
venv/
|
|
26
|
+
ENV/
|
|
27
|
+
|
|
28
|
+
# IDE
|
|
29
|
+
.idea/
|
|
30
|
+
.vscode/
|
|
31
|
+
*.swp
|
|
32
|
+
*.swo
|
|
33
|
+
|
|
34
|
+
# Testing
|
|
35
|
+
.pytest_cache/
|
|
36
|
+
.coverage
|
|
37
|
+
htmlcov/
|
|
38
|
+
.tox/
|
|
39
|
+
.nox/
|
|
40
|
+
|
|
41
|
+
# Environment
|
|
42
|
+
.env
|
|
43
|
+
.env.local
|
|
44
|
+
*.env
|
|
45
|
+
|
|
46
|
+
# OS
|
|
47
|
+
.DS_Store
|
|
48
|
+
Thumbs.db
|
|
49
|
+
|
|
50
|
+
# Logs
|
|
51
|
+
*.log
|
|
52
|
+
|
|
53
|
+
# Lock files (optional - remove if you want to track)
|
|
54
|
+
uv.lock
|
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: langchain-camb
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: LangChain integration for CAMB AI - multilingual audio and localization tools
|
|
5
|
+
Project-URL: Homepage, https://github.com/camb-ai/langchain-camb
|
|
6
|
+
Project-URL: Documentation, https://docs.camb.ai
|
|
7
|
+
Project-URL: Repository, https://github.com/camb-ai/langchain-camb
|
|
8
|
+
Author-email: CAMB AI <support@camb.ai>
|
|
9
|
+
License-Expression: MIT
|
|
10
|
+
Keywords: audio,camb,langchain,localization,multilingual,text-to-speech,transcription,translation,tts,voice-cloning
|
|
11
|
+
Classifier: Development Status :: 4 - Beta
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Topic :: Multimedia :: Sound/Audio :: Speech
|
|
20
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
21
|
+
Requires-Python: >=3.9
|
|
22
|
+
Requires-Dist: camb-sdk>=1.5.0
|
|
23
|
+
Requires-Dist: langchain-core>=0.3.0
|
|
24
|
+
Requires-Dist: pydantic>=2.0.0
|
|
25
|
+
Provides-Extra: dev
|
|
26
|
+
Requires-Dist: langchain-tests>=0.3.0; extra == 'dev'
|
|
27
|
+
Requires-Dist: mypy>=1.0.0; extra == 'dev'
|
|
28
|
+
Requires-Dist: pytest-asyncio>=0.21.0; extra == 'dev'
|
|
29
|
+
Requires-Dist: pytest-cov>=4.0.0; extra == 'dev'
|
|
30
|
+
Requires-Dist: pytest>=7.0.0; extra == 'dev'
|
|
31
|
+
Requires-Dist: ruff>=0.1.0; extra == 'dev'
|
|
32
|
+
Description-Content-Type: text/markdown
|
|
33
|
+
|
|
34
|
+
# langchain-camb
|
|
35
|
+
|
|
36
|
+
LangChain integration for [CAMB AI](https://camb.ai) - multilingual audio and localization services supporting 140+ languages.
|
|
37
|
+
|
|
38
|
+
## Installation
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
pip install langchain-camb
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Quick Start
|
|
45
|
+
|
|
46
|
+
```python
|
|
47
|
+
from langchain_camb import CambToolkit, CambTTSTool
|
|
48
|
+
from langchain_openai import ChatOpenAI
|
|
49
|
+
from langgraph.prebuilt import create_react_agent
|
|
50
|
+
|
|
51
|
+
# Set your API key
|
|
52
|
+
import os
|
|
53
|
+
os.environ["CAMB_API_KEY"] = "your-api-key"
|
|
54
|
+
|
|
55
|
+
# Use individual tools
|
|
56
|
+
tts = CambTTSTool()
|
|
57
|
+
audio_path = tts.invoke({
|
|
58
|
+
"text": "Hello, world!",
|
|
59
|
+
"language": "en-us",
|
|
60
|
+
"voice_id": 147320
|
|
61
|
+
})
|
|
62
|
+
print(f"Audio saved to: {audio_path}")
|
|
63
|
+
|
|
64
|
+
# Or use the toolkit with a LangChain agent
|
|
65
|
+
toolkit = CambToolkit()
|
|
66
|
+
agent = create_react_agent(ChatOpenAI(), toolkit.get_tools())
|
|
67
|
+
|
|
68
|
+
result = agent.invoke({
|
|
69
|
+
"messages": [{"role": "user", "content": "Say 'Good morning' in Spanish"}]
|
|
70
|
+
})
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## Available Tools
|
|
74
|
+
|
|
75
|
+
| Tool | Description |
|
|
76
|
+
|------|-------------|
|
|
77
|
+
| `CambTTSTool` | Text-to-Speech - Convert text to natural speech |
|
|
78
|
+
| `CambTranslatedTTSTool` | Translate text and convert to speech in one step |
|
|
79
|
+
| `CambTranslationTool` | Text translation between 140+ languages |
|
|
80
|
+
| `CambTranscriptionTool` | Speech-to-text with speaker identification |
|
|
81
|
+
| `CambVoiceListTool` | List available voices for TTS |
|
|
82
|
+
| `CambVoiceCloneTool` | Clone voices from 2+ second audio samples |
|
|
83
|
+
| `CambTextToSoundTool` | Generate music and sound effects from text |
|
|
84
|
+
| `CambAudioSeparationTool` | Separate vocals from background audio |
|
|
85
|
+
|
|
86
|
+
## Tool Examples
|
|
87
|
+
|
|
88
|
+
### Text-to-Speech
|
|
89
|
+
|
|
90
|
+
```python
|
|
91
|
+
from langchain_camb import CambTTSTool
|
|
92
|
+
|
|
93
|
+
tts = CambTTSTool()
|
|
94
|
+
result = tts.invoke({
|
|
95
|
+
"text": "Hello, how are you today?",
|
|
96
|
+
"language": "en-us",
|
|
97
|
+
"voice_id": 147320,
|
|
98
|
+
"speech_model": "mars-flash", # or "mars-pro", "mars-instruct"
|
|
99
|
+
"speed": 1.0, # 0.5 to 2.0
|
|
100
|
+
"output_format": "file_path" # or "base64", "bytes"
|
|
101
|
+
})
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
### Translation
|
|
105
|
+
|
|
106
|
+
```python
|
|
107
|
+
from langchain_camb import CambTranslationTool
|
|
108
|
+
|
|
109
|
+
translator = CambTranslationTool()
|
|
110
|
+
result = translator.invoke({
|
|
111
|
+
"text": "Hello, how are you?",
|
|
112
|
+
"source_language": 1, # English (en-us)
|
|
113
|
+
"target_language": 54, # Spanish (es-es)
|
|
114
|
+
"formality": 1 # 1=formal, 2=informal
|
|
115
|
+
})
|
|
116
|
+
print(result) # "Hola, ¿cómo está usted?"
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
### Transcription
|
|
120
|
+
|
|
121
|
+
```python
|
|
122
|
+
from langchain_camb import CambTranscriptionTool
|
|
123
|
+
|
|
124
|
+
transcriber = CambTranscriptionTool()
|
|
125
|
+
result = transcriber.invoke({
|
|
126
|
+
"audio_url": "https://example.com/audio.mp3",
|
|
127
|
+
"language": 1 # English
|
|
128
|
+
})
|
|
129
|
+
# Returns JSON with text, segments, and speaker identification
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
### Voice Cloning
|
|
133
|
+
|
|
134
|
+
```python
|
|
135
|
+
from langchain_camb import CambVoiceCloneTool
|
|
136
|
+
|
|
137
|
+
cloner = CambVoiceCloneTool()
|
|
138
|
+
result = cloner.invoke({
|
|
139
|
+
"voice_name": "My Custom Voice",
|
|
140
|
+
"audio_file_path": "/path/to/sample.wav", # 2+ seconds
|
|
141
|
+
"gender": 2, # 1=Male, 2=Female
|
|
142
|
+
"description": "A warm, friendly voice"
|
|
143
|
+
})
|
|
144
|
+
# Returns new voice_id to use with TTS
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
### Text-to-Sound
|
|
148
|
+
|
|
149
|
+
```python
|
|
150
|
+
from langchain_camb import CambTextToSoundTool
|
|
151
|
+
|
|
152
|
+
sound_gen = CambTextToSoundTool()
|
|
153
|
+
result = sound_gen.invoke({
|
|
154
|
+
"prompt": "Upbeat electronic music with a driving beat",
|
|
155
|
+
"duration": 30,
|
|
156
|
+
"audio_type": "music" # or "sound"
|
|
157
|
+
})
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
### Audio Separation
|
|
161
|
+
|
|
162
|
+
```python
|
|
163
|
+
from langchain_camb import CambAudioSeparationTool
|
|
164
|
+
|
|
165
|
+
separator = CambAudioSeparationTool()
|
|
166
|
+
result = separator.invoke({
|
|
167
|
+
"audio_file_path": "/path/to/mixed_audio.mp3"
|
|
168
|
+
})
|
|
169
|
+
# Returns JSON with paths to vocals and background audio
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
## Using the Toolkit
|
|
173
|
+
|
|
174
|
+
The `CambToolkit` bundles all tools and allows filtering:
|
|
175
|
+
|
|
176
|
+
```python
|
|
177
|
+
from langchain_camb import CambToolkit
|
|
178
|
+
|
|
179
|
+
# All tools
|
|
180
|
+
toolkit = CambToolkit()
|
|
181
|
+
tools = toolkit.get_tools()
|
|
182
|
+
|
|
183
|
+
# TTS-focused toolkit
|
|
184
|
+
tts_toolkit = CambToolkit(
|
|
185
|
+
include_tts=True,
|
|
186
|
+
include_voice_list=True,
|
|
187
|
+
include_translation=False,
|
|
188
|
+
include_transcription=False,
|
|
189
|
+
include_translated_tts=False,
|
|
190
|
+
include_voice_clone=False,
|
|
191
|
+
include_text_to_sound=False,
|
|
192
|
+
include_audio_separation=False,
|
|
193
|
+
)
|
|
194
|
+
|
|
195
|
+
# Translation-focused toolkit
|
|
196
|
+
translation_toolkit = CambToolkit(
|
|
197
|
+
include_tts=False,
|
|
198
|
+
include_translated_tts=True,
|
|
199
|
+
include_translation=True,
|
|
200
|
+
include_transcription=True,
|
|
201
|
+
include_voice_list=False,
|
|
202
|
+
include_voice_clone=False,
|
|
203
|
+
include_text_to_sound=False,
|
|
204
|
+
include_audio_separation=False,
|
|
205
|
+
)
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
## Language Codes
|
|
209
|
+
|
|
210
|
+
CAMB AI uses integer language codes. Common codes:
|
|
211
|
+
|
|
212
|
+
| Code | Language | BCP-47 |
|
|
213
|
+
|------|----------|--------|
|
|
214
|
+
| 1 | English (US) | en-us |
|
|
215
|
+
| 31 | German (Germany) | de-de |
|
|
216
|
+
| 54 | Spanish (Spain) | es-es |
|
|
217
|
+
| 76 | French (France) | fr-fr |
|
|
218
|
+
| 87 | Italian | it-it |
|
|
219
|
+
| 88 | Japanese | ja-jp |
|
|
220
|
+
| 94 | Korean | ko-kr |
|
|
221
|
+
| 108 | Dutch | nl-nl |
|
|
222
|
+
| 111 | Portuguese (Brazil) | pt-br |
|
|
223
|
+
| 114 | Russian | ru-ru |
|
|
224
|
+
| 139 | Chinese (Simplified) | zh-cn |
|
|
225
|
+
|
|
226
|
+
Use `client.languages.get_source_languages()` for the full list of 140+ languages.
|
|
227
|
+
|
|
228
|
+
For TTS, use BCP-47 codes like `"en-us"`, `"es-es"`, `"fr-fr"`.
|
|
229
|
+
|
|
230
|
+
## Configuration
|
|
231
|
+
|
|
232
|
+
### API Key
|
|
233
|
+
|
|
234
|
+
Set your API key via environment variable or parameter:
|
|
235
|
+
|
|
236
|
+
```python
|
|
237
|
+
# Environment variable
|
|
238
|
+
import os
|
|
239
|
+
os.environ["CAMB_API_KEY"] = "your-api-key"
|
|
240
|
+
|
|
241
|
+
# Or pass directly
|
|
242
|
+
tool = CambTTSTool(api_key="your-api-key")
|
|
243
|
+
toolkit = CambToolkit(api_key="your-api-key")
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
### Timeouts and Polling
|
|
247
|
+
|
|
248
|
+
For async operations (transcription, text-to-sound, etc.):
|
|
249
|
+
|
|
250
|
+
```python
|
|
251
|
+
tool = CambTranscriptionTool(
|
|
252
|
+
timeout=60.0, # HTTP request timeout
|
|
253
|
+
max_poll_attempts=60, # Max polling attempts
|
|
254
|
+
poll_interval=2.0, # Seconds between polls
|
|
255
|
+
)
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
## Agent Integration
|
|
259
|
+
|
|
260
|
+
### LangGraph ReAct Agent
|
|
261
|
+
|
|
262
|
+
```python
|
|
263
|
+
from langchain_camb import CambToolkit
|
|
264
|
+
from langchain_openai import ChatOpenAI
|
|
265
|
+
from langgraph.prebuilt import create_react_agent
|
|
266
|
+
|
|
267
|
+
toolkit = CambToolkit()
|
|
268
|
+
agent = create_react_agent(ChatOpenAI(model="gpt-4"), toolkit.get_tools())
|
|
269
|
+
|
|
270
|
+
# TTS
|
|
271
|
+
result = agent.invoke({
|
|
272
|
+
"messages": [{"role": "user", "content": "Say 'Hello world' in a friendly tone"}]
|
|
273
|
+
})
|
|
274
|
+
|
|
275
|
+
# Translation
|
|
276
|
+
result = agent.invoke({
|
|
277
|
+
"messages": [{"role": "user", "content": "Translate 'Good morning' to French and German"}]
|
|
278
|
+
})
|
|
279
|
+
|
|
280
|
+
# Transcription
|
|
281
|
+
result = agent.invoke({
|
|
282
|
+
"messages": [{"role": "user", "content": "Transcribe https://example.com/audio.mp3"}]
|
|
283
|
+
})
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
## Development
|
|
287
|
+
|
|
288
|
+
```bash
|
|
289
|
+
# Install dev dependencies
|
|
290
|
+
pip install -e ".[dev]"
|
|
291
|
+
|
|
292
|
+
# Run unit tests
|
|
293
|
+
pytest tests/unit/
|
|
294
|
+
|
|
295
|
+
# Run integration tests (requires CAMB_API_KEY)
|
|
296
|
+
CAMB_API_KEY=your-key pytest tests/integration/ -m integration
|
|
297
|
+
|
|
298
|
+
# Lint
|
|
299
|
+
ruff check .
|
|
300
|
+
|
|
301
|
+
# Type check
|
|
302
|
+
mypy langchain_camb/
|
|
303
|
+
```
|
|
304
|
+
|
|
305
|
+
## License
|
|
306
|
+
|
|
307
|
+
MIT
|
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
# langchain-camb
|
|
2
|
+
|
|
3
|
+
LangChain integration for [CAMB AI](https://camb.ai) - multilingual audio and localization services supporting 140+ languages.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pip install langchain-camb
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Quick Start
|
|
12
|
+
|
|
13
|
+
```python
|
|
14
|
+
from langchain_camb import CambToolkit, CambTTSTool
|
|
15
|
+
from langchain_openai import ChatOpenAI
|
|
16
|
+
from langgraph.prebuilt import create_react_agent
|
|
17
|
+
|
|
18
|
+
# Set your API key
|
|
19
|
+
import os
|
|
20
|
+
os.environ["CAMB_API_KEY"] = "your-api-key"
|
|
21
|
+
|
|
22
|
+
# Use individual tools
|
|
23
|
+
tts = CambTTSTool()
|
|
24
|
+
audio_path = tts.invoke({
|
|
25
|
+
"text": "Hello, world!",
|
|
26
|
+
"language": "en-us",
|
|
27
|
+
"voice_id": 147320
|
|
28
|
+
})
|
|
29
|
+
print(f"Audio saved to: {audio_path}")
|
|
30
|
+
|
|
31
|
+
# Or use the toolkit with a LangChain agent
|
|
32
|
+
toolkit = CambToolkit()
|
|
33
|
+
agent = create_react_agent(ChatOpenAI(), toolkit.get_tools())
|
|
34
|
+
|
|
35
|
+
result = agent.invoke({
|
|
36
|
+
"messages": [{"role": "user", "content": "Say 'Good morning' in Spanish"}]
|
|
37
|
+
})
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## Available Tools
|
|
41
|
+
|
|
42
|
+
| Tool | Description |
|
|
43
|
+
|------|-------------|
|
|
44
|
+
| `CambTTSTool` | Text-to-Speech - Convert text to natural speech |
|
|
45
|
+
| `CambTranslatedTTSTool` | Translate text and convert to speech in one step |
|
|
46
|
+
| `CambTranslationTool` | Text translation between 140+ languages |
|
|
47
|
+
| `CambTranscriptionTool` | Speech-to-text with speaker identification |
|
|
48
|
+
| `CambVoiceListTool` | List available voices for TTS |
|
|
49
|
+
| `CambVoiceCloneTool` | Clone voices from 2+ second audio samples |
|
|
50
|
+
| `CambTextToSoundTool` | Generate music and sound effects from text |
|
|
51
|
+
| `CambAudioSeparationTool` | Separate vocals from background audio |
|
|
52
|
+
|
|
53
|
+
## Tool Examples
|
|
54
|
+
|
|
55
|
+
### Text-to-Speech
|
|
56
|
+
|
|
57
|
+
```python
|
|
58
|
+
from langchain_camb import CambTTSTool
|
|
59
|
+
|
|
60
|
+
tts = CambTTSTool()
|
|
61
|
+
result = tts.invoke({
|
|
62
|
+
"text": "Hello, how are you today?",
|
|
63
|
+
"language": "en-us",
|
|
64
|
+
"voice_id": 147320,
|
|
65
|
+
"speech_model": "mars-flash", # or "mars-pro", "mars-instruct"
|
|
66
|
+
"speed": 1.0, # 0.5 to 2.0
|
|
67
|
+
"output_format": "file_path" # or "base64", "bytes"
|
|
68
|
+
})
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### Translation
|
|
72
|
+
|
|
73
|
+
```python
|
|
74
|
+
from langchain_camb import CambTranslationTool
|
|
75
|
+
|
|
76
|
+
translator = CambTranslationTool()
|
|
77
|
+
result = translator.invoke({
|
|
78
|
+
"text": "Hello, how are you?",
|
|
79
|
+
"source_language": 1, # English (en-us)
|
|
80
|
+
"target_language": 54, # Spanish (es-es)
|
|
81
|
+
"formality": 1 # 1=formal, 2=informal
|
|
82
|
+
})
|
|
83
|
+
print(result) # "Hola, ¿cómo está usted?"
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
### Transcription
|
|
87
|
+
|
|
88
|
+
```python
|
|
89
|
+
from langchain_camb import CambTranscriptionTool
|
|
90
|
+
|
|
91
|
+
transcriber = CambTranscriptionTool()
|
|
92
|
+
result = transcriber.invoke({
|
|
93
|
+
"audio_url": "https://example.com/audio.mp3",
|
|
94
|
+
"language": 1 # English
|
|
95
|
+
})
|
|
96
|
+
# Returns JSON with text, segments, and speaker identification
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
### Voice Cloning
|
|
100
|
+
|
|
101
|
+
```python
|
|
102
|
+
from langchain_camb import CambVoiceCloneTool
|
|
103
|
+
|
|
104
|
+
cloner = CambVoiceCloneTool()
|
|
105
|
+
result = cloner.invoke({
|
|
106
|
+
"voice_name": "My Custom Voice",
|
|
107
|
+
"audio_file_path": "/path/to/sample.wav", # 2+ seconds
|
|
108
|
+
"gender": 2, # 1=Male, 2=Female
|
|
109
|
+
"description": "A warm, friendly voice"
|
|
110
|
+
})
|
|
111
|
+
# Returns new voice_id to use with TTS
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
### Text-to-Sound
|
|
115
|
+
|
|
116
|
+
```python
|
|
117
|
+
from langchain_camb import CambTextToSoundTool
|
|
118
|
+
|
|
119
|
+
sound_gen = CambTextToSoundTool()
|
|
120
|
+
result = sound_gen.invoke({
|
|
121
|
+
"prompt": "Upbeat electronic music with a driving beat",
|
|
122
|
+
"duration": 30,
|
|
123
|
+
"audio_type": "music" # or "sound"
|
|
124
|
+
})
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
### Audio Separation
|
|
128
|
+
|
|
129
|
+
```python
|
|
130
|
+
from langchain_camb import CambAudioSeparationTool
|
|
131
|
+
|
|
132
|
+
separator = CambAudioSeparationTool()
|
|
133
|
+
result = separator.invoke({
|
|
134
|
+
"audio_file_path": "/path/to/mixed_audio.mp3"
|
|
135
|
+
})
|
|
136
|
+
# Returns JSON with paths to vocals and background audio
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
## Using the Toolkit
|
|
140
|
+
|
|
141
|
+
The `CambToolkit` bundles all tools and allows filtering:
|
|
142
|
+
|
|
143
|
+
```python
|
|
144
|
+
from langchain_camb import CambToolkit
|
|
145
|
+
|
|
146
|
+
# All tools
|
|
147
|
+
toolkit = CambToolkit()
|
|
148
|
+
tools = toolkit.get_tools()
|
|
149
|
+
|
|
150
|
+
# TTS-focused toolkit
|
|
151
|
+
tts_toolkit = CambToolkit(
|
|
152
|
+
include_tts=True,
|
|
153
|
+
include_voice_list=True,
|
|
154
|
+
include_translation=False,
|
|
155
|
+
include_transcription=False,
|
|
156
|
+
include_translated_tts=False,
|
|
157
|
+
include_voice_clone=False,
|
|
158
|
+
include_text_to_sound=False,
|
|
159
|
+
include_audio_separation=False,
|
|
160
|
+
)
|
|
161
|
+
|
|
162
|
+
# Translation-focused toolkit
|
|
163
|
+
translation_toolkit = CambToolkit(
|
|
164
|
+
include_tts=False,
|
|
165
|
+
include_translated_tts=True,
|
|
166
|
+
include_translation=True,
|
|
167
|
+
include_transcription=True,
|
|
168
|
+
include_voice_list=False,
|
|
169
|
+
include_voice_clone=False,
|
|
170
|
+
include_text_to_sound=False,
|
|
171
|
+
include_audio_separation=False,
|
|
172
|
+
)
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
## Language Codes
|
|
176
|
+
|
|
177
|
+
CAMB AI uses integer language codes. Common codes:
|
|
178
|
+
|
|
179
|
+
| Code | Language | BCP-47 |
|
|
180
|
+
|------|----------|--------|
|
|
181
|
+
| 1 | English (US) | en-us |
|
|
182
|
+
| 31 | German (Germany) | de-de |
|
|
183
|
+
| 54 | Spanish (Spain) | es-es |
|
|
184
|
+
| 76 | French (France) | fr-fr |
|
|
185
|
+
| 87 | Italian | it-it |
|
|
186
|
+
| 88 | Japanese | ja-jp |
|
|
187
|
+
| 94 | Korean | ko-kr |
|
|
188
|
+
| 108 | Dutch | nl-nl |
|
|
189
|
+
| 111 | Portuguese (Brazil) | pt-br |
|
|
190
|
+
| 114 | Russian | ru-ru |
|
|
191
|
+
| 139 | Chinese (Simplified) | zh-cn |
|
|
192
|
+
|
|
193
|
+
Use `client.languages.get_source_languages()` for the full list of 140+ languages.
|
|
194
|
+
|
|
195
|
+
For TTS, use BCP-47 codes like `"en-us"`, `"es-es"`, `"fr-fr"`.
|
|
196
|
+
|
|
197
|
+
## Configuration
|
|
198
|
+
|
|
199
|
+
### API Key
|
|
200
|
+
|
|
201
|
+
Set your API key via environment variable or parameter:
|
|
202
|
+
|
|
203
|
+
```python
|
|
204
|
+
# Environment variable
|
|
205
|
+
import os
|
|
206
|
+
os.environ["CAMB_API_KEY"] = "your-api-key"
|
|
207
|
+
|
|
208
|
+
# Or pass directly
|
|
209
|
+
tool = CambTTSTool(api_key="your-api-key")
|
|
210
|
+
toolkit = CambToolkit(api_key="your-api-key")
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
### Timeouts and Polling
|
|
214
|
+
|
|
215
|
+
For async operations (transcription, text-to-sound, etc.):
|
|
216
|
+
|
|
217
|
+
```python
|
|
218
|
+
tool = CambTranscriptionTool(
|
|
219
|
+
timeout=60.0, # HTTP request timeout
|
|
220
|
+
max_poll_attempts=60, # Max polling attempts
|
|
221
|
+
poll_interval=2.0, # Seconds between polls
|
|
222
|
+
)
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
## Agent Integration
|
|
226
|
+
|
|
227
|
+
### LangGraph ReAct Agent
|
|
228
|
+
|
|
229
|
+
```python
|
|
230
|
+
from langchain_camb import CambToolkit
|
|
231
|
+
from langchain_openai import ChatOpenAI
|
|
232
|
+
from langgraph.prebuilt import create_react_agent
|
|
233
|
+
|
|
234
|
+
toolkit = CambToolkit()
|
|
235
|
+
agent = create_react_agent(ChatOpenAI(model="gpt-4"), toolkit.get_tools())
|
|
236
|
+
|
|
237
|
+
# TTS
|
|
238
|
+
result = agent.invoke({
|
|
239
|
+
"messages": [{"role": "user", "content": "Say 'Hello world' in a friendly tone"}]
|
|
240
|
+
})
|
|
241
|
+
|
|
242
|
+
# Translation
|
|
243
|
+
result = agent.invoke({
|
|
244
|
+
"messages": [{"role": "user", "content": "Translate 'Good morning' to French and German"}]
|
|
245
|
+
})
|
|
246
|
+
|
|
247
|
+
# Transcription
|
|
248
|
+
result = agent.invoke({
|
|
249
|
+
"messages": [{"role": "user", "content": "Transcribe https://example.com/audio.mp3"}]
|
|
250
|
+
})
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
## Development
|
|
254
|
+
|
|
255
|
+
```bash
|
|
256
|
+
# Install dev dependencies
|
|
257
|
+
pip install -e ".[dev]"
|
|
258
|
+
|
|
259
|
+
# Run unit tests
|
|
260
|
+
pytest tests/unit/
|
|
261
|
+
|
|
262
|
+
# Run integration tests (requires CAMB_API_KEY)
|
|
263
|
+
CAMB_API_KEY=your-key pytest tests/integration/ -m integration
|
|
264
|
+
|
|
265
|
+
# Lint
|
|
266
|
+
ruff check .
|
|
267
|
+
|
|
268
|
+
# Type check
|
|
269
|
+
mypy langchain_camb/
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
## License
|
|
273
|
+
|
|
274
|
+
MIT
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Example 1: Basic Text-to-Speech
|
|
3
|
+
|
|
4
|
+
Generate speech from text in multiple languages.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from dotenv import load_dotenv
|
|
8
|
+
|
|
9
|
+
load_dotenv()
|
|
10
|
+
import os
|
|
11
|
+
|
|
12
|
+
from langchain_camb import CambTTSTool, CambVoiceListTool
|
|
13
|
+
|
|
14
|
+
# Set your API key
|
|
15
|
+
# os.environ["CAMB_API_KEY"] = "your-api-key"
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def main():
|
|
19
|
+
# First, list available voices
|
|
20
|
+
print("Fetching available voices...")
|
|
21
|
+
voice_list = CambVoiceListTool()
|
|
22
|
+
voices = voice_list.invoke({})
|
|
23
|
+
print(f"Available voices (first 5):\n{voices[:500]}...\n")
|
|
24
|
+
|
|
25
|
+
# Create TTS tool
|
|
26
|
+
tts = CambTTSTool()
|
|
27
|
+
|
|
28
|
+
# Generate speech in English
|
|
29
|
+
print("Generating English speech...")
|
|
30
|
+
english_audio = tts.invoke({
|
|
31
|
+
"text": "Hello! Welcome to CAMB AI. We support over 140 languages for text to speech.",
|
|
32
|
+
"language": "en-us",
|
|
33
|
+
"voice_id": 147320, # Default voice
|
|
34
|
+
"speech_model": "mars-flash",
|
|
35
|
+
"output_format": "file_path",
|
|
36
|
+
})
|
|
37
|
+
print(f"English audio saved to: {english_audio}")
|
|
38
|
+
|
|
39
|
+
# Generate speech in Spanish
|
|
40
|
+
print("\nGenerating Spanish speech...")
|
|
41
|
+
spanish_audio = tts.invoke({
|
|
42
|
+
"text": "¡Hola! Bienvenido a CAMB AI. Soportamos más de 140 idiomas.",
|
|
43
|
+
"language": "es-es",
|
|
44
|
+
"voice_id": 147320,
|
|
45
|
+
"output_format": "file_path",
|
|
46
|
+
})
|
|
47
|
+
print(f"Spanish audio saved to: {spanish_audio}")
|
|
48
|
+
|
|
49
|
+
# Generate with different speed
|
|
50
|
+
print("\nGenerating slow speech...")
|
|
51
|
+
slow_audio = tts.invoke({
|
|
52
|
+
"text": "This is spoken slowly for clarity.",
|
|
53
|
+
"language": "en-us",
|
|
54
|
+
"voice_id": 147320,
|
|
55
|
+
"speed": 0.7, # Slower
|
|
56
|
+
"output_format": "file_path",
|
|
57
|
+
})
|
|
58
|
+
print(f"Slow audio saved to: {slow_audio}")
|
|
59
|
+
|
|
60
|
+
print("\nDone! You can play these audio files with any media player.")
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
if __name__ == "__main__":
|
|
64
|
+
main()
|