Skip to content

Commit

Permalink
Merge pull request #495 from pipecat-ai/mb/elevenlabs-input-lang
Browse files Browse the repository at this point in the history
Add language_code support for ElevenLabs TTS
  • Loading branch information
markbackman authored Sep 25, 2024
2 parents e123f33 + 306632b commit 521e152
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/pipecat/services/elevenlabs.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ def calculate_word_times(

class ElevenLabsTTSService(AsyncWordTTSService):
class InputParams(BaseModel):
language_code: Optional[str] = None
output_format: Literal["pcm_16000", "pcm_22050", "pcm_24000", "pcm_44100"] = "pcm_16000"
optimize_streaming_latency: Optional[str] = None
stability: Optional[float] = None
Expand Down Expand Up @@ -228,6 +229,15 @@ async def _connect(self):
if self._params.optimize_streaming_latency:
url += f"&optimize_streaming_latency={self._params.optimize_streaming_latency}"

# language_code can only be used with the 'eleven_turbo_v2_5' model
if self._params.language_code:
if model == "eleven_turbo_v2_5":
url += f"&language_code={self._params.language_code}"
else:
logger.debug(
f"Language code [{self._params.language_code}] not applied. Language codes can only be used with the 'eleven_turbo_v2_5' model."
)

self._websocket = await websockets.connect(url)
self._receive_task = self.get_event_loop().create_task(self._receive_task_handler())
self._keepalive_task = self.get_event_loop().create_task(self._keepalive_task_handler())
Expand Down

0 comments on commit 521e152

Please sign in to comment.