File size: 11,833 Bytes
be54278 | 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 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 | import { useVoxtral } from "./VoxtralContext";
import { THEME } from "../constants";
import {
AppGridBackground,
ErrorMessageBox,
MicrophoneIcon,
VoiceMeter,
} from "./SharedUI";
export const RunningPage = () => {
const {
status,
transcript,
startRecording,
stopRecording,
resetSession,
error,
} = useVoxtral();
const isRecording = status === "recording";
const transcriptText = transcript.trimStart();
const hasTranscript = transcriptText.length > 0;
const statusConfig = error
? {
bg: `${THEME.errorRed}0D`,
border: THEME.errorRed,
dot: THEME.errorRed,
label: "SYSTEM ERROR",
}
: isRecording
? {
bg: `${THEME.mistralOrange}0D`,
border: THEME.mistralOrange,
dot: THEME.mistralOrange,
label: "LIVE TRANSCRIPTION",
}
: {
bg: "transparent",
border: THEME.beigeDark,
dot: "#9CA3AF",
label: "STANDBY",
};
const controlLabel = isRecording ? "Stop" : "Start";
const helperText = error
? "Resolve the error and start again."
: isRecording
? "Listening live. Tap stop when you're done."
: "Tap the microphone to begin.";
return (
<AppGridBackground
className="min-h-screen flex items-center justify-center px-4 py-4 md:px-6 md:py-6"
style={{ color: THEME.textBlack }}
>
<div
className="w-full max-w-4xl rounded-[2rem] border bg-white/84 p-4 shadow-2xl backdrop-blur-sm md:p-5"
style={{ borderColor: error ? `${THEME.errorRed}55` : THEME.beigeDark }}
>
<section
className="flex min-h-[min(78vh,720px)] flex-col overflow-hidden rounded-[1.6rem] border bg-white/90"
style={{
borderColor: error ? `${THEME.errorRed}55` : THEME.beigeDark,
}}
>
<div
className="flex min-h-[76px] items-center justify-between border-b px-5 py-4"
style={{ borderColor: THEME.beigeDark }}
>
<div className="flex min-h-[40px] flex-col justify-center">
<p className="text-xs font-mono uppercase tracking-[0.3em] text-gray-500">
Voxtral Realtime
</p>
<h1 className="mt-1 text-xl font-semibold leading-none tracking-tight md:text-2xl">
Real-time transcription
</h1>
</div>
<div
className="flex h-8 items-center gap-2 rounded-full border px-3 py-1.5"
style={{
backgroundColor: statusConfig.bg,
borderColor: `${statusConfig.border}4D`,
}}
>
<span className="relative flex h-2.5 w-2.5">
{isRecording && (
<span
className="absolute inline-flex h-full w-full animate-ping rounded-full opacity-75"
style={{ backgroundColor: statusConfig.dot }}
/>
)}
<span
className="relative inline-flex h-2.5 w-2.5 rounded-full"
style={{ backgroundColor: statusConfig.dot }}
/>
</span>
<span
className="text-[10px] font-bold tracking-[0.2em]"
style={{ color: statusConfig.dot }}
>
{statusConfig.label}
</span>
</div>
</div>
<div className="flex flex-1 flex-col">
{error && (
<ErrorMessageBox
className="mx-5 mt-5 rounded-2xl border px-4 py-3"
message={error}
/>
)}
<div className="relative flex-1 overflow-hidden">
<div
className="absolute inset-0 opacity-[0.03] pointer-events-none"
style={{
backgroundImage: `linear-gradient(${THEME.black} 1px, transparent 1px), linear-gradient(90deg, ${THEME.black} 1px, transparent 1px)`,
backgroundSize: "20px 20px",
}}
/>
<div
className={`relative z-10 flex h-full flex-col px-5 py-5 md:px-6 md:py-6 ${isRecording ? "justify-start" : "justify-center"}`}
>
{!isRecording && !transcriptText ? (
<div className="mx-auto flex max-w-md flex-col items-center text-center">
<div className="relative">
<button
onClick={startRecording}
className="relative flex h-28 w-28 cursor-pointer items-center justify-center rounded-full border-none outline-none transition-all duration-300 hover:-translate-y-1 active:scale-95 md:h-32 md:w-32"
style={{
background: `linear-gradient(135deg, ${THEME.mistralOrange}, ${THEME.mistralOrangeLight})`,
boxShadow: `0 22px 44px ${THEME.mistralOrange}30`,
}}
aria-label={controlLabel}
>
<span
className="absolute inset-0 rounded-full opacity-25"
style={{
boxShadow: `0 0 0 14px ${THEME.mistralOrange}20`,
}}
/>
<MicrophoneIcon className="relative h-12 w-12 text-white" />
</button>
</div>
<div className="mt-8 space-y-3">
<p className="text-2xl font-semibold tracking-tight md:text-3xl">
Start transcription
</p>
<p className="text-sm text-gray-500 md:text-base">
{helperText}
</p>
</div>
<div
className="mt-8 w-full rounded-2xl border px-4 py-4"
style={{
backgroundColor: `${THEME.beigeLight}CC`,
borderColor: THEME.beigeDark,
}}
>
<VoiceMeter color={THEME.beigeDark} />
<p className="mt-3 text-xs font-mono uppercase tracking-[0.18em] text-gray-500">
Ready when you are
</p>
</div>
</div>
) : (
<>
<div className="flex items-center justify-between gap-3 pb-4">
<div className="flex items-center space-x-2">
<svg
className="w-4 h-4 text-gray-400"
fill="none"
viewBox="0 0 24 24"
stroke="currentColor"
>
<path
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth={2}
d="M8 9l3 3-3 3m5 0h3M5 20h14a2 2 0 002-2V6a2 2 0 00-2-2H5a2 2 0 00-2 2v12a2 2 0 002 2z"
/>
</svg>
<span className="text-xs font-bold text-gray-500 uppercase tracking-widest">
Transcript
</span>
</div>
<div
className="rounded-full px-3 py-1 text-[10px] font-bold uppercase tracking-[0.2em]"
style={{
backgroundColor: `${THEME.beigeLight}`,
color: THEME.textBlack,
}}
>
{transcriptText ? "Live output" : "Waiting for speech"}
</div>
</div>
<div className="history-scroll flex-1 overflow-y-auto">
{transcriptText ? (
<p
className="max-w-none text-lg font-mono leading-relaxed break-words whitespace-pre-wrap md:text-[1.4rem]"
style={{ color: THEME.textBlack }}
>
<span className="mr-1">{transcriptText}</span>
{isRecording && (
<span
className="inline-block w-2.5 h-5 align-middle cursor-blink ml-1"
style={{ backgroundColor: THEME.mistralOrange }}
/>
)}
</p>
) : (
<div className="flex h-full flex-col items-center justify-center space-y-4 py-12 text-center opacity-70">
<VoiceMeter color={THEME.mistralOrange} active />
<div className="space-y-1">
<p className="text-sm font-mono italic text-gray-500">
Listening for speech...
</p>
<p className="text-xs font-mono uppercase tracking-[0.18em] text-gray-400">
Local processing · realtime stream
</p>
</div>
</div>
)}
</div>
</>
)}
</div>
</div>
{(isRecording || hasTranscript) && (
<div className="flex justify-center gap-3 px-5 pb-5 pt-2">
{!isRecording && hasTranscript && (
<button
onClick={resetSession}
className="rounded-full border px-4 py-2 text-sm font-semibold text-gray-600 transition-all duration-300 hover:-translate-y-0.5 hover:text-black active:scale-95"
style={{
borderColor: THEME.beigeDark,
backgroundColor: `${THEME.beigeLight}`,
}}
>
Reset
</button>
)}
{isRecording && (
<button
onClick={stopRecording}
className="group inline-flex items-center gap-3 rounded-full px-4 py-2 text-sm font-semibold text-white transition-all duration-300 hover:-translate-y-0.5 active:scale-95"
style={{
background: `linear-gradient(135deg, ${THEME.mistralOrangeDark}, ${THEME.mistralOrange})`,
boxShadow: `0 12px 28px ${THEME.mistralOrange}30`,
}}
>
<span className="flex h-8 w-8 items-center justify-center rounded-full bg-white/18">
<svg
className="h-4 w-4"
fill="currentColor"
viewBox="0 0 24 24"
>
<rect x="6" y="6" width="12" height="12" rx="2" />
</svg>
</span>
Stop
</button>
)}
</div>
)}
</div>
<div
className="flex items-center justify-between border-t bg-white/70 px-5 py-3 text-[10px] font-mono text-gray-400"
style={{ borderColor: THEME.beigeDark }}
>
<span>{isRecording ? "stream: live" : "stream: ready"}</span>
<span>{isRecording ? "mic: active" : "mic: idle"}</span>
</div>
</section>
</div>
</AppGridBackground>
);
};
|