The all-in-one local AI studio for your desktop: chat, image and video generation and a coding agent in one free, open source app. Windows and Linux. No Docker, no terminal, no cloud required.
TypeScript agentai-chatai-studioall-in-onecoding-agentdesktop-appfluximage-generationlinuxllmlocal-ailocal-llmopen-sourceprivacyself-hostedstable-diffusionuncensoreduncensored-aivideo-generationwindows
fix(voice): say when the external voice fails and the system voice speaks
purple708b359c95b4
diff --git a/src/components/chat/SpeakerButton.tsx b/src/components/chat/SpeakerButton.tsxindex 016a9195..8eb78474 100644--- a/src/components/chat/SpeakerButton.tsx+++ b/src/components/chat/SpeakerButton.tsx@@ -1,5 +1,7 @@+import { useState } from "react"import { Volume2, VolumeX } from "lucide-react"import { useVoice } from "../../hooks/useVoice"+import { useVoiceStore } from "../../stores/voiceStore"interface Props {text: string@@ -7,6 +9,11 @@ interface Props {export function SpeakerButton({ text }: Props) {const { isSpeaking, ttsSupported, ttsAvailable, ttsExternalReady, ttsEnabled, speakTextStreaming, stopSpeaking } = useVoice()+ // Jaeger B, B11: when the external voice fails, read-aloud switches to the+ // system voice. The bubble whose button was pressed says so, with the+ // error, instead of speaking in another voice without a word.+ const fallbackReason = useVoiceStore((s) => (s.ttsMode === "external" ? s.ttsFallbackReason : null))+ const [pressed, setPressed] = useState(false)// Show the read-aloud button only when the feature is on AND some TTS engine// is usable: an external HTTP engine (#58), local neural Piper, or the@@ -19,11 +26,13 @@ export function SpeakerButton({ text }: Props) {if (isSpeaking) {stopSpeaking()} else {+ setPressed(true)speakTextStreaming(text)}}return (+ <><buttononClick={handleClick}className={@@ -37,5 +46,11 @@ export function SpeakerButton({ text }: Props) {>{isSpeaking ? <VolumeX size={12} /> : <Volume2 size={12} />}</button>+ {pressed && fallbackReason && (+ <span role="status" className="text-[0.6rem] leading-snug text-amber-600 dark:text-amber-400 max-w-[18rem]">+ {fallbackReason}+ </span>+ )}+ </>)}diff --git a/src/components/settings/SpeechSettings.tsx b/src/components/settings/SpeechSettings.tsxindex 4b157937..8668b34a 100644--- a/src/components/settings/SpeechSettings.tsx+++ b/src/components/settings/SpeechSettings.tsx@@ -424,6 +424,10 @@ export function SpeechSettings() {<p className="text-[0.55rem] text-gray-500 leading-snug">Any OpenAI-compatible TTS endpoint (e.g. Kokoro-FastAPI). Used for read-aloud instead of Piper. Stays on your machine when the endpoint is local.</p>+ {/* B11: the external voice fell back to the system voice in silence. */}+ {voiceSettings.ttsFallbackReason && (+ <p className={`text-[0.55rem] leading-snug ${HINWEIS_TEXT.fehler}`}>{voiceSettings.ttsFallbackReason}</p>+ )}</div>)}</>)diff --git a/src/hooks/__tests__/external-voice-failure-is-said.dom.test.tsx b/src/hooks/__tests__/external-voice-failure-is-said.dom.test.tsxnew file mode 100644index 00000000..3524034f--- /dev/null+++ b/src/hooks/__tests__/external-voice-failure-is-said.dom.test.tsx@@ -0,0 +1,83 @@+// @vitest-environment jsdom+/**+ * Jaeger B, B11: with Voice engine "External HTTP" and an endpoint that does+ * not deliver audio, read-aloud switched to the system voice and said+ * nothing; ttsFallbackReason stayed null. Now the reason is recorded with+ * the error, and the Read aloud button that was pressed shows it.+ *+ * Run: npx vitest run src/hooks/__tests__/external-voice-failure-is-said.dom.test.tsx+ */+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'+import { createElement } from 'react'+import { act, cleanup, fireEvent, render, renderHook, screen } from '@testing-library/react'+import { standOn } from '../../test-support/devices'++const voice = vi.hoisted(() => ({+ synthesizeExternal: vi.fn(),+ playNeuralAudio: vi.fn(async () => {}),+ stopNeuralAudio: vi.fn(),+ stopSpeaking: vi.fn(),+ isSpeechSynthesisSupported: vi.fn(() => true),+ speak: vi.fn(async () => {}),+ speakStreaming: vi.fn(async (_text: string, ..._rest: unknown[]) => {}),+ getVoicesAsync: vi.fn(async () => []),+}))+vi.mock('../../api/voice', async (orig) => ({ ...((await orig()) as object), ...voice }))+vi.mock('../../lib/logger', () => ({ log: { error: vi.fn(), warn: vi.fn(), info: vi.fn(), debug: vi.fn() } }))+vi.mock('../../stores/cloudAuthStore', async (orig) => ({ ...((await orig()) as object), deriveCloudAvailable: () => false }))++import { useVoice, stopSpeechPlayback } from '../useVoice'+import { useVoiceStore } from '../../stores/voiceStore'+import { SpeakerButton } from '../../components/chat/SpeakerButton'++beforeEach(() => {+ standOn('mac')+ for (const fn of Object.values(voice)) fn.mockClear()+ voice.synthesizeExternal.mockReset()+ voice.synthesizeExternal.mockRejectedValue(new Error('neural audio playback failed'))+ useVoiceStore.setState({+ isSpeaking: false, ttsFallbackReason: null, ttsEnabled: true, ttsAvailable: false,+ ttsMode: 'external', externalTtsUrl: 'http://127.0.0.1:18943/v1/audio/speech', externalTtsVoice: 'alloy',+ })+})+afterEach(() => {+ cleanup()+ stopSpeechPlayback()+ vi.unstubAllGlobals()+})++describe('B11: a failed external voice is said, not hidden', () => {+ it('records why the system voice spoke, with the error', async () => {+ const { result } = renderHook(() => useVoice())+ await act(async () => { await result.current.speakText('Hello there.') })+ expect(voice.synthesizeExternal).toHaveBeenCalledTimes(1)+ expect(voice.speak).toHaveBeenCalledTimes(1)+ const reason = useVoiceStore.getState().ttsFallbackReason+ expect(reason).toContain('external voice failed')+ expect(reason).toContain('neural audio playback failed')+ expect(reason).toContain('system voice')+ })++ it('a working external voice clears the reason', async () => {+ useVoiceStore.setState({ ttsFallbackReason: 'old' })+ voice.synthesizeExternal.mockResolvedValue('blob:ok')+ const { result } = renderHook(() => useVoice())+ await act(async () => { await result.current.speakText('Hello there.') })+ expect(useVoiceStore.getState().ttsFallbackReason).toBeNull()+ expect(voice.speak).not.toHaveBeenCalled()+ })++ it('the pressed Read aloud button shows the notice', async () => {+ render(createElement(SpeakerButton, { text: 'Hello there.' }))+ expect(screen.queryByRole('status')).toBeNull()+ await act(async () => { fireEvent.click(screen.getByLabelText('Read aloud')) })+ await act(async () => { await new Promise((r) => setTimeout(r, 0)) })+ expect(screen.getByRole('status').textContent).toContain('external voice failed')+ })++ it('switching the engine drops a reason of the other engine', () => {+ useVoiceStore.setState({ ttsMode: 'piper', ttsFallbackReason: 'Piper failed to speak (x).' })+ useVoiceStore.getState().updateVoiceSettings({ ttsMode: 'external' })+ expect(useVoiceStore.getState().ttsFallbackReason).toBeNull()+ })+})diff --git a/src/hooks/useVoice.ts b/src/hooks/useVoice.tsindex 42f2ee77..bdda0c1e 100644--- a/src/hooks/useVoice.ts+++ b/src/hooks/useVoice.ts@@ -451,6 +451,14 @@ export function stopSpeechPlayback(): void {useVoiceStore.getState().setSpeaking(false);}+/** The notice when the external HTTP voice (#58) could not speak (B11). */+export function externalTtsFallbackReason(err: unknown, systemVoice: boolean): string {+ const detail = (err instanceof Error ? err.message : String(err)) || "no detail";+ return systemVoice+ ? `The external voice failed (${detail}). Read-aloud used the system voice instead.`+ : `The external voice failed (${detail}). No system voice is available, so nothing was read.`;+}+/*** Read-aloud on a phone.*@@ -863,10 +871,15 @@ export function useVoice() {const url = await synthesizeExternal(text, store.externalTtsUrl.trim(), store.externalTtsVoice || undefined);if (stopped()) return;await playNeuralAudio(url);+ store.setTtsFallbackReason(null);return;} catch (err) {if (stopped()) return;log.error("External TTS failed, falling back to browser voices", { err });+ // Jaeger B, B11: the same silent switch as Piper had (#77). Who+ // set up an own voice heard another one and was told nothing.+ // The reason is shown at the Read aloud button and in Settings.+ store.setTtsFallbackReason(externalTtsFallbackReason(err, ttsSupported));}} else {// Local neural (Piper). Trust the cached availability flag, but if itdiff --git a/src/stores/voiceStore.ts b/src/stores/voiceStore.tsindex 4f0df764..521f37ce 100644--- a/src/stores/voiceStore.ts+++ b/src/stores/voiceStore.ts@@ -172,7 +172,13 @@ export const useVoiceStore = create<VoiceState>()(setRetryTakeReady: (ready) => set({ retryTakeReady: ready }),setPiperVoice: (voice) => set({ piperVoice: voice }),- updateVoiceSettings: (settings) => set((state) => ({ ...state, ...settings })),+ // A fallback reason belongs to the engine that failed: switching the+ // engine drops it, so a Piper reason never shows under External (B11).+ updateVoiceSettings: (settings) => set((state) => ({+ ...state,+ ...settings,+ ...(settings.ttsMode !== undefined && settings.ttsMode !== state.ttsMode ? { ttsFallbackReason: null } : {}),+ })),resetTransient: () =>set({