-
Notifications
You must be signed in to change notification settings - Fork 2.6k
AssemblyAI added EU streaming endpoint option #4571
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -77,7 +77,14 @@ def __init__( | |||||||||||||||||||||||||||||||||||||
| keyterms_prompt: NotGivenOr[list[str]] = NOT_GIVEN, | ||||||||||||||||||||||||||||||||||||||
| http_session: aiohttp.ClientSession | None = None, | ||||||||||||||||||||||||||||||||||||||
| buffer_size_seconds: float = 0.05, | ||||||||||||||||||||||||||||||||||||||
| endpoint_url: str = "wss://streaming.assemblyai.com/v3/ws", | ||||||||||||||||||||||||||||||||||||||
| ): | ||||||||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||||||||
| Args: | ||||||||||||||||||||||||||||||||||||||
| endpoint_url: The AssemblyAI streaming WebSocket endpoint URL. Use the EU endpoint | ||||||||||||||||||||||||||||||||||||||
| (wss://streaming.eu.assemblyai.com/v3/ws) for streaming in the EU. Defaults to | ||||||||||||||||||||||||||||||||||||||
| wss://streaming.assemblyai.com/v3/ws. | ||||||||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||||||||
| super().__init__( | ||||||||||||||||||||||||||||||||||||||
| capabilities=stt.STTCapabilities( | ||||||||||||||||||||||||||||||||||||||
| streaming=True, | ||||||||||||||||||||||||||||||||||||||
|
|
@@ -86,6 +93,7 @@ def __init__( | |||||||||||||||||||||||||||||||||||||
| offline_recognize=False, | ||||||||||||||||||||||||||||||||||||||
| ), | ||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||
| self._endpoint_url = endpoint_url | ||||||||||||||||||||||||||||||||||||||
| assemblyai_api_key = api_key if is_given(api_key) else os.environ.get("ASSEMBLYAI_API_KEY") | ||||||||||||||||||||||||||||||||||||||
| if not assemblyai_api_key: | ||||||||||||||||||||||||||||||||||||||
| raise ValueError( | ||||||||||||||||||||||||||||||||||||||
|
|
@@ -145,6 +153,7 @@ def stream( | |||||||||||||||||||||||||||||||||||||
| opts=config, | ||||||||||||||||||||||||||||||||||||||
| api_key=self._api_key, | ||||||||||||||||||||||||||||||||||||||
| http_session=self.session, | ||||||||||||||||||||||||||||||||||||||
| endpoint_url=self._endpoint_url, | ||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||
| self._streams.add(stream) | ||||||||||||||||||||||||||||||||||||||
| return stream | ||||||||||||||||||||||||||||||||||||||
|
|
@@ -189,12 +198,14 @@ def __init__( | |||||||||||||||||||||||||||||||||||||
| conn_options: APIConnectOptions, | ||||||||||||||||||||||||||||||||||||||
| api_key: str, | ||||||||||||||||||||||||||||||||||||||
| http_session: aiohttp.ClientSession, | ||||||||||||||||||||||||||||||||||||||
| endpoint_url: str, | ||||||||||||||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you move this to the
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i'm not quite sure what you mean. Could you suggest how/what to change? |
||||||||||||||||||||||||||||||||||||||
| ) -> None: | ||||||||||||||||||||||||||||||||||||||
| super().__init__(stt=stt, conn_options=conn_options, sample_rate=opts.sample_rate) | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| self._opts = opts | ||||||||||||||||||||||||||||||||||||||
| self._api_key = api_key | ||||||||||||||||||||||||||||||||||||||
| self._session = http_session | ||||||||||||||||||||||||||||||||||||||
| self._endpoint_url = endpoint_url | ||||||||||||||||||||||||||||||||||||||
| self._speech_duration: float = 0 | ||||||||||||||||||||||||||||||||||||||
| self._last_preflight_start_time: float = 0 | ||||||||||||||||||||||||||||||||||||||
| self._reconnect_event = asyncio.Event() | ||||||||||||||||||||||||||||||||||||||
|
|
@@ -346,13 +357,12 @@ async def _connect_ws(self) -> aiohttp.ClientWebSocketResponse: | |||||||||||||||||||||||||||||||||||||
| "User-Agent": "AssemblyAI/1.0 (integration=Livekit)", | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| ws_url = "wss://streaming.assemblyai.com/v3/ws" | ||||||||||||||||||||||||||||||||||||||
| filtered_config = { | ||||||||||||||||||||||||||||||||||||||
| k: ("true" if v else "false") if isinstance(v, bool) else v | ||||||||||||||||||||||||||||||||||||||
| for k, v in live_config.items() | ||||||||||||||||||||||||||||||||||||||
| if v is not None | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| url = f"{ws_url}?{urlencode(filtered_config)}" | ||||||||||||||||||||||||||||||||||||||
| url = f"{self._endpoint_url}?{urlencode(filtered_config)}" | ||||||||||||||||||||||||||||||||||||||
| ws = await self._session.ws_connect(url, headers=headers) | ||||||||||||||||||||||||||||||||||||||
|
Comment on lines
360
to
366
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Build the WS URL safely if
🛠️ Proposed fix-from urllib.parse import urlencode
+from urllib.parse import parse_qsl, urlencode, urlsplit, urlunsplit
@@
- url = f"{self._endpoint_url}?{urlencode(filtered_config)}"
+ split = urlsplit(self._endpoint_url)
+ query = dict(parse_qsl(split.query))
+ query.update(filtered_config)
+ url = urlunsplit((split.scheme, split.netloc, split.path, urlencode(query), split.fragment))📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||
| return ws | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do you want this to be a base_url instead? do you expect the
/v3/wsparameter to be modifiable.