@@ -61,7 +61,14 @@ interface TTSContextType {
6161const TTSContext = createContext < TTSContextType | undefined > ( undefined ) ;
6262
6363export function TTSProvider ( { children } : { children : React . ReactNode } ) {
64- const { apiKey : openApiKey , baseUrl : openApiBaseUrl , isLoading : configIsLoading } = useConfig ( ) ;
64+ const {
65+ apiKey : openApiKey ,
66+ baseUrl : openApiBaseUrl ,
67+ isLoading : configIsLoading ,
68+ voiceSpeed,
69+ voice : configVoice ,
70+ updateConfigKey
71+ } = useConfig ( ) ;
6572
6673 // Move openai initialization to a ref to avoid breaking hooks rules
6774 const openaiRef = useRef < OpenAI | null > ( null ) ;
@@ -75,8 +82,8 @@ export function TTSProvider({ children }: { children: React.ReactNode }) {
7582 const [ activeHowl , setActiveHowl ] = useState < Howl | null > ( null ) ;
7683 const [ audioQueue ] = useState < AudioBuffer [ ] > ( [ ] ) ;
7784 const [ isProcessing , setIsProcessing ] = useState ( false ) ;
78- const [ speed , setSpeed ] = useState ( 1 ) ;
79- const [ voice , setVoice ] = useState ( 'alloy' ) ;
85+ const [ speed , setSpeed ] = useState ( voiceSpeed ) ;
86+ const [ voice , setVoice ] = useState ( configVoice ) ;
8087 const [ availableVoices , setAvailableVoices ] = useState < string [ ] > ( [ ] ) ;
8188
8289 const [ currDocPage , setCurrDocPage ] = useState < number > ( 1 ) ;
@@ -422,6 +429,7 @@ export function TTSProvider({ children }: { children: React.ReactNode }) {
422429
423430 const setSpeedAndRestart = useCallback ( ( newSpeed : number ) => {
424431 setSpeed ( newSpeed ) ;
432+ updateConfigKey ( 'voiceSpeed' , newSpeed ) ;
425433 // Clear the audio cache since it contains audio at the old speed
426434 audioCacheRef . current . clear ( ) ;
427435
@@ -431,10 +439,11 @@ export function TTSProvider({ children }: { children: React.ReactNode }) {
431439 setCurrentIndex ( currentIdx ) ;
432440 setIsPlaying ( true ) ;
433441 }
434- } , [ isPlaying , currentIndex , stop ] ) ;
442+ } , [ isPlaying , currentIndex , stop , updateConfigKey ] ) ;
435443
436444 const setVoiceAndRestart = useCallback ( ( newVoice : string ) => {
437445 setVoice ( newVoice ) ;
446+ updateConfigKey ( 'voice' , newVoice ) ;
438447 // Clear the audio cache since it contains audio with the old voice
439448 audioCacheRef . current . clear ( ) ;
440449
@@ -444,7 +453,7 @@ export function TTSProvider({ children }: { children: React.ReactNode }) {
444453 setCurrentIndex ( currentIdx ) ;
445454 setIsPlaying ( true ) ;
446455 }
447- } , [ isPlaying , currentIndex , stop ] ) ;
456+ } , [ isPlaying , currentIndex , stop , updateConfigKey ] ) ;
448457
449458 const value = {
450459 isPlaying,
0 commit comments