Компоненты
- Accordion
- Alert
- Alert Dialog
- Autocomplete
- Avatar
- Badge
- Breadcrumb
- Button
- Calendar
- Card
- Checkbox
- Checkbox Group
- Collapsible
- Combobox
- Command
- Date Picker
- Dialog
- DrawerNew
- Empty
- Field
- Fieldset
- Form
- Frame
- Group
- Input
- Input Group
- Kbd
- Label
- Menu
- Meter
- Number Field
- OTP FieldNew
- Pagination
- Popover
- Preview Card
- Progress
- Radio Group
- Scroll Area
- Select
- Separator
- Sheet
- Skeleton
- Slider
- Spinner
- Switch
- Table
- Tabs
- Textarea
- Toast
- Toggle
- Toggle Group
- Toolbar
- Tooltip
AI Components
- AI Components
- Chat Conversation
- Chat Message
- Chat Response
- Chat Suggestion
- Chat Prompt Input
- Chat Attachments
- Chat Code Block
- Chat Image
- Chat Inline Citation
- Chat Reasoning
- Chat Sources
- Chat Actions
- Chat Context
- Chat Loader
- Chat Task
- Chat Tool
- Chat Web Preview
- Chat Snippet
- Chat Terminal
- Chat Stack Trace
- Chat Test Results
- Chat File Tree
- Chat Environment Variables
- Chat Audio Player
- Chat Transcription
- Chat Speech Input
- Chat Mic Selector
- Chat Voice Selector
- Chat Agent
- Chat Persona
- Chat Connection
- Chat Queue
- Chat Checkpoint
- Chat Confirmation
- Chat Artifact
- Chat JSX Preview
- Chat Schema Display
- Chat Package Info
- Chat Commit
- Chat Plan
- Chat Panel
- Chat Open In Chat
- Chat Sandbox
- Chat Model Selector
- Chat Canvas
- Chat Node
- Chat Edge
Resources
Chat Speech Input
Push-to-talk кнопка с Web SpeechRecognition + MediaRecorder fallback.
Status: idle
Press the mic and start speaking. (Web Speech API works in Chrome / Edge; Safari and Firefox use the MediaRecorder fallback — wire up `onAudioRecorded`.)
"use client";
import { useState } from "react";
import { Button } from "@/components/ui/button";
import {
ChatSpeechInput,
type ChatSpeechInputStatus,
} from "@/components/ui/chat-speech-input";
export default function Particle() {
const [text, setText] = useState("");
const [status, setStatus] = useState<ChatSpeechInputStatus>("idle");
return (
<div className="flex w-full max-w-md flex-col gap-3 rounded-lg border bg-card p-3">
<div className="flex items-center gap-2">
<Button disabled size="icon" variant="outline">
<span className="sr-only">Other tool</span>
</Button>
<ChatSpeechInput
onStatusChange={setStatus}
onTranscriptionChange={(value) => setText(value)}
/>
<p className="text-muted-foreground text-xs">
Status: <span className="font-medium text-foreground">{status}</span>
</p>
</div>
<p className="min-h-[1.5rem] text-sm leading-relaxed">
{text || (
<span className="text-muted-foreground">
Press the mic and start speaking. (Web Speech API works in Chrome /
Edge; Safari and Firefox use the MediaRecorder fallback — wire up
`onAudioRecorded`.)
</span>
)}
</p>
</div>
);
}
Installation
pnpm dlx shadcn@latest add @jenny/chat-speech-input
Usage
import { ChatSpeechInput } from "@/components/ui/chat-speech-input";
<ChatSpeechInput
lang="ru-RU"
onTranscriptionChange={(text, isFinal) => {
setDraft(text);
if (isFinal) sendMessage(text);
}}
onAudioRecorded={async (blob) => {
// Fallback для Firefox / Safari — отправляешь blob на свой STT endpoint
const response = await fetch("/api/stt", { method: "POST", body: blob });
const { text } = await response.json();
return text;
}}
/>Стратегия
| Браузер | Mode | Что происходит |
|---|---|---|
| Chrome, Edge | speech-recognition | Web Speech API стримит interim и final transcripts в onTranscriptionChange. |
| Firefox, Safari | media-recorder | Записывает MediaRecorder, по stop отдаёт Blob в onAudioRecorded. Текст из вашего callback идёт в onTranscriptionChange как isFinal: true. |
| Без обоих API | unsupported | Кнопка отключена с иконкой <MicOff>. |
Статус доступен через data-state="idle"/"listening"/"processing"/"unsupported" для кастомных стилей, плюс callback onStatusChange.
Использование внутри prompt-input
<ChatPromptInputTools>
<ChatSpeechInput
onTranscriptionChange={(text, isFinal) => {
if (isFinal) textareaRef.current?.setValue(text);
}}
/>
</ChatPromptInputTools>