diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx
index f6a3d13a..96a661c5 100644
--- a/frontend/src/App.tsx
+++ b/frontend/src/App.tsx
@@ -7,6 +7,7 @@ import { SessionDetail } from './pages/SessionDetail'
import { SettingsDialog } from './components/settings/SettingsDialog'
import { useSettingsDialog } from './hooks/useSettingsDialog'
import { useTheme } from './hooks/useTheme'
+import { TTSProvider } from './contexts/TTSContext'
const queryClient = new QueryClient({
defaultOptions: {
@@ -44,7 +45,9 @@ function App() {
return (
-
+
+
+
)
}
diff --git a/frontend/src/hooks/useTTS.ts b/frontend/src/hooks/useTTS.ts
index 78005dcb..090eaae0 100644
--- a/frontend/src/hooks/useTTS.ts
+++ b/frontend/src/hooks/useTTS.ts
@@ -1,248 +1,12 @@
-import { useState, useRef, useCallback, useEffect } from 'react'
-import { useSettings } from './useSettings'
-import { API_BASE_URL } from '@/config'
+import { useContext } from 'react'
+import { TTSContext, type TTSContextValue, type TTSState } from '@/contexts/tts-context'
-const SENTENCE_REGEX = /(?<=[.!?])\s+/
-const SENTENCES_PER_CHUNK = 2
+export type { TTSState }
-function splitIntoChunks(text: string): string[] {
- const sentences = text.split(SENTENCE_REGEX).filter(s => s.trim().length > 0)
- if (sentences.length === 0) return [text]
-
- const chunks: string[] = []
- for (let i = 0; i < sentences.length; i += SENTENCES_PER_CHUNK) {
- const chunk = sentences.slice(i, i + SENTENCES_PER_CHUNK).join(' ')
- if (chunk.trim()) chunks.push(chunk.trim())
- }
-
- return chunks.length > 0 ? chunks : [text]
-}
-
-export type TTSState = 'idle' | 'loading' | 'playing' | 'error'
-
-export function useTTS() {
- const { preferences } = useSettings()
- const [state, setState] = useState('idle')
- const [error, setError] = useState(null)
- const [currentText, setCurrentText] = useState(null)
-
- const abortControllerRef = useRef(null)
- const audioRef = useRef(null)
- const stoppedRef = useRef(false)
- const chunksRef = useRef([])
- const chunkIndexRef = useRef(0)
- const prefetchedBlobsRef = useRef