speech-input
elevenlabs/speech-inputFreeComponent
shadcn/ui publishes no description for this item.
Install it
npx shadcn@latest add https://raw.githubusercontent.com/elevenlabs/ui/main/apps/www/public/r/speech-input.jsonSource
1"use client"23import * as React from "react"4import { cva, type VariantProps } from "class-variance-authority"5import { motion } from "framer-motion"6import { MicIcon, SquareIcon, XIcon } from "lucide-react"78import { cn } from "@/lib/utils"9import {10 useScribe,11 type AudioFormat,12 type CommitStrategy,13} from "@/registry/elevenlabs-ui/hooks/use-scribe"14import { Button } from "@/components/ui/button"15import { Skeleton } from "@/components/ui/skeleton"1617const buttonVariants = cva("!px-0", {18 variants: {19 size: {20 default: "h-9 w-9",21 sm: "h-8 w-8",22 lg: "h-10 w-10",23 },24 },25 defaultVariants: {26 size: "default",27 },28})2930type ButtonSize = VariantProps<typeof buttonVariants>["size"]3132export interface SpeechInputData {33 /** The current partial (in-progress) transcript */34 partialTranscript: string35 /** Array of all committed (finalized) transcripts */36 committedTranscripts: string[]37 /** Full transcript combining committed and partial transcripts */38 transcript: string39}4041interface SpeechInputContextValue {42 isConnected: boolean43 isConnecting: boolean44 transcript: string45 partialTranscript: string46 committedTranscripts: string[]47 error: string | null48 start: () => Promise<void>49 stop: () => void50 cancel: () => void51 size: ButtonSize52}5354const SpeechInputContext = React.createContext<SpeechInputContextValue | null>(55 null56)5758function useSpeechInput() {59 const context = React.useContext(SpeechInputContext)60 if (!context) {61 throw new Error(62 "SpeechInput compound components must be used within a SpeechInput"63 )64 }65 return context66}6768function buildTranscript({69 partialTranscript,70 committedTranscripts,71}: {72 partialTranscript: string73 committedTranscripts: string[]74}): string {75 const committed = committedTranscripts.join(" ").trim()76 const partial = partialTranscript.trim()7778 if (committed && partial) {79 return `${committed} ${partial}`80 }81 return committed || partial82}8384function buildData({85 partialTranscript,86 committedTranscripts,87}: {88 partialTranscript: string89 committedTranscripts: string[]90}): SpeechInputData {91 return {92 partialTranscript,93 committedTranscripts,94 transcript: buildTranscript({ partialTranscript, committedTranscripts }),95 }96}9798export interface SpeechInputProps {99 children: React.ReactNode100101 /**102 * Function that returns a token for authenticating with the speech service.103 * This should be an async function that fetches a token from your backend.104// … truncated
What it pulls in
npm packages
Other registry items
Files it writes
More from shadcn/ui
All 50 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| audio-playeraudio-player | shadcn/ui | Components | Free | 2 deps | |
| bar-visualizerbar-visualizer | shadcn/ui | Components | Free | no deps | |
| conversationconversation | shadcn/ui | Components | Free | 1 dep | |
| conversation-barconversation-bar | shadcn/ui | Components | Free | 1 dep | |
| live-waveformlive-waveform | shadcn/ui | Components | Free | no deps | |
| matrixmatrix | shadcn/ui | Components | Free | no deps | |
| messagemessage | shadcn/ui | Components | Free | 1 dep | |
| mic-selectormic-selector | shadcn/ui | Components | Free | no deps |
