Comprehensive guide for developers working with the VoiceTextInput component - a sophisticated React component that combines text input, voice dictation, and natural conversation capabilities.
Understanding the VoiceTextInput component's core functionality and use cases
VoiceTextInput is a React component that provides a unified interface for text and voice input. It supports three main interaction modes: standard text input, voice dictation, and natural conversation with AI.
useSpeechRecognition - Voice input handlinguseState/useEffect - React state managementuseCallback/useRef - Performance optimizationWaveformVisualizer - Real-time audio visualizationStaticWaveform - Static demo waveformsButton, Input, Tooltip - UI primitivesimport { VoiceTextInput } from "@/components/voice-text-input";
function ChatInterface() {
const handleSubmit = (message: string, inputType: "voice" | "text") => {
console.log(`Received ${inputType} message: ${message}`);
};
const handleConversation = (message: string, isUser: boolean) => {
console.log(`${isUser ? 'User' : 'AI'}: ${message}`);
};
return (
<VoiceTextInput
placeholder="Type a message or speak..."
onSubmit={handleSubmit}
onConversationMessage={handleConversation}
variant="chat"
showSendButton
enableNaturalConversation
/>
);
}