MCPcopy Index your code
hub / github.com/TanStack/ai / TTSUI

Function TTSUI

testing/e2e/src/components/TTSUI.tsx:22–99  ·  view source on GitHub ↗
({ provider, mode, testId, aimockPort }: TTSUIProps)

Source from the content-addressed store, hash-verified

20const ELEVENLABS_DEFAULT_VOICE = '21m00Tcm4TlvDq8ikWAM'
21
22export function TTSUI({ provider, mode, testId, aimockPort }: TTSUIProps) {
23 const [text, setText] = useState('')
24 const defaultVoice =
25 provider === 'elevenlabs' ? ELEVENLABS_DEFAULT_VOICE : undefined
26
27 const connectionOptions = () => {
28 const body = { provider, testId, aimockPort }
29
30 if (mode === 'sse') {
31 return { connection: fetchServerSentEvents('/api/tts'), body }
32 }
33 if (mode === 'http-stream') {
34 return { connection: fetchHttpStream('/api/tts/stream'), body }
35 }
36 return {
37 fetcher: async (input: { text: string; voice?: string }) => {
38 return generateSpeechFn({
39 data: {
40 text: input.text,
41 voice: input.voice,
42 provider,
43 aimockPort,
44 testId,
45 },
46 }) as Promise<TTSResult>
47 },
48 }
49 }
50
51 const { generate, result, isLoading, error, status } =
52 useGenerateSpeech(connectionOptions())
53
54 return (
55 <div className="p-4 space-y-4">
56 <div className="flex gap-2">
57 <input
58 data-testid="text-input"
59 type="text"
60 value={text}
61 onChange={(e) => setText(e.target.value)}
62 placeholder="Text to speak..."
63 className="flex-1 bg-gray-800 border border-gray-700 rounded px-3 py-2 text-sm"
64 />
65 <button
66 data-testid="generate-button"
67 onClick={() => generate({ text, voice: defaultVoice })}
68 disabled={!text.trim() || isLoading}
69 className="px-4 py-2 bg-orange-500 text-white rounded text-sm font-medium disabled:opacity-50"
70 >
71 Generate
72 </button>
73 </div>
74 <div data-testid="generation-status">
75 {status === 'idle'
76 ? 'idle'
77 : isLoading
78 ? 'loading'
79 : error

Callers

nothing calls this directly

Calls 3

useGenerateSpeechFunction · 0.90
connectionOptionsFunction · 0.70
generateFunction · 0.70

Tested by

no test coverage detected