Update MARS model names to mars-flash, mars-pro, mars-instruct
Rename model identifiers from mars-8-* to the new naming convention: - mars-8-flash -> mars-flash (default) - mars-8 -> removed - mars-8-instruct -> mars-instruct - Added mars-pro
This commit is contained in:
@@ -1 +1 @@
|
|||||||
- Added Camb.ai TTS integration with MARS-8 models (mars-8, mars-8-flash, mars-8-instruct) for high-quality text-to-speech synthesis.
|
- Added Camb.ai TTS integration with MARS models (mars-flash, mars-pro, mars-instruct) for high-quality text-to-speech synthesis.
|
||||||
|
|||||||
@@ -68,12 +68,12 @@ async def main(voice_id: int):
|
|||||||
|
|
||||||
# Create HTTP session for Camb.ai TTS
|
# Create HTTP session for Camb.ai TTS
|
||||||
async with aiohttp.ClientSession() as session:
|
async with aiohttp.ClientSession() as session:
|
||||||
# Camb.ai TTS with MARS-8-flash model
|
# Camb.ai TTS with MARS-flash model
|
||||||
tts = CambTTSService(
|
tts = CambTTSService(
|
||||||
api_key=os.getenv("CAMB_API_KEY"),
|
api_key=os.getenv("CAMB_API_KEY"),
|
||||||
aiohttp_session=session,
|
aiohttp_session=session,
|
||||||
voice_id=voice_id,
|
voice_id=voice_id,
|
||||||
model="mars-8-flash",
|
model="mars-flash",
|
||||||
params=CambTTSService.InputParams(
|
params=CambTTSService.InputParams(
|
||||||
speed=1.0,
|
speed=1.0,
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -4,13 +4,13 @@
|
|||||||
# SPDX-License-Identifier: BSD 2-Clause License
|
# SPDX-License-Identifier: BSD 2-Clause License
|
||||||
#
|
#
|
||||||
|
|
||||||
"""Camb.ai MARS-8 text-to-speech service implementation.
|
"""Camb.ai MARS text-to-speech service implementation.
|
||||||
|
|
||||||
This module provides TTS functionality using Camb.ai's MARS-8 model family,
|
This module provides TTS functionality using Camb.ai's MARS model family,
|
||||||
offering high-quality text-to-speech synthesis with HTTP streaming support.
|
offering high-quality text-to-speech synthesis with HTTP streaming support.
|
||||||
|
|
||||||
Features:
|
Features:
|
||||||
- MARS-8 models: mars-8, mars-8-flash, mars-8-instruct
|
- MARS models: mars-flash, mars-pro, mars-instruct
|
||||||
- 140+ languages supported
|
- 140+ languages supported
|
||||||
- Real-time HTTP streaming
|
- Real-time HTTP streaming
|
||||||
- 24kHz audio output
|
- 24kHz audio output
|
||||||
@@ -40,7 +40,7 @@ from pipecat.utils.tracing.service_decorators import traced_tts
|
|||||||
# Default configuration
|
# Default configuration
|
||||||
DEFAULT_VOICE_ID = 2681 # Attic voice (publicly available)
|
DEFAULT_VOICE_ID = 2681 # Attic voice (publicly available)
|
||||||
DEFAULT_LANGUAGE = "en-us"
|
DEFAULT_LANGUAGE = "en-us"
|
||||||
DEFAULT_MODEL = "mars-8-flash" # Faster inference
|
DEFAULT_MODEL = "mars-flash" # Faster inference
|
||||||
DEFAULT_BASE_URL = "https://client.camb.ai/apis"
|
DEFAULT_BASE_URL = "https://client.camb.ai/apis"
|
||||||
DEFAULT_SAMPLE_RATE = 24000 # 24kHz
|
DEFAULT_SAMPLE_RATE = 24000 # 24kHz
|
||||||
DEFAULT_TIMEOUT = 60.0 # Seconds (minimum recommended by Camb.ai)
|
DEFAULT_TIMEOUT = 60.0 # Seconds (minimum recommended by Camb.ai)
|
||||||
@@ -126,18 +126,18 @@ def language_to_camb_language(language: Language) -> Optional[str]:
|
|||||||
|
|
||||||
|
|
||||||
class CambTTSService(TTSService):
|
class CambTTSService(TTSService):
|
||||||
"""Camb.ai MARS-8 HTTP-based text-to-speech service.
|
"""Camb.ai MARS HTTP-based text-to-speech service.
|
||||||
|
|
||||||
Converts text to speech using Camb.ai's MARS-8 TTS models with support for
|
Converts text to speech using Camb.ai's MARS TTS models with support for
|
||||||
multiple languages. Provides control over voice characteristics like speed
|
multiple languages. Provides control over voice characteristics like speed
|
||||||
and custom instructions (for mars-8-instruct model).
|
and custom instructions (for mars-instruct model).
|
||||||
|
|
||||||
Example::
|
Example::
|
||||||
|
|
||||||
tts = CambTTSService(
|
tts = CambTTSService(
|
||||||
api_key="your-api-key",
|
api_key="your-api-key",
|
||||||
voice_id=2681,
|
voice_id=2681,
|
||||||
model="mars-8-flash",
|
model="mars-flash",
|
||||||
aiohttp_session=session,
|
aiohttp_session=session,
|
||||||
params=CambTTSService.InputParams(
|
params=CambTTSService.InputParams(
|
||||||
language=Language.EN,
|
language=Language.EN,
|
||||||
@@ -145,11 +145,11 @@ class CambTTSService(TTSService):
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
# For mars-8-instruct with custom instructions:
|
# For mars-instruct with custom instructions:
|
||||||
tts_instruct = CambTTSService(
|
tts_instruct = CambTTSService(
|
||||||
api_key="your-api-key",
|
api_key="your-api-key",
|
||||||
voice_id=2681,
|
voice_id=2681,
|
||||||
model="mars-8-instruct",
|
model="mars-instruct",
|
||||||
aiohttp_session=session,
|
aiohttp_session=session,
|
||||||
params=CambTTSService.InputParams(
|
params=CambTTSService.InputParams(
|
||||||
language=Language.EN,
|
language=Language.EN,
|
||||||
@@ -164,7 +164,7 @@ class CambTTSService(TTSService):
|
|||||||
Parameters:
|
Parameters:
|
||||||
language: Language for synthesis (BCP-47 format). Defaults to English.
|
language: Language for synthesis (BCP-47 format). Defaults to English.
|
||||||
speed: Speech speed multiplier (0.5 to 2.0). Defaults to 1.0.
|
speed: Speech speed multiplier (0.5 to 2.0). Defaults to 1.0.
|
||||||
user_instructions: Custom instructions for mars-8-instruct model only.
|
user_instructions: Custom instructions for mars-instruct model only.
|
||||||
Ignored for other models. Max 1000 characters.
|
Ignored for other models. Max 1000 characters.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@@ -173,7 +173,7 @@ class CambTTSService(TTSService):
|
|||||||
user_instructions: Optional[str] = Field(
|
user_instructions: Optional[str] = Field(
|
||||||
default=None,
|
default=None,
|
||||||
max_length=1000,
|
max_length=1000,
|
||||||
description="Custom instructions for mars-8-instruct model only. "
|
description="Custom instructions for mars-instruct model only. "
|
||||||
"Use to control tone, style, or pronunciation. Max 1000 characters.",
|
"Use to control tone, style, or pronunciation. Max 1000 characters.",
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -195,8 +195,8 @@ class CambTTSService(TTSService):
|
|||||||
api_key: Camb.ai API key for authentication.
|
api_key: Camb.ai API key for authentication.
|
||||||
aiohttp_session: Shared aiohttp session for making HTTP requests.
|
aiohttp_session: Shared aiohttp session for making HTTP requests.
|
||||||
voice_id: Voice ID to use (e.g., 2681 for Attic). Defaults to 2681.
|
voice_id: Voice ID to use (e.g., 2681 for Attic). Defaults to 2681.
|
||||||
model: TTS model to use. Options: "mars-8", "mars-8-flash", "mars-8-instruct".
|
model: TTS model to use. Options: "mars-flash", "mars-pro", "mars-instruct".
|
||||||
Defaults to "mars-8-flash" (fastest).
|
Defaults to "mars-flash" (fastest).
|
||||||
base_url: Camb.ai API base URL. Defaults to production URL.
|
base_url: Camb.ai API base URL. Defaults to production URL.
|
||||||
sample_rate: Audio sample rate in Hz. If None, uses Camb.ai default (24000).
|
sample_rate: Audio sample rate in Hz. If None, uses Camb.ai default (24000).
|
||||||
params: Additional voice parameters. If None, uses defaults.
|
params: Additional voice parameters. If None, uses defaults.
|
||||||
@@ -315,8 +315,8 @@ class CambTTSService(TTSService):
|
|||||||
"voice_settings": {"speed": self._settings["speed"]},
|
"voice_settings": {"speed": self._settings["speed"]},
|
||||||
}
|
}
|
||||||
|
|
||||||
# Add user instructions if using mars-8-instruct model
|
# Add user instructions if using mars-instruct model
|
||||||
if self._model_name == "mars-8-instruct" and self._settings.get("user_instructions"):
|
if self._model_name == "mars-instruct" and self._settings.get("user_instructions"):
|
||||||
payload["user_instructions"] = self._settings["user_instructions"]
|
payload["user_instructions"] = self._settings["user_instructions"]
|
||||||
|
|
||||||
headers = {
|
headers = {
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ async def test_run_camb_tts_success(aiohttp_client):
|
|||||||
assert "text" in body
|
assert "text" in body
|
||||||
assert body["voice_id"] == 2681
|
assert body["voice_id"] == 2681
|
||||||
assert body["language"] == "en-us"
|
assert body["language"] == "en-us"
|
||||||
assert body["speech_model"] == "mars-8-flash"
|
assert body["speech_model"] == "mars-flash"
|
||||||
assert body["output_configuration"]["format"] == "pcm_s16le"
|
assert body["output_configuration"]["format"] == "pcm_s16le"
|
||||||
|
|
||||||
# Prepare a StreamResponse with chunked PCM data
|
# Prepare a StreamResponse with chunked PCM data
|
||||||
@@ -78,7 +78,7 @@ async def test_run_camb_tts_success(aiohttp_client):
|
|||||||
aiohttp_session=session,
|
aiohttp_session=session,
|
||||||
base_url=base_url,
|
base_url=base_url,
|
||||||
voice_id=2681,
|
voice_id=2681,
|
||||||
model="mars-8-flash",
|
model="mars-flash",
|
||||||
)
|
)
|
||||||
|
|
||||||
# Manually set sample rate (normally done by StartFrame)
|
# Manually set sample rate (normally done by StartFrame)
|
||||||
@@ -367,7 +367,7 @@ async def test_language_mapping():
|
|||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_mars8_instruct_model(aiohttp_client):
|
async def test_mars8_instruct_model(aiohttp_client):
|
||||||
"""Test that user_instructions are included for mars-8-instruct model."""
|
"""Test that user_instructions are included for mars-instruct model."""
|
||||||
|
|
||||||
received_payload = {}
|
received_payload = {}
|
||||||
|
|
||||||
@@ -392,7 +392,7 @@ async def test_mars8_instruct_model(aiohttp_client):
|
|||||||
api_key="test-api-key",
|
api_key="test-api-key",
|
||||||
aiohttp_session=session,
|
aiohttp_session=session,
|
||||||
base_url=base_url,
|
base_url=base_url,
|
||||||
model="mars-8-instruct",
|
model="mars-instruct",
|
||||||
params=CambTTSService.InputParams(user_instructions="Speak with excitement"),
|
params=CambTTSService.InputParams(user_instructions="Speak with excitement"),
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -413,7 +413,7 @@ async def test_mars8_instruct_model(aiohttp_client):
|
|||||||
)
|
)
|
||||||
|
|
||||||
# Verify user_instructions was included in the request
|
# Verify user_instructions was included in the request
|
||||||
assert received_payload.get("speech_model") == "mars-8-instruct"
|
assert received_payload.get("speech_model") == "mars-instruct"
|
||||||
assert received_payload.get("user_instructions") == "Speak with excitement"
|
assert received_payload.get("user_instructions") == "Speak with excitement"
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user