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

services(aws): don't block the asyncio event loop #535

Closed
wants to merge 1 commit into from

Conversation

aconchillo
Copy link
Contributor

No description provided.

@aconchillo aconchillo requested a review from markbackman October 2, 2024 02:16
@@ -146,7 +148,9 @@ async def run_tts(self, text: str) -> AsyncGenerator[Frame, None]:
# Filter out None values
filtered_params = {k: v for k, v in params.items() if v is not None}

response = self._polly_client.synthesize_speech(**filtered_params)
response = await asyncio.to_thread(
self._polly_client.synthesize_speech(**filtered_params)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this needs this update otherwise it's treated as callable.

Suggested change
self._polly_client.synthesize_speech(**filtered_params)
lambda: self._polly_client.synthesize_speech(**filtered_params)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oops, sorry. It has to be (updated):

            response = await asyncio.to_thread(
                self._polly_client.synthesize_speech, **filtered_params
            )

@markbackman
Copy link
Contributor

This does work to generate speech sooner, but it produces choppy audio until all of the speech is generated. Once the speech is generated, then things smooth out. I think this has to do with a limitation with Polly where it's intended to generate speech entirely before responding. You can test this out with 07m-interruptible-aws.py and ask it to give you a long response (e.g. "tell me a story").

@aconchillo
Copy link
Contributor Author

This does work to generate speech sooner, but it produces choppy audio until all of the speech is generated. Once the speech is generated, then things smooth out. I think this has to do with a limitation with Polly where it's intended to generate speech entirely before responding. You can test this out with 07m-interruptible-aws.py and ask it to give you a long response (e.g. "tell me a story").

Yes, but it would be the same without the asyncio.thread right?

@aconchillo
Copy link
Contributor Author

This does work to generate speech sooner, but it produces choppy audio until all of the speech is generated. Once the speech is generated, then things smooth out. I think this has to do with a limitation with Polly where it's intended to generate speech entirely before responding. You can test this out with 07m-interruptible-aws.py and ask it to give you a long response (e.g. "tell me a story").

Yes, but it would be the same without the asyncio.thread right?

The asyncio.thread only prevents the asyncio event loop not being blocked. It doesn't fix anything else.

@aconchillo aconchillo force-pushed the aleix/aws-asyncio-non-blocking branch from 10dc293 to c4ba426 Compare October 2, 2024 15:14
@markbackman markbackman force-pushed the aleix/aws-asyncio-non-blocking branch from c4ba426 to f0e8bb7 Compare October 2, 2024 15:46
@markbackman
Copy link
Contributor

I just pushed the change you suggested above. Using it, I still get choppy speech when a lot of text is generated. We need to better understand the root cause before merging this.

@markbackman markbackman force-pushed the aleix/aws-asyncio-non-blocking branch from f0e8bb7 to e1075e2 Compare October 2, 2024 15:54
@aconchillo
Copy link
Contributor Author

So weird, let's close for now.

@aconchillo aconchillo closed this Oct 2, 2024
@aconchillo aconchillo deleted the aleix/aws-asyncio-non-blocking branch October 23, 2024 20:50
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.

2 participants