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

Make AudioPlayer queue global #484

Merged
merged 5 commits into from
Feb 26, 2024
Merged

Make AudioPlayer queue global #484

merged 5 commits into from
Feb 26, 2024

Conversation

Amnish04
Copy link
Collaborator

In #357, I was able to stream audio responses as the LLM response was generated and also optimize the playback.

But there were some problems with it, and follow ups were filed.

This is regarding one of those follow ups - #391.

The problem was that once an audio clip was added to the audio queue, there was no way to stop it from other parts of the application since every invocation to useAudioPlayer hook resulted in a fresh audio queue. This was pretty annoying and made the TTS feature unusable as users had to wait for the previous message announcement to finish before it started playing for the next one.

To fix this issue, I have made the Audio Player queue global, by creating and providing an AudioPlayerContext at the root of the application.

https://github.com/tarasglek/chatcraft.org/compare/amnish04/global-audio-player?expand=1#diff-1cd8b18798a1a103bfe13bef54354c1f3a3bea29a31c8eea1a0c67a3a839b811

This allowed me to expose another function from the hook called clearAudioQueue which can now be called from any application component to pause the current audio clip, and flush the remaining clips in the queue.

Currently, I am using it for 2 scenarios:

  1. The audio for previous message will instantly stop playing as soon as the user asks a new question.
  2. Any audio clips being played via useAudioPlayer will instantly stop as soon as the user disables the TTS setting.

This approach also makes the audio system more robust any we now have a single source of truth for audio clips, and the risk to play multiple audio clips at once is also reduced.

This fixes #391

@Amnish04 Amnish04 self-assigned this Feb 23, 2024
@tarasglek
Copy link
Owner

This is great will get back to you once i had a chance to test it

Copy link

cloudflare-pages bot commented Feb 25, 2024

Deploying with  Cloudflare Pages  Cloudflare Pages

Latest commit: 5ea0510
Status: ✅  Deploy successful!
Preview URL: https://9d052ac7.console-overthinker-dev.pages.dev
Branch Preview URL: https://amnish04-global-audio-player.console-overthinker-dev.pages.dev

View logs

@tarasglek
Copy link
Owner

There is a bug:when I record a new message it keeps talking while I'm recording a reply. It should stop immediately

@Amnish04
Copy link
Collaborator Author

That's right, just pushed the fix!

@tarasglek
Copy link
Owner

works awesome now. lets land

@Amnish04 Amnish04 merged commit 284e866 into main Feb 26, 2024
4 checks passed
kliu57 added a commit that referenced this pull request Mar 4, 2024
created OpenAiProvider and OpenRouterProvider

Make AudioPlayer queue global (#484)

* Make audio player queue global and allow stopping tts

* Pause immediately when another question is asked

* Stop announcing messages as soon as tts is disabled

* Reorder definitions

* TTS should stop as soon as you start recording

src/lib/ChatCraftProvider.ts

fix
kliu57 added a commit that referenced this pull request Mar 4, 2024
- Catch up with main - Make AudioPlayer queue global (#484)
kliu57 added a commit that referenced this pull request Mar 4, 2024
- Catch up with main - Make AudioPlayer queue global (#484)
@kliu57 kliu57 added this to the Release 1.4 milestone Mar 7, 2024
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.

Stop playing audio when tts is turned off
3 participants