fix for Deepgram settings not merging

This commit is contained in:
Kwindla Hultman Kramer
2024-10-11 21:07:39 -07:00
parent 66a76af341
commit 53451899a7
2 changed files with 21 additions and 9 deletions

View File

@@ -14,7 +14,7 @@ from pipecat.pipeline.pipeline import Pipeline
from pipecat.pipeline.runner import PipelineRunner
from pipecat.pipeline.task import PipelineTask
from pipecat.processors.frame_processor import FrameDirection, FrameProcessor
from pipecat.services.deepgram import DeepgramSTTService
from pipecat.services.deepgram import DeepgramSTTService, LiveOptions, Language
from pipecat.transports.services.daily import DailyParams, DailyTransport
from runner import configure
@@ -45,7 +45,10 @@ async def main():
room_url, None, "Transcription bot", DailyParams(audio_in_enabled=True)
)
stt = DeepgramSTTService(api_key=os.getenv("DEEPGRAM_API_KEY"))
stt = DeepgramSTTService(
api_key=os.getenv("DEEPGRAM_API_KEY"),
# live_options=LiveOptions(language=Language.FR),
)
tl = TranscriptionLogger()

View File

@@ -35,6 +35,7 @@ try:
LiveResultResponse,
LiveTranscriptionEvents,
SpeakOptions,
logging,
)
except ModuleNotFoundError as e:
logger.error(f"Exception: {e}")
@@ -118,7 +119,11 @@ class DeepgramSTTService(STTService):
*,
api_key: str,
url: str = "",
live_options: LiveOptions = LiveOptions(
live_options: LiveOptions = None,
**kwargs,
):
super().__init__(**kwargs)
default_options = LiveOptions(
encoding="linear16",
language=Language.EN,
model="nova-2-conversationalai",
@@ -129,15 +134,19 @@ class DeepgramSTTService(STTService):
punctuate=True,
profanity_filter=True,
vad_events=False,
),
**kwargs,
):
super().__init__(**kwargs)
)
self._settings = vars(live_options)
merged_options = default_options
if live_options:
merged_options = LiveOptions(**{**default_options.to_dict(), **live_options.to_dict()})
self._settings = merged_options
self._client = DeepgramClient(
api_key, config=DeepgramClientOptions(url=url, options={"keepalive": "true"})
api_key,
config=DeepgramClientOptions(
url=url,
options={"keepalive": "true"}, # verbose=logging.DEBUG
),
)
self._connection: AsyncListenWebSocketClient = self._client.listen.asyncwebsocket.v("1")
self._connection.on(LiveTranscriptionEvents.Transcript, self._on_message)