blob: c4692ff12a20d43bd505299fc9a59b31c452f8de (
plain) (
blame)
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
|
import { useState, useCallback } from "react";
import { Masthead } from "../components/Masthead";
import { useSpeakWebSocket } from "../hooks/useSpeakWebSocket";
export default function SpeakPage() {
const [text, setText] = useState("");
const tts = useSpeakWebSocket();
const handleSpeak = useCallback(() => {
if (!text.trim()) return;
tts.speak(text);
}, [text, tts]);
const handleCancel = useCallback(() => {
tts.cancel();
}, [tts]);
const handleKeyDown = useCallback(
(e: React.KeyboardEvent<HTMLTextAreaElement>) => {
// Ctrl/Cmd + Enter to speak
if ((e.ctrlKey || e.metaKey) && e.key === "Enter") {
e.preventDefault();
handleSpeak();
}
},
[handleSpeak]
);
const statusLabel = (() => {
switch (tts.status) {
case "disconnected":
return "DISCONNECTED";
case "connecting":
return "CONNECTING...";
case "connected":
return "CONNECTED";
case "loading_model":
return "LOADING TTS MODEL...";
case "speaking":
return "SPEAKING";
case "error":
return "ERROR";
default:
return "IDLE";
}
})();
const statusColor = (() => {
switch (tts.status) {
case "connected":
case "speaking":
return "border-[#3f6fb3] text-[#75aafc]";
case "error":
return "border-red-400/50 text-red-400";
default:
return "border-[rgba(117,170,252,0.25)] text-[#9bc3ff]";
}
})();
const dotColor = (() => {
switch (tts.status) {
case "connected":
case "speaking":
return "bg-[#75aafc]";
case "error":
return "bg-red-400";
default:
return "bg-[#3f6fb3]";
}
})();
return (
<div className="relative z-10 h-screen flex flex-col overflow-hidden">
<Masthead showTicker={false} showNav />
<main className="flex-1 flex flex-col items-center justify-center p-4 md:p-8 gap-6 min-h-0 overflow-auto">
{/* Text input area */}
<div className="w-full max-w-2xl">
<textarea
value={text}
onChange={(e) => setText(e.target.value)}
onKeyDown={handleKeyDown}
placeholder="Enter text to speak..."
disabled={tts.isSpeaking || tts.isModelLoading}
className="w-full h-48 p-4 font-mono text-sm text-[#dbe7ff] bg-[#0d1b2d] border border-[#0f3c78] focus:border-[#3f6fb3] focus:outline-none placeholder-[#3f6fb3] resize-none transition-colors disabled:opacity-50"
/>
<div className="mt-1 text-right font-mono text-xs text-[#3f6fb3]">
Ctrl+Enter to speak
</div>
</div>
{/* Controls row */}
<div className="w-full max-w-2xl flex items-center gap-4">
{/* Speak / Cancel button */}
{tts.isSpeaking || tts.isModelLoading ? (
<button
onClick={handleCancel}
className="px-6 py-2 font-mono text-sm text-red-400 bg-[#0d1b2d] border border-red-400/50 hover:border-red-400 transition-colors uppercase tracking-wide"
>
Cancel
</button>
) : (
<button
onClick={handleSpeak}
disabled={!text.trim()}
className="px-6 py-2 font-mono text-sm text-[#dbe7ff] bg-[#0d1b2d] border border-[#0f3c78] hover:border-[#3f6fb3] transition-colors uppercase tracking-wide disabled:opacity-50 disabled:cursor-not-allowed"
>
Speak
</button>
)}
{/* Status indicator */}
<div
className={`inline-flex items-center gap-1.5 px-2 py-1 border font-mono text-xs tracking-wide uppercase ${statusColor}`}
>
<span className={`w-1.5 h-1.5 rounded-full ${dotColor}`} />
{statusLabel}
</div>
</div>
{/* Loading bar (indeterminate) */}
{tts.isModelLoading && (
<div className="w-full max-w-2xl">
<div className="w-full h-1.5 bg-[#0f1c2f] overflow-hidden">
<div
className="h-full w-1/3 bg-[#75aafc]"
style={{
animation: "loading-slide 1.5s ease-in-out infinite",
}}
/>
</div>
<div className="mt-2 font-mono text-xs text-[#9bc3ff] text-center tracking-wide uppercase">
Loading TTS model... This may take a moment on first use.
</div>
</div>
)}
{/* Speaking animation bar */}
{tts.isSpeaking && (
<div className="w-full max-w-2xl">
<div className="w-full h-1.5 bg-[#0f1c2f] overflow-hidden">
<div
className="h-full w-full bg-[#75aafc] animate-pulse"
/>
</div>
</div>
)}
{/* Error display */}
{tts.error && (
<div className="w-full max-w-2xl font-mono text-xs text-red-400 text-center px-4 py-2 border border-red-400/50 bg-red-400/10">
{tts.error}
</div>
)}
</main>
</div>
);
}
|