Voice Input

Talk instead of typing: tap or hold the mic, a live level meter and transcript, then send or cancel.

Installation

pnpm dlx shadcn@latest add checkfu/uicontext/voice-input

Usage

import { VoiceInput } from "./ui/uicontext/components/chat/VoiceInput.ts"
const Message = UiSchema.TaggedEnum({	SpokeVoice: { audio: Schema.instanceOf(Blob), seconds: Schema.Number },	FinishedVoice: { audio: Schema.instanceOf(Blob), seconds: Schema.Number },	CancelledVoice: {},})// transcribe `Spoke` for the live preview (pass it back as `transcript`), and `Finished` to sendexport const Dictation = (h: Html.H<typeof Message.Type>, heard: string) =>	VoiceInput(h, {		props: { transcript: heard },		onEmit: {			Started: () => undefined,			Spoke: ({ audio, seconds }) => Message.SpokeVoice({ audio, seconds }),			Finished: ({ audio, seconds }) => Message.FinishedVoice({ audio, seconds }),			Cancelled: () => Message.CancelledVoice(),		},	})

API reference

Props

VoiceInput props
NameTypeDescription
transcriptstringWhat the app has heard so far, from Spoke; shown while listening
disabledbooleanThe mic can't be used right now (a reply is streaming, no plan)

Events

VoiceInput events
EventPayloadDescription
Started{}The microphone is on
Spoke{ audio: instanceOf; seconds: number }The audio so far, about once a second, for a live transcript
Finished{ audio: instanceOf; seconds: number }The person sent the recording: transcribe it and send the text
Cancelled{}The person threw the recording away

Source