From d255e954d6aaa885bed86330e74c3653e451c24e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aleix=20Conchillo=20Flaqu=C3=A9?= Date: Thu, 8 Aug 2024 22:29:40 -0700 Subject: [PATCH] services(elevenlabs): allow specifying output_format --- CHANGELOG.md | 3 +++ src/pipecat/services/elevenlabs.py | 11 ++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b9d727a9b..63dbda5bd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added +- `ElevenLabsTTSService` can now specify ElevenLabs input parameters such as + `output_format`. + - `TwilioFrameSerializer` can now specify Twilio's and Pipecat's desired sample rates to use. diff --git a/src/pipecat/services/elevenlabs.py b/src/pipecat/services/elevenlabs.py index cc63d189a..0de629034 100644 --- a/src/pipecat/services/elevenlabs.py +++ b/src/pipecat/services/elevenlabs.py @@ -6,7 +6,8 @@ import aiohttp -from typing import AsyncGenerator +from typing import AsyncGenerator, Literal +from pydantic import BaseModel from pipecat.frames.frames import AudioRawFrame, ErrorFrame, Frame, MetricsFrame from pipecat.services.ai_services import TTSService @@ -15,6 +16,8 @@ from loguru import logger class ElevenLabsTTSService(TTSService): + class InputParams(BaseModel): + output_format: Literal["pcm_16000", "pcm_22050", "pcm_24000", "pcm_44100"] = "pcm_16000" def __init__( self, @@ -23,12 +26,14 @@ class ElevenLabsTTSService(TTSService): voice_id: str, aiohttp_session: aiohttp.ClientSession, model: str = "eleven_turbo_v2_5", + params: InputParams = InputParams(), **kwargs): super().__init__(**kwargs) self._api_key = api_key self._voice_id = voice_id self._model = model + self._params = params self._aiohttp_session = aiohttp_session def can_generate_metrics(self) -> bool: @@ -46,8 +51,8 @@ class ElevenLabsTTSService(TTSService): payload = {"text": text, "model_id": self._model} querystring = { - "output_format": "pcm_16000", - "optimize_streaming_latency": 2} + "output_format": self._params.output_format + } headers = { "xi-api-key": self._api_key,