diff --git a/frontend/src/components/message/FloatingTTSButton.tsx b/frontend/src/components/message/FloatingTTSButton.tsx
new file mode 100644
index 00000000..394f98ef
--- /dev/null
+++ b/frontend/src/components/message/FloatingTTSButton.tsx
@@ -0,0 +1,53 @@
+import { Volume2, VolumeX, Loader2 } from 'lucide-react'
+import { useTTS } from '@/hooks/useTTS'
+import { useMobile } from '@/hooks/useMobile'
+
+interface FloatingTTSButtonProps {
+ content: string
+}
+
+export function FloatingTTSButton({ content }: FloatingTTSButtonProps) {
+ const { speak, stop, isEnabled, isPlaying, isLoading, originalText } = useTTS()
+ const isMobile = useMobile()
+
+ if (!isEnabled || !content.trim()) {
+ return null
+ }
+
+ const isThisPlaying = (isPlaying || isLoading) && originalText === content
+
+ const handleClick = () => {
+ if (isThisPlaying) {
+ stop()
+ } else {
+ speak(content)
+ }
+ }
+
+ const buttonPosition = isMobile ? 'bottom-24' : 'bottom-20'
+
+ return (
+
+ )
+}
diff --git a/frontend/src/components/message/MessagePart.tsx b/frontend/src/components/message/MessagePart.tsx
index 05227111..15931ea2 100644
--- a/frontend/src/components/message/MessagePart.tsx
+++ b/frontend/src/components/message/MessagePart.tsx
@@ -1,8 +1,7 @@
import { memo } from 'react'
import type { components } from '@/api/opencode-types'
-import { Volume2, Loader2 } from 'lucide-react'
+import { Volume2, VolumeX, Loader2 } from 'lucide-react'
import { TextPart } from './TextPart'
-import { SquareFill } from '@/components/ui/square-fill'
import { PatchPart } from './PatchPart'
import { ToolCallPart } from './ToolCallPart'
import { RetryPart } from './RetryPart'
@@ -59,14 +58,12 @@ function getCopyableContent(part: Part, allParts?: Part[]): string {
}
}
-
-
interface TTSButtonProps {
content: string
className?: string
}
-export function TTSButton({ content, className = "" }: TTSButtonProps) {
+function TTSButton({ content, className = "" }: TTSButtonProps) {
const { speak, stop, isEnabled, isPlaying, isLoading, originalText } = useTTS()
if (!isEnabled || !content.trim()) {
@@ -93,7 +90,7 @@ export function TTSButton({ content, className = "" }: TTSButtonProps) {
{isLoading && isThisPlaying ? (
) : isThisPlaying ? (
-
+
) : (
)}
@@ -101,8 +98,6 @@ export function TTSButton({ content, className = "" }: TTSButtonProps) {
)
}
-
-
export const MessagePart = memo(function MessagePart({ part, role, allParts, partIndex, onFileClick, onChildSessionClick, messageTextContent }: MessagePartProps) {
const copyableContent = getCopyableContent(part, allParts)
const isMobile = useMobile()
diff --git a/frontend/src/pages/SessionDetail.tsx b/frontend/src/pages/SessionDetail.tsx
index 1f301b1e..5c7f034f 100644
--- a/frontend/src/pages/SessionDetail.tsx
+++ b/frontend/src/pages/SessionDetail.tsx
@@ -4,7 +4,8 @@ import { useQuery } from "@tanstack/react-query";
import { getRepo } from "@/api/repos";
import { MessageThread } from "@/components/message/MessageThread";
import { PromptInput, type PromptInputHandle } from "@/components/message/PromptInput";
-import { X, VolumeX, FolderOpen, Plug, Settings, CornerUpLeft, GitCommitHorizontal, Brain, ShieldOff, Code } from "lucide-react";
+import { FloatingTTSButton } from '@/components/message/FloatingTTSButton'
+import { X, FolderOpen, Plug, Settings, CornerUpLeft, GitCommitHorizontal, Brain, ShieldOff, Code } from "lucide-react";
import { ModelSelectDialog } from "@/components/model/ModelSelectDialog";
import { Header } from "@/components/ui/header";
import { SessionList } from "@/components/session/SessionList";
@@ -130,13 +131,14 @@ export function SessionDetail() {
const { open: openSettings } = useSettingsDialog();
const { model, modelString } = useModelSelection(opcodeUrl, repoDirectory);
const isEditingMessage = useUIState((state) => state.isEditingMessage);
- const { isPlaying, stop } = useTTS();
+ const { isEnabled: ttsEnabled } = useTTS();
const setSessionStatus = useSessionStatus((state) => state.setStatus);
const { current: currentQuestion, reply: replyToQuestion, reject: rejectQuestion } = useQuestions();
const sessionStatus = useSessionStatusForSession(sessionId);
const isSessionActive = sessionStatus.type === 'busy' || sessionStatus.type === 'retry';
const lastAssistantMessage = messages?.filter(m => m.info.role === 'assistant').at(-1);
+ const lastAssistantText = lastAssistantMessage?.parts.filter(p => p.type === 'text').map(p => p.text).join('\n\n') || '';
const hasIncompleteMessages = lastAssistantMessage ? !('completed' in lastAssistantMessage.info.time && lastAssistantMessage.info.time.completed) : false;
const hasActiveStream = hasIncompleteMessages && isSessionActive;
@@ -497,20 +499,9 @@ export function SessionDetail() {
Waiting for shortcut key...
)}
- {isPlaying && !leaderActive && (
-
+
+ {ttsEnabled && lastAssistantText && !hasPromptContent && !hasActiveStream && (
+
)}
{currentQuestion && currentQuestion.sessionID === sessionId && (