Skip to main content

langchain-camb

LangChain integration for CAMB AI - multilingual audio and localization services supporting 140+ languages.

Installation

pip install langchain-camb

Quick Start

from langchain_camb import CambToolkit, CambTTSTool
from langchain_openai import ChatOpenAI
from langgraph.prebuilt import create_react_agent

# Set your API key
import os
os.environ["CAMB_API_KEY"] = "your-api-key"

# Use individual tools
tts = CambTTSTool()
audio_path = tts.invoke({
    "text": "Hello, world!",
    "language": "en-us",
    "voice_id": 147320
})
print(f"Audio saved to: {audio_path}")

# Or use the toolkit with a LangChain agent
toolkit = CambToolkit()
agent = create_react_agent(ChatOpenAI(), toolkit.get_tools())

result = agent.invoke({
    "messages": [{"role": "user", "content": "Say 'Good morning' in Spanish"}]
})

Available Tools

Tool Description
CambTTSTool Text-to-Speech - Convert text to natural speech
CambTranslatedTTSTool Translate text and convert to speech in one step
CambTranslationTool Text translation between 140+ languages
CambTranscriptionTool Speech-to-text with speaker identification
CambVoiceListTool List available voices for TTS
CambVoiceCloneTool Clone voices from 2+ second audio samples
CambTextToSoundTool Generate music and sound effects from text
CambAudioSeparationTool Separate vocals from background audio

Tool Examples

Text-to-Speech

from langchain_camb import CambTTSTool

tts = CambTTSTool()
result = tts.invoke({
    "text": "Hello, how are you today?",
    "language": "en-us",
    "voice_id": 147320,
    "speech_model": "mars-flash",  # or "mars-pro", "mars-instruct"
    "speed": 1.0,  # 0.5 to 2.0
    "output_format": "file_path"  # or "base64", "bytes"
})

Translation

from langchain_camb import CambTranslationTool

translator = CambTranslationTool()
result = translator.invoke({
    "text": "Hello, how are you?",
    "source_language": 1,   # English (en-us)
    "target_language": 54,  # Spanish (es-es)
    "formality": 1  # 1=formal, 2=informal
})
print(result)  # "Hola, ¿cómo está usted?"

Transcription

from langchain_camb import CambTranscriptionTool

transcriber = CambTranscriptionTool()
result = transcriber.invoke({
    "audio_url": "https://example.com/audio.mp3",
    "language": 1  # English
})
# Returns JSON with text, segments, and speaker identification

Voice Cloning

from langchain_camb import CambVoiceCloneTool

cloner = CambVoiceCloneTool()
result = cloner.invoke({
    "voice_name": "My Custom Voice",
    "audio_file_path": "/path/to/sample.wav",  # 2+ seconds
    "gender": 2,  # 1=Male, 2=Female
    "description": "A warm, friendly voice"
})
# Returns new voice_id to use with TTS

Text-to-Sound

from langchain_camb import CambTextToSoundTool

sound_gen = CambTextToSoundTool()
result = sound_gen.invoke({
    "prompt": "Upbeat electronic music with a driving beat",
    "duration": 30,
    "audio_type": "music"  # or "sound"
})

Audio Separation

from langchain_camb import CambAudioSeparationTool

separator = CambAudioSeparationTool()
result = separator.invoke({
    "audio_file_path": "/path/to/mixed_audio.mp3"
})
# Returns JSON with paths to vocals and background audio

Using the Toolkit

The CambToolkit bundles all tools and allows filtering:

from langchain_camb import CambToolkit

# All tools
toolkit = CambToolkit()
tools = toolkit.get_tools()

# TTS-focused toolkit
tts_toolkit = CambToolkit(
    include_tts=True,
    include_voice_list=True,
    include_translation=False,
    include_transcription=False,
    include_translated_tts=False,
    include_voice_clone=False,
    include_text_to_sound=False,
    include_audio_separation=False,
)

# Translation-focused toolkit
translation_toolkit = CambToolkit(
    include_tts=False,
    include_translated_tts=True,
    include_translation=True,
    include_transcription=True,
    include_voice_list=False,
    include_voice_clone=False,
    include_text_to_sound=False,
    include_audio_separation=False,
)

Language Codes

CAMB AI uses integer language codes. Common codes:

Code Language BCP-47
1 English (US) en-us
31 German (Germany) de-de
54 Spanish (Spain) es-es
76 French (France) fr-fr
87 Italian it-it
88 Japanese ja-jp
94 Korean ko-kr
108 Dutch nl-nl
111 Portuguese (Brazil) pt-br
114 Russian ru-ru
139 Chinese (Simplified) zh-cn

Use client.languages.get_source_languages() for the full list of 140+ languages.

For TTS, use BCP-47 codes like "en-us", "es-es", "fr-fr".

Configuration

API Key

Set your API key via environment variable or parameter:

# Environment variable
import os
os.environ["CAMB_API_KEY"] = "your-api-key"

# Or pass directly
tool = CambTTSTool(api_key="your-api-key")
toolkit = CambToolkit(api_key="your-api-key")

Timeouts and Polling

For async operations (transcription, text-to-sound, etc.):

tool = CambTranscriptionTool(
    timeout=60.0,         # HTTP request timeout
    max_poll_attempts=60, # Max polling attempts
    poll_interval=2.0,    # Seconds between polls
)

Agent Integration

LangGraph ReAct Agent

from langchain_camb import CambToolkit
from langchain_openai import ChatOpenAI
from langgraph.prebuilt import create_react_agent

toolkit = CambToolkit()
agent = create_react_agent(ChatOpenAI(model="gpt-4"), toolkit.get_tools())

# TTS
result = agent.invoke({
    "messages": [{"role": "user", "content": "Say 'Hello world' in a friendly tone"}]
})

# Translation
result = agent.invoke({
    "messages": [{"role": "user", "content": "Translate 'Good morning' to French and German"}]
})

# Transcription
result = agent.invoke({
    "messages": [{"role": "user", "content": "Transcribe https://example.com/audio.mp3"}]
})

Development

# Install dev dependencies
pip install -e ".[dev]"

# Run unit tests
pytest tests/unit/

# Run integration tests (requires CAMB_API_KEY)
CAMB_API_KEY=your-key pytest tests/integration/ -m integration

# Lint
ruff check .

# Type check
mypy langchain_camb/

License

MIT

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

langchain_camb-0.1.0.tar.gz (24.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

langchain_camb-0.1.0-py3-none-any.whl (22.3 kB view details)

Uploaded Python 3

File details

Details for the file langchain_camb-0.1.0.tar.gz.

File metadata

  • Download URL: langchain_camb-0.1.0.tar.gz
  • Upload date:
  • Size: 24.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.9

File hashes

Hashes for langchain_camb-0.1.0.tar.gz
Algorithm Hash digest
SHA256 02efd68f7ce04281ccaa879f2069d8f89f907b7430f9ecdfa1756228a9e117b5
MD5 8c11de91abc0e43d281928ed1ec34d39
BLAKE2b-256 2289209dc62d3b20e0ba580b362148c42854fd180583cfd43e17d5d3184da293

See more details on using hashes here.

File details

Details for the file langchain_camb-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: langchain_camb-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 22.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.9

File hashes

Hashes for langchain_camb-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 86314594c2216fbf8ea8991f6345aae83804a83a90e271ba5c30fb035dfee476
MD5 4fa2297c8ffe017de83e1ddf9c350977
BLAKE2b-256 04e01b527947c243db57a1d650ce5ac3145fe957f488233462735c9749270910

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page