services(elevenlabs): allow specifying output_format
This commit is contained in:
@@ -9,6 +9,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|
||||||
|
- `ElevenLabsTTSService` can now specify ElevenLabs input parameters such as
|
||||||
|
`output_format`.
|
||||||
|
|
||||||
- `TwilioFrameSerializer` can now specify Twilio's and Pipecat's desired sample
|
- `TwilioFrameSerializer` can now specify Twilio's and Pipecat's desired sample
|
||||||
rates to use.
|
rates to use.
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,8 @@
|
|||||||
|
|
||||||
import aiohttp
|
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.frames.frames import AudioRawFrame, ErrorFrame, Frame, MetricsFrame
|
||||||
from pipecat.services.ai_services import TTSService
|
from pipecat.services.ai_services import TTSService
|
||||||
@@ -15,6 +16,8 @@ from loguru import logger
|
|||||||
|
|
||||||
|
|
||||||
class ElevenLabsTTSService(TTSService):
|
class ElevenLabsTTSService(TTSService):
|
||||||
|
class InputParams(BaseModel):
|
||||||
|
output_format: Literal["pcm_16000", "pcm_22050", "pcm_24000", "pcm_44100"] = "pcm_16000"
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
@@ -23,12 +26,14 @@ class ElevenLabsTTSService(TTSService):
|
|||||||
voice_id: str,
|
voice_id: str,
|
||||||
aiohttp_session: aiohttp.ClientSession,
|
aiohttp_session: aiohttp.ClientSession,
|
||||||
model: str = "eleven_turbo_v2_5",
|
model: str = "eleven_turbo_v2_5",
|
||||||
|
params: InputParams = InputParams(),
|
||||||
**kwargs):
|
**kwargs):
|
||||||
super().__init__(**kwargs)
|
super().__init__(**kwargs)
|
||||||
|
|
||||||
self._api_key = api_key
|
self._api_key = api_key
|
||||||
self._voice_id = voice_id
|
self._voice_id = voice_id
|
||||||
self._model = model
|
self._model = model
|
||||||
|
self._params = params
|
||||||
self._aiohttp_session = aiohttp_session
|
self._aiohttp_session = aiohttp_session
|
||||||
|
|
||||||
def can_generate_metrics(self) -> bool:
|
def can_generate_metrics(self) -> bool:
|
||||||
@@ -46,8 +51,8 @@ class ElevenLabsTTSService(TTSService):
|
|||||||
payload = {"text": text, "model_id": self._model}
|
payload = {"text": text, "model_id": self._model}
|
||||||
|
|
||||||
querystring = {
|
querystring = {
|
||||||
"output_format": "pcm_16000",
|
"output_format": self._params.output_format
|
||||||
"optimize_streaming_latency": 2}
|
}
|
||||||
|
|
||||||
headers = {
|
headers = {
|
||||||
"xi-api-key": self._api_key,
|
"xi-api-key": self._api_key,
|
||||||
|
|||||||
Reference in New Issue
Block a user