Repository navigation
feat(tts): add text-to-speech controls for bot messages #757
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
Open
awaisanwarcode
wants to merge
2
commits into
AOSSIE-Org:main
Choose a base branch
from
awaisanwarcode:feat/bot-text-to-speech
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,125 @@ | ||
| /** | ||
| * BotVoiceControls | ||
| * | ||
| * A compact, accessible Play / Pause / Stop control strip for a single | ||
| * bot message in DebateAI's DebateRoom. | ||
| * | ||
| * Props: | ||
| * messageId – stable unique ID for this message (used to identify | ||
| * which message is currently active in the hook). | ||
| * text – the bot message text to speak. | ||
| * botName – the bot's display name (used for voice-personality lookup). | ||
| * tts – the UseSpeechSynthesisReturn object from useSpeechSynthesis(), | ||
| * passed in from the parent so a single hook instance manages | ||
| * all messages (single-active-playback guarantee). | ||
| * | ||
| * Behaviour: | ||
| * - If TTS is unsupported, renders nothing. | ||
| * - Shows a play button when idle (or when another message is active). | ||
| * - When THIS message is active: | ||
| * • Shows pause button while playing. | ||
| * • Shows play (resume) button while paused. | ||
| * • Always shows stop button when active. | ||
| * - Clicking play on a different message stops any existing playback first | ||
| * (handled inside useSpeechSynthesis.play()). | ||
| */ | ||
|
|
||
| import React from "react"; | ||
| import { Play, Pause, Square, Volume2 } from "lucide-react"; | ||
| import { Button } from "@/components/ui/button"; | ||
| import type { UseSpeechSynthesisReturn } from "@/hooks/useSpeechSynthesis"; | ||
|
|
||
| interface BotVoiceControlsProps { | ||
| messageId: string; | ||
| text: string; | ||
| botName: string; | ||
| tts: UseSpeechSynthesisReturn; | ||
| } | ||
|
|
||
| const BotVoiceControls: React.FC<BotVoiceControlsProps> = ({ | ||
| messageId, | ||
| text, | ||
| botName, | ||
| tts, | ||
| }) => { | ||
| if (!tts.isSupported) return null; | ||
|
|
||
| const isThisActive = tts.activeMessageId === messageId; | ||
| const isPlaying = isThisActive && tts.playbackState === "playing"; | ||
| const isPaused = isThisActive && tts.playbackState === "paused"; | ||
|
|
||
| const handlePlayPause = () => { | ||
| if (isPlaying) { | ||
| tts.pause(); | ||
| } else if (isPaused) { | ||
| tts.resume(); | ||
| } else { | ||
| // Either idle or a different message is active — start this one. | ||
| tts.play(messageId, text, botName); | ||
| } | ||
| }; | ||
|
|
||
| const handleStop = () => { | ||
| tts.stop(); | ||
| }; | ||
|
|
||
| return ( | ||
| <div | ||
| className="inline-flex items-center gap-1 ml-2" | ||
| role="group" | ||
| aria-label={`Voice controls for ${botName}'s message`} | ||
| > | ||
| {/* Speaker icon — decorative, indicates TTS feature */} | ||
| <Volume2 | ||
| className={`w-3.5 h-3.5 ${ | ||
| isThisActive | ||
| ? "text-primary animate-pulse" | ||
| : "text-muted-foreground opacity-60" | ||
| }`} | ||
| aria-hidden="true" | ||
| /> | ||
|
|
||
| {/* Play / Pause toggle */} | ||
| <Button | ||
| variant="ghost" | ||
| size="icon" | ||
| className="h-6 w-6 rounded-full hover:bg-primary/10 transition-colors" | ||
| onClick={handlePlayPause} | ||
| aria-label={ | ||
| isPlaying | ||
| ? `Pause ${botName}'s message` | ||
| : isPaused | ||
| ? `Resume ${botName}'s message` | ||
| : `Listen to ${botName}'s message` | ||
| } | ||
| title={isPlaying ? "Pause" : isPaused ? "Resume" : "Listen"} | ||
| > | ||
| {isPlaying ? ( | ||
| <Pause className="w-3.5 h-3.5 text-primary" /> | ||
| ) : ( | ||
| <Play | ||
| className={`w-3.5 h-3.5 ${ | ||
| isPaused ? "text-primary" : "text-muted-foreground" | ||
| }`} | ||
| /> | ||
| )} | ||
| </Button> | ||
|
|
||
| {/* Stop button — only visible when this message is active */} | ||
| {isThisActive && ( | ||
| <Button | ||
| variant="ghost" | ||
| size="icon" | ||
| className="h-6 w-6 rounded-full hover:bg-destructive/10 transition-colors" | ||
| onClick={handleStop} | ||
| aria-label={`Stop listening to ${botName}'s message`} | ||
| title="Stop" | ||
| > | ||
| <Square className="w-3 h-3 text-destructive" /> | ||
| </Button> | ||
| )} | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
| export default BotVoiceControls; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.