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

Added support for custom deepgram base url #1088

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ def __init__(
profanity_filter: bool = False,
api_key: str | None = None,
http_session: aiohttp.ClientSession | None = None,
base_url: str = BASE_URL,
base_url_ws: str = BASE_URL_WS
) -> None:
"""
Create a new instance of Deepgram STT.
Expand All @@ -132,6 +134,9 @@ def __init__(
)
)

self._base_url = base_url
self._base_url_ws = base_url_ws

api_key = api_key or os.environ.get("DEEPGRAM_API_KEY")
if api_key is None:
raise ValueError("Deepgram API key is required")
Expand Down Expand Up @@ -189,6 +194,8 @@ async def _recognize_impl(
"smart_format": config.smart_format,
"keywords": self._opts.keywords,
"profanity_filter": config.profanity_filter,
"base_url": self._base_url,
"base_url_ws": self._base_url_ws
}
if config.language:
recognize_config["language"] = config.language
Expand Down Expand Up @@ -303,6 +310,8 @@ async def _run(self, max_retry: int) -> None:
"filler_words": self._opts.filler_words,
"keywords": self._opts.keywords,
"profanity_filter": self._opts.profanity_filter,
"base_url": self._base_url,
"base_url_ws": self._base_url_ws
}

if self._opts.language:
Expand Down Expand Up @@ -549,5 +558,5 @@ 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()}
base_url = BASE_URL_WS if websocket else BASE_URL
base_url = opts.get("base_url_ws") if websocket else opts.get("base_url")
return f"{base_url}?{urlencode(opts, doseq=True)}"
Loading