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

@@ -45,6 +45,7 @@ class DeepgramSTTService(STTService):
*,
api_key: str,
url: str = "",
base_url: str = "",
sample_rate: Optional[int] = None,
live_options: Optional[LiveOptions] = 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)
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(
encoding="linear16",
language=Language.EN,
@@ -81,7 +93,7 @@ class DeepgramSTTService(STTService):
self._client = DeepgramClient(
api_key,
config=DeepgramClientOptions(
url=url,
url=base_url,
options={"keepalive": "true"}, # verbose=logging.DEBUG
),
)

View File

@@ -18,7 +18,7 @@ from pipecat.frames.frames import (
from pipecat.services.tts_service import TTSService
try:
from deepgram import DeepgramClient, SpeakOptions
from deepgram import DeepgramClient, DeepgramClientOptions, SpeakOptions
except ModuleNotFoundError as e:
logger.error(f"Exception: {e}")
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,
voice: str = "aura-helios-en",
base_url: str = "",
sample_rate: Optional[int] = None,
encoding: str = "linear16",
**kwargs,
@@ -41,7 +42,9 @@ class DeepgramTTSService(TTSService):
"encoding": encoding,
}
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:
return True