Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support for additional deepgram config #1020

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/quiet-spiders-behave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"livekit-plugins-deepgram": patch
---

support for additional deepgram config
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ class STTOptions:
num_channels: int
keywords: list[Tuple[str, float]]
profanity_filter: bool
additional_config: dict = dataclasses.field(default_factory=dict)


class STT(stt.STT):
Expand All @@ -118,6 +119,7 @@ def __init__(
profanity_filter: bool = False,
api_key: str | None = None,
http_session: aiohttp.ClientSession | None = None,
additional_config: dict | None = None,
) -> None:
"""
Create a new instance of Deepgram STT.
Expand Down Expand Up @@ -168,6 +170,7 @@ def __init__(
num_channels=1,
keywords=keywords,
profanity_filter=profanity_filter,
additional_config=additional_config or {},
)
self._session = http_session

Expand All @@ -189,6 +192,7 @@ async def _recognize_impl(
"smart_format": config.smart_format,
"keywords": self._opts.keywords,
"profanity_filter": config.profanity_filter,
**config.additional_config,
}
if config.language:
recognize_config["language"] = config.language
Expand Down Expand Up @@ -243,6 +247,9 @@ def _sanitize_options(self, *, language: str | None = None) -> STTOptions:
if config.detect_language:
config.language = None

for key, value in self._opts.additional_config.items():
setattr(config, key, value)

return config


Expand Down Expand Up @@ -303,6 +310,7 @@ async def _run(self, max_retry: int) -> None:
"filler_words": self._opts.filler_words,
"keywords": self._opts.keywords,
"profanity_filter": self._opts.profanity_filter,
**self._opts.additional_config,
}

if self._opts.language:
Expand Down Expand Up @@ -549,5 +557,6 @@ def _to_deepgram_url(opts: dict, *, websocket: bool = False) -> str:

# lowercase bools
opts = {k: str(v).lower() if isinstance(v, bool) else v for k, v in opts.items()}
logger.info(f"Connecting to Deepgram with configs: {opts}")
base_url = BASE_URL_WS if websocket else BASE_URL
return f"{base_url}?{urlencode(opts, doseq=True)}"
Loading