-
Notifications
You must be signed in to change notification settings - Fork 1.4k
feat: play notification sound on agent response #707
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
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 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -89,6 +89,32 @@ function Chat({ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| useEffect(() => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| onLoadingChange?.(runId, isLoading); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, [runId, isLoading, onLoadingChange]); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Play a notification sound when the agent finishes responding | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const prevLoadingRef = useRef(isLoading); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| useEffect(() => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const wasLoading = prevLoadingRef.current; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| prevLoadingRef.current = isLoading; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (!wasLoading || isLoading) return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Agent just finished — play a short notification beep | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const ctx = new AudioContext(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const osc = ctx.createOscillator(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const gain = ctx.createGain(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| osc.connect(gain); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| gain.connect(ctx.destination); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| osc.type = "sine"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Play two quick ascending tones | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| osc.frequency.setValueAtTime(880, ctx.currentTime); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| osc.frequency.setValueAtTime(1100, ctx.currentTime + 0.08); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| gain.gain.setValueAtTime(0.12, ctx.currentTime); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| gain.gain.exponentialRampToValueAtTime(0.001, ctx.currentTime + 0.2); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| osc.start(ctx.currentTime); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| osc.stop(ctx.currentTime + 0.2); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } catch { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // AudioContext may fail in some environments — silently ignore | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+100
to
+116
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.
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, [isLoading]); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const [hermesSessionId, setHermesSessionId] = useState<string | null>( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| initialSessionId ?? null, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
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.
Chatinstance, including background sessions. Every other audio/keyboard side effect in this component guards onactive(see theCmd+Nhandler, context-menu handlers, etc.), but the notification sound doesn't. If a user has two background sessions finishing simultaneously they'll both beep, and a background session finishing while the user is reading the active chat will emit a misleading sound.Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!