react-native-rn-voicekit
v0.1.2
Published
Voice to text
Downloads
469
Readme
react-native-rn-voicekit
A lightweight React Native voice-to-text (speech recognition) library for iOS and Android, built with native APIs and TurboModules.
✨ Features
- 🎙️ Start/stop/cancel voice recognition
- 📡 Real-time partial results + final results
- ⚡ Works with both iOS (Speech API) and Android (SpeechRecognizer)
- 📦 Simple JS API (
start,stop,cancel,subscribe) - 🔄 Built with react-native-builder-bob
📦 Installation
npm install react-native-rn-voicekit
# or
yarn add react-native-rn-voicekitiOS
- Add permissions to your Info.plist:
<key>NSSpeechRecognitionUsageDescription</key>
<string>This app needs access to speech recognition</string>
<key>NSMicrophoneUsageDescription</key>
<string>This app needs access to the microphone</string>- Install pods:
cd ios && pod installAndroid
Add microphone permission to your AndroidManifest.xml:
<uses-permission android:name="android.permission.RECORD_AUDIO" />🚀 Usage
import React, { useEffect, useState } from 'react';
import { SafeAreaView, Button, Text, ScrollView } from 'react-native';
import { start, stop, cancel, subscribe } from 'react-native-rn-voicekit';
export default function App() {
const [logs, setLogs] = useState<string[]>([]);
const addLog = (msg: string) => setLogs((prev) => [msg, ...prev]);
useEffect(() => {
const unsub = subscribe({
onSpeechStart: () => addLog('🎤 Speech started'),
onSpeechEnd: () => addLog('🛑 Speech ended'),
onSpeechError: (e) => addLog(`❌ Error: ${e.code} - ${e.message}`),
onSpeechResults: (v) => addLog(`✅ Final: ${v.join(' ')}`),
onSpeechPartialResults: (v) => addLog(`⌛ Partial: ${v.join(' ')}`),
});
return unsub;
}, []);
return (
<SafeAreaView style={{ flex: 1, padding: 20 }}>
<Button title="Start" onPress={() => start('en-US')} />
<Button title="Stop" onPress={stop} />
<Button title="Cancel" onPress={cancel} />
<ScrollView>
{logs.map((l, i) => (
<Text key={i}>{l}</Text>
))}
</ScrollView>
</SafeAreaView>
);
}📡 API
Functions
| Function | Description |
|-------------------|-------------------------------------------------|
| start(locale?) | Start listening (default locale: en-US) |
| stop() | Stop recognition and finalize results |
| cancel() | Cancel recognition without results |
| isAvailable() | Returns whether speech recognition is supported |
Events
Subscribe with subscribe(handlers):
| Event | Payload |
|---------------------------|----------------------------------------|
| onSpeechStart | void |
| onSpeechEnd | void |
| onSpeechError | { code: string; message: string } |
| onSpeechResults | { value: string[] } (final results) |
| onSpeechPartialResults | { value: string[] } (partial text) |
🤝 Contributing
Contributions welcome!
See CONTRIBUTING.md and CODE_OF_CONDUCT.md.
📜 License
MIT © Ayo Ayeni
