import { createRoot } from "react-dom/client";
import { useState } from "react";
import { useVoiceInput } from "@cloudflare/voice/react";
import { Button, Surface, Text } from "@cloudflare/kumo";
import { ModeToggle, PoweredByAgents } from "@cloudflare/agents-ui";
import { ThemeProvider } from "@cloudflare/agents-ui/hooks";
import {
MicrophoneIcon,
MicrophoneSlashIcon,
StopIcon,
TrashIcon,
CopyIcon,
CheckIcon,
InfoIcon
} from "@phosphor-icons/react";
import "./styles.css";
function AudioLevelBar({ level }: { level: number }) {
return (
);
}
function App() {
const {
transcript,
interimTranscript,
isListening,
audioLevel,
isMuted,
error,
start,
stop,
toggleMute,
clear
} = useVoiceInput({ agent: "VoiceInputAgent" });
const [copied, setCopied] = useState(false);
const displayText =
transcript +
(interimTranscript ? (transcript ? " " : "") + interimTranscript : "");
const handleCopy = async () => {
if (!displayText) return;
await navigator.clipboard.writeText(displayText);
setCopied(true);
setTimeout(() => setCopied(false), 2000);
};
return (
{/* Header */}
{/* Main content */}
{/* Info card */}
Voice-to-Text Dictation
Click the microphone to start dictating. Your speech is
transcribed in real time using Workers AI and displayed in the
text area below. Uses the useVoiceInput hook from
@cloudflare/voice.
{/* Text area */}
{displayText ? (
{transcript}
{interimTranscript && (
{transcript ? " " : ""}
{interimTranscript}
)}
) : (
{isListening
? "Listening... start speaking"
: "Click the microphone button to start dictating"}
)}
{/* Audio level indicator */}
{isListening && (
)}
{/* Toolbar */}
{!isListening ? (
Dictate
) : (
<>
Stop
{isMuted ? (
) : (
)}
{isMuted ? "Unmute" : "Mute"}
>
)}
{copied ? (
) : (
)}
{copied ? "Copied" : "Copy"}
Clear
{/* Error display */}
{error && (
{error}
)}
{/* Footer */}
);
}
const root = document.getElementById("root")!;
createRoot(root).render(
);