-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expand file tree
/
Copy pathTtsContext.tsx
More file actions
49 lines (44 loc) · 1.2 KB
/
TtsContext.tsx
File metadata and controls
49 lines (44 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import { createContext, useContext, type ReactNode } from 'react';
import { useSpeechOutput } from '../hooks/useSpeechOutput';
import type { VoiceInfo } from '../hooks/useSpeechOutput';
type TtsContextValue = {
enabled: boolean;
toggle: () => void;
rate: number;
setRate: (rate: number) => void;
pitch: number;
setPitch: (pitch: number) => void;
voiceURI: string;
setVoiceURI: (uri: string) => void;
lang: string;
setLang: (lang: string) => void;
isSpeaking: boolean;
speak: (text: string) => void;
stop: () => void;
testVoice: () => void;
availableVoices: VoiceInfo[];
filteredVoices: VoiceInfo[];
availableLanguages: string[];
};
const TtsContext = createContext<TtsContextValue | null>(null);
type ChatMessage = {
type: string;
content?: string;
isStreaming?: boolean;
isToolUse?: boolean;
isInteractivePrompt?: boolean;
[key: string]: unknown;
};
export function TtsProvider({
chatMessages,
children,
}: {
chatMessages: ChatMessage[];
children: ReactNode;
}) {
const tts = useSpeechOutput(chatMessages);
return <TtsContext.Provider value={tts}>{children}</TtsContext.Provider>;
}
export function useTts(): TtsContextValue | null {
return useContext(TtsContext);
}