Skip to content

Conversation

@pabloFuente
Copy link
Contributor

The AWS Python SDK used by livekit-plugins-aws in the STT implementation (amazon-transcribe) has known critical CPU bottleneck performance issues and has been deprecated by AWS in favor of aws-sdk-transcribe-streaming.

This PR replaces the old, deprecated, low-performance AWS SDK with the new official AWS SDK. I have tested the problematic scenario explained in this issue (#3739) and it is no longer a problem when using this PR. Transcribing multiple users from the same LiveKit Agent using livekit-plugin-aws STT is now possible, with no delays. The scope of the commit is quite small, so I do not expect any significant side effects.

…-streaming

- Replace `amazon-transcribe` dependency with `aws_sdk_transcribe_streaming` in pyproject.toml
- Bump minimum Python version to 3.12, as requried by the official AWS SDK.
- Update `STT` implementation to use the new SDK client and models.
- Refactor `SpeechStream._run` to use `TranscribeStreamingClient` from the new SDK.
- Update audio input streaming to use `AudioStreamAudioEvent`.
- Update transcript event processing to match the new SDK's event structure.
- Remove custom credential resolver logic in favor of `EnvironmentCredentialsResolver`
Prevent race conditions and unhandled exceptions during participant disconnects:
Changes:
- Implement a graceful shutdown sequence: close input stream first, then wait for output stream to finish.
- Use `asyncio.shield` to protect inner tasks from immediate cancellation, allowing for proper cleanup.
- Suppress `concurrent.futures.InvalidStateError` in `handle_transcript_events` to avoid noise from AWS CRT bindings during shutdown.
- Ensure `gather_future` is awaited to prevent "exception never retrieved" warnings.
- Use `contextlib.suppress` for cleaner exception handling during resource cleanup.
@pabloFuente
Copy link
Contributor Author

Unit test tests/test_chat_ctx.py is failing with an authorization error:

Error code: 401 - {'error': {'message': "You didn't provide an API key. You need to provide your API key in an Authorization header..."}

I don't think this has anything to do with the changes in my PR.

Copy link
Contributor

@longcw longcw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for creating the pr! Looks good to me, something nit:

Copy link
Contributor

@longcw longcw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@davidzhao davidzhao merged commit 391bbdd into livekit:main Nov 28, 2025
11 of 13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants