DeepgramTTSService: re-add base_url to constructor

This commit is contained in:
Aleix Conchillo Flaqué
2025-04-16 14:48:31 -07:00
parent 31f7082d12
commit e9af585edd
4 changed files with 108 additions and 89 deletions

View File

@@ -9,6 +9,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added ### Added
- `DeepgramTTSService` accepts `base_url` argument again, allowing you to
connect to an on-prem service.
- It is now possible to disable `SoundfileMixer` when created. You can then use - It is now possible to disable `SoundfileMixer` when created. You can then use
`MixerEnableFrame` to dynamically enable it when necessary. `MixerEnableFrame` to dynamically enable it when necessary.
@@ -25,6 +28,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `SoundfileMixer` constructor arguments need to be keywords. - `SoundfileMixer` constructor arguments need to be keywords.
### Deprecated
- `DeepgramSTTService` parameter `url` is now deprecated, use `base_url`
instead.
### Fixed ### Fixed
- Fixed a `TavusVideoService` issue that was causing audio choppiness. - Fixed a `TavusVideoService` issue that was causing audio choppiness.

View File

@@ -6,7 +6,6 @@
import os import os
import aiohttp
from dotenv import load_dotenv from dotenv import load_dotenv
from loguru import logger from loguru import logger
@@ -40,15 +39,12 @@ async def run_bot(webrtc_connection: SmallWebRTCConnection):
), ),
) )
# Create an HTTP session
async with aiohttp.ClientSession() as session:
stt = DeepgramSTTService(api_key=os.getenv("DEEPGRAM_API_KEY")) stt = DeepgramSTTService(api_key=os.getenv("DEEPGRAM_API_KEY"))
tts = DeepgramTTSService( tts = DeepgramTTSService(
aiohttp_session=session,
api_key=os.getenv("DEEPGRAM_API_KEY"), api_key=os.getenv("DEEPGRAM_API_KEY"),
voice="aura-asteria-en", voice="aura-asteria-en",
base_url="http://0.0.0.0:8080/v1/speak", base_url="http://0.0.0.0:8080",
) )
llm = OpenAILLMService( llm = OpenAILLMService(

View File

@@ -45,6 +45,7 @@ class DeepgramSTTService(STTService):
*, *,
api_key: str, api_key: str,
url: str = "", url: str = "",
base_url: str = "",
sample_rate: Optional[int] = None, sample_rate: Optional[int] = None,
live_options: Optional[LiveOptions] = None, live_options: Optional[LiveOptions] = None,
addons: Optional[Dict] = None, addons: Optional[Dict] = None,
@@ -53,6 +54,17 @@ class DeepgramSTTService(STTService):
sample_rate = sample_rate or (live_options.sample_rate if live_options else None) sample_rate = sample_rate or (live_options.sample_rate if live_options else None)
super().__init__(sample_rate=sample_rate, **kwargs) super().__init__(sample_rate=sample_rate, **kwargs)
if url:
import warnings
with warnings.catch_warnings():
warnings.simplefilter("always")
warnings.warn(
"Parameter 'url' is deprecated, use 'base_url' instead.",
DeprecationWarning,
)
base_url = url
default_options = LiveOptions( default_options = LiveOptions(
encoding="linear16", encoding="linear16",
language=Language.EN, language=Language.EN,
@@ -81,7 +93,7 @@ class DeepgramSTTService(STTService):
self._client = DeepgramClient( self._client = DeepgramClient(
api_key, api_key,
config=DeepgramClientOptions( config=DeepgramClientOptions(
url=url, url=base_url,
options={"keepalive": "true"}, # verbose=logging.DEBUG options={"keepalive": "true"}, # verbose=logging.DEBUG
), ),
) )

View File

@@ -18,7 +18,7 @@ from pipecat.frames.frames import (
from pipecat.services.tts_service import TTSService from pipecat.services.tts_service import TTSService
try: try:
from deepgram import DeepgramClient, SpeakOptions from deepgram import DeepgramClient, DeepgramClientOptions, SpeakOptions
except ModuleNotFoundError as e: except ModuleNotFoundError as e:
logger.error(f"Exception: {e}") logger.error(f"Exception: {e}")
logger.error("In order to use Deepgram, you need to `pip install pipecat-ai[deepgram]`.") logger.error("In order to use Deepgram, you need to `pip install pipecat-ai[deepgram]`.")
@@ -31,6 +31,7 @@ class DeepgramTTSService(TTSService):
*, *,
api_key: str, api_key: str,
voice: str = "aura-helios-en", voice: str = "aura-helios-en",
base_url: str = "",
sample_rate: Optional[int] = None, sample_rate: Optional[int] = None,
encoding: str = "linear16", encoding: str = "linear16",
**kwargs, **kwargs,
@@ -41,7 +42,9 @@ class DeepgramTTSService(TTSService):
"encoding": encoding, "encoding": encoding,
} }
self.set_voice(voice) self.set_voice(voice)
self._deepgram_client = DeepgramClient(api_key=api_key)
client_options = DeepgramClientOptions(url=base_url)
self._deepgram_client = DeepgramClient(api_key, config=client_options)
def can_generate_metrics(self) -> bool: def can_generate_metrics(self) -> bool:
return True return True