refactor: Improve code reability and replace deprecated interruption frames
This commit is contained in:
@@ -20,9 +20,9 @@ from pipecat.frames.frames import (
|
|||||||
EndFrame,
|
EndFrame,
|
||||||
ErrorFrame,
|
ErrorFrame,
|
||||||
Frame,
|
Frame,
|
||||||
|
InterruptionFrame,
|
||||||
LLMFullResponseEndFrame,
|
LLMFullResponseEndFrame,
|
||||||
StartFrame,
|
StartFrame,
|
||||||
StartInterruptionFrame,
|
|
||||||
TTSAudioRawFrame,
|
TTSAudioRawFrame,
|
||||||
TTSStartedFrame,
|
TTSStartedFrame,
|
||||||
TTSStoppedFrame,
|
TTSStoppedFrame,
|
||||||
@@ -121,6 +121,9 @@ class SarvamHttpTTSService(TTSService):
|
|||||||
default=0.6,
|
default=0.6,
|
||||||
ge=0.01,
|
ge=0.01,
|
||||||
le=1.0,
|
le=1.0,
|
||||||
|
description="Controls the randomness of the output for bulbul v3 beta. "
|
||||||
|
"Lower values make the output more focused and deterministic, while "
|
||||||
|
"higher values make it more random. Range: 0.01 to 1.0. Default: 0.6.",
|
||||||
)
|
)
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
@@ -155,31 +158,31 @@ class SarvamHttpTTSService(TTSService):
|
|||||||
self._base_url = base_url
|
self._base_url = base_url
|
||||||
self._session = aiohttp_session
|
self._session = aiohttp_session
|
||||||
|
|
||||||
if model == "bulbul:v3-beta" or model == "bulbul:v3":
|
# Build base settings common to all models
|
||||||
# For bulbul v3 beta, exclude pace and loudness parameters
|
self._settings = {
|
||||||
self._settings = {
|
"language": (
|
||||||
"language": (
|
self.language_to_service_language(params.language) if params.language else "en-IN"
|
||||||
self.language_to_service_language(params.language)
|
),
|
||||||
if params.language
|
"enable_preprocessing": params.enable_preprocessing,
|
||||||
else "en-IN"
|
}
|
||||||
),
|
|
||||||
"enable_preprocessing": params.enable_preprocessing,
|
# Add model-specific parameters
|
||||||
"temperature": getattr(params, "temperature", 0.6),
|
if model in ("bulbul:v3-beta", "bulbul:v3"):
|
||||||
"model": model, # Include model in settings for v3 beta
|
self._settings.update(
|
||||||
}
|
{
|
||||||
|
"temperature": getattr(params, "temperature", 0.6),
|
||||||
|
"model": model,
|
||||||
|
}
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
# For bulbul v2, include all parameters including pace and loudness
|
self._settings.update(
|
||||||
self._settings = {
|
{
|
||||||
"language": (
|
"pitch": params.pitch,
|
||||||
self.language_to_service_language(params.language)
|
"pace": params.pace,
|
||||||
if params.language
|
"loudness": params.loudness,
|
||||||
else "en-IN"
|
"model": model,
|
||||||
),
|
}
|
||||||
"pitch": params.pitch,
|
)
|
||||||
"pace": params.pace,
|
|
||||||
"loudness": params.loudness,
|
|
||||||
"enable_preprocessing": params.enable_preprocessing,
|
|
||||||
}
|
|
||||||
|
|
||||||
self.set_model_name(model)
|
self.set_model_name(model)
|
||||||
self.set_voice(voice_id)
|
self.set_voice(voice_id)
|
||||||
@@ -310,7 +313,7 @@ class SarvamTTSService(InterruptibleTTSService):
|
|||||||
)
|
)
|
||||||
|
|
||||||
# For bulbul v3 beta with any speaker and temperature:
|
# For bulbul v3 beta with any speaker and temperature:
|
||||||
# Note: pace and loudness are not supported for bulbul v3 beta
|
# Note: pace and loudness are not supported for bulbul v3 and bulbul v3 beta
|
||||||
tts_v3 = SarvamTTSService(
|
tts_v3 = SarvamTTSService(
|
||||||
api_key="your-api-key",
|
api_key="your-api-key",
|
||||||
voice_id="speaker_name",
|
voice_id="speaker_name",
|
||||||
@@ -386,8 +389,10 @@ class SarvamTTSService(InterruptibleTTSService):
|
|||||||
voice_id: Voice identifier for synthesis (default "anushka").
|
voice_id: Voice identifier for synthesis (default "anushka").
|
||||||
url: WebSocket URL for connecting to the TTS backend (default production URL).
|
url: WebSocket URL for connecting to the TTS backend (default production URL).
|
||||||
aiohttp_session: Optional shared aiohttp session. To maintain backward compatibility.
|
aiohttp_session: Optional shared aiohttp session. To maintain backward compatibility.
|
||||||
|
|
||||||
.. deprecated:: 0.0.81
|
.. deprecated:: 0.0.81
|
||||||
aiohttp_session is no longer used. This parameter will be removed in a future version.
|
aiohttp_session is no longer used. This parameter will be removed in a future version.
|
||||||
|
|
||||||
aggregate_sentences: Whether to merge multiple sentences into one audio chunk (default True).
|
aggregate_sentences: Whether to merge multiple sentences into one audio chunk (default True).
|
||||||
sample_rate: Desired sample rate for the output audio in Hz (overrides default if set).
|
sample_rate: Desired sample rate for the output audio in Hz (overrides default if set).
|
||||||
params: Optional input parameters to override global configuration.
|
params: Optional input parameters to override global configuration.
|
||||||
@@ -423,44 +428,37 @@ class SarvamTTSService(InterruptibleTTSService):
|
|||||||
self._api_key = api_key
|
self._api_key = api_key
|
||||||
self.set_model_name(model)
|
self.set_model_name(model)
|
||||||
self.set_voice(voice_id)
|
self.set_voice(voice_id)
|
||||||
# Configuration parameters
|
# Build base settings common to all models
|
||||||
if model == "bulbul:v3-beta" or model == "bulbul:v3":
|
self._settings = {
|
||||||
# For bulbul v3 beta, exclude pace and loudness parameters
|
"target_language_code": (
|
||||||
self._settings = {
|
self.language_to_service_language(params.language) if params.language else "en-IN"
|
||||||
"target_language_code": (
|
),
|
||||||
self.language_to_service_language(params.language)
|
"speaker": voice_id,
|
||||||
if params.language
|
"speech_sample_rate": 0,
|
||||||
else "en-IN"
|
"enable_preprocessing": params.enable_preprocessing,
|
||||||
),
|
"min_buffer_size": params.min_buffer_size,
|
||||||
"speaker": voice_id,
|
"max_chunk_length": params.max_chunk_length,
|
||||||
"speech_sample_rate": 0,
|
"output_audio_codec": params.output_audio_codec,
|
||||||
"enable_preprocessing": params.enable_preprocessing,
|
"output_audio_bitrate": params.output_audio_bitrate,
|
||||||
"min_buffer_size": params.min_buffer_size,
|
}
|
||||||
"max_chunk_length": params.max_chunk_length,
|
|
||||||
"output_audio_codec": params.output_audio_codec,
|
# Add model-specific parameters
|
||||||
"output_audio_bitrate": params.output_audio_bitrate,
|
if model in ("bulbul:v3-beta", "bulbul:v3"):
|
||||||
"temperature": getattr(params, "temperature", 0.6),
|
self._settings.update(
|
||||||
"model": model, # Include model in settings for v3 beta
|
{
|
||||||
}
|
"temperature": getattr(params, "temperature", 0.6),
|
||||||
|
"model": model,
|
||||||
|
}
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
# For bulbul v2, include all parameters including pace and loudness
|
self._settings.update(
|
||||||
self._settings = {
|
{
|
||||||
"target_language_code": (
|
"pitch": params.pitch,
|
||||||
self.language_to_service_language(params.language)
|
"pace": params.pace,
|
||||||
if params.language
|
"loudness": params.loudness,
|
||||||
else "en-IN"
|
"model": model,
|
||||||
),
|
}
|
||||||
"pitch": params.pitch,
|
)
|
||||||
"pace": params.pace,
|
|
||||||
"speaker": voice_id,
|
|
||||||
"loudness": params.loudness,
|
|
||||||
"speech_sample_rate": 0,
|
|
||||||
"enable_preprocessing": params.enable_preprocessing,
|
|
||||||
"min_buffer_size": params.min_buffer_size,
|
|
||||||
"max_chunk_length": params.max_chunk_length,
|
|
||||||
"output_audio_codec": params.output_audio_codec,
|
|
||||||
"output_audio_bitrate": params.output_audio_bitrate,
|
|
||||||
}
|
|
||||||
self._started = False
|
self._started = False
|
||||||
|
|
||||||
self._receive_task = None
|
self._receive_task = None
|
||||||
@@ -529,7 +527,7 @@ class SarvamTTSService(InterruptibleTTSService):
|
|||||||
direction: The direction to push the frame.
|
direction: The direction to push the frame.
|
||||||
"""
|
"""
|
||||||
await super().push_frame(frame, direction)
|
await super().push_frame(frame, direction)
|
||||||
if isinstance(frame, (TTSStoppedFrame, StartInterruptionFrame)):
|
if isinstance(frame, (TTSStoppedFrame, InterruptionFrame)):
|
||||||
self._started = False
|
self._started = False
|
||||||
|
|
||||||
async def process_frame(self, frame: Frame, direction: FrameDirection):
|
async def process_frame(self, frame: Frame, direction: FrameDirection):
|
||||||
|
|||||||
Reference in New Issue
Block a user