Skip to Content
Hooks

useSpeechRecognition

Live speech-to-text for React Native with the same API as the web hook, backed by the optional expo-speech-recognition module.

iOSAndroid

Installation

pnpm dlx @kivacore/ui-cli add @kivacore/rn-hooks-use-speech-recognition
Required Packages(1 package)
pnpm add expo-speech-recognition

expo-speech-recognition is an optional peer with a config plugin, so it needs a development build — see Speech Recognition for the setup. The module is loaded lazily with a guarded require(): in Expo Go (or when it isn't installed) isSupported is false, start / stop are no-ops, and KivaAgentChatInputMicButton hides itself. start() asks for microphone + speech permissions first; a denial sets error to 'not-allowed'.

Usage

import {
  KivaAgentChatInput,
  KivaAgentChatInputDefaultBody,
  KivaAgentChatInputMicButton,
  useKivaAgentMicTranscription
} from '@/components/kiva-native/kiva-agent';
import { useSpeechRecognition } from '@/hooks/kiva-native/use-speech-recognition';

function MicTool() {
  const mic = useKivaAgentMicTranscription();
  const speech = useSpeechRecognition({ lang: 'en-US', ...mic.speechHandlers });

  return <KivaAgentChatInputMicButton isRecording={speech.isRecording} isSupported={speech.isSupported} onToggle={speech.toggle} />;
}

<KivaAgentChatInput>
  <KivaAgentChatInputDefaultBody extraTools={<MicTool />} />
</KivaAgentChatInput>

KivaAgentChatInputMic is the same thing pre-wired.

API Reference

UseSpeechRecognitionArgs

OptionTypeDefaultDescription
langstringdevice localeBCP-47 tag (en-US, tr-TR)
continuousbooleantrueKeep listening after each result
interimResultsbooleantrueStream partial transcripts
onTranscript(chunks: { final: string; interim: string }) => void-Every result: cumulative final text + pending interim
onStart() => void-Session started
onEnd() => void-Session ended (stop, error or timeout)

UseSpeechRecognitionResult

FieldTypeDescription
isSupportedbooleanModule installed, linked and recognition available
isRecordingbooleanSession active
transcriptstringCumulative final transcript of the session
start / stop / toggle() => voidControl the session
reset() => voidClear the transcript
errorstring | nullLast native error code ('not-allowed', 'no-speech', …)

isSpeechRecognitionAvailable() is exported as a plain function for non-hook checks.

On this page