@dev-amirzubair/react-native-voice

中文文档
1.0.4发布于 2025/11/25MITTypeScriptCommonJS近 30 天下载 4328

React Native Voice library for iOS and Android - Fork with New Architecture, Bridgeless mode, and React Native 0.76+ support

原始使用文档
文档目录21 节
  1. What's Different?
  2. Installation
  3. iOS Setup
  4. Android Setup
  5. Usage
  6. Full Example
  7. API
  8. Events
  9. Permissions
  10. Android
  11. iOS
  12. Platform Notes
  13. Android
  14. iOS
  15. Expo Support
  16. Troubleshooting
  17. Android: No speech recognition services found
  18. iOS: Speech recognition not working on simulator
  19. Events not firing
  20. Credits
  21. License

React Native Voice

npm

A speech-to-text library for React Native with New Architecture (Fabric/TurboModules) and Bridgeless mode support.

Note: This library is a fork of @react-native-voice/voice with custom fixes for React Native 0.76+ and the New Architecture. View source on GitHub

What's Different?

This fork includes the following improvements over the original library:

  • ✅ New Architecture Support - Works with Fabric and TurboModules
  • ✅ Bridgeless Mode - Full support for React Native's Bridgeless mode
  • ✅ React Native 0.76+ - Tested and working with the latest RN versions
  • ✅ Fixed Android Event Emission - Events properly reach JavaScript in new architecture
  • ✅ Fixed iOS TurboModule Registration - Proper fallback handling for iOS
  • ✅ Improved Locale Handling - Better support for Indo-Pak region languages
  • ✅ Clean TypeScript Types - Updated type definitions

Installation

yarn add @dev-amirzubair/react-native-voice

# or

npm install @dev-amirzubair/react-native-voice --save

iOS Setup

cd ios && pod install

Android Setup

No additional setup required - autolinking handles everything.

Usage

import Voice from '@dev-amirzubair/react-native-voice';

// Set up event handlers
Voice.onSpeechStart = () => console.log('Speech started');
Voice.onSpeechEnd = () => console.log('Speech ended');
Voice.onSpeechResults = (e) => console.log('Results:', e.value);
Voice.onSpeechPartialResults = (e) => console.log('Partial:', e.value);
Voice.onSpeechError = (e) => console.log('Error:', e.error);

// Start listening
await Voice.start('en-US');

// Stop listening
await Voice.stop();

// Clean up
await Voice.destroy();

Full Example

import React, { useEffect, useState, useCallback } from 'react';
import { View, Text, Button } from 'react-native';
import Voice from '@dev-amirzubair/react-native-voice';

function SpeechToText() {
  const [results, setResults] = useState([]);
  const [isListening, setIsListening] = useState(false);

  useEffect(() => {
    Voice.onSpeechStart = () => setIsListening(true);
    Voice.onSpeechEnd = () => setIsListening(false);
    Voice.onSpeechResults = (e) => setResults(e.value ?? []);
    Voice.onSpeechError = (e) => console.error(e.error);

    return () => {
      Voice.destroy().then(Voice.removeAllListeners);
    };
  }, []);

  const startListening = async () => {
    try {
      await Voice.start('en-US');
    } catch (e) {
      console.error(e);
    }
  };

  const stopListening = async () => {
    try {
      await Voice.stop();
    } catch (e) {
      console.error(e);
    }
  };

  return (
    <View>
      <Text>{isListening ? '🎤 Listening...' : 'Press Start'}</Text>
      <Text>{results.join(' ')}</Text>
      <Button title="Start" onPress={startListening} />
      <Button title="Stop" onPress={stopListening} />
    </View>
  );
}

API

MethodDescriptionPlatform
Voice.isAvailable()Check if speech recognition is availableAndroid, iOS
Voice.start(locale)Start listening for speechAndroid, iOS
Voice.stop()Stop listeningAndroid, iOS
Voice.cancel()Cancel speech recognitionAndroid, iOS
Voice.destroy()Destroy the recognizer instanceAndroid, iOS
Voice.removeAllListeners()Remove all event listenersAndroid, iOS
Voice.isRecognizing()Check if currently recognizingAndroid, iOS
Voice.getSpeechRecognitionServices()Get available speech enginesAndroid only

Events

EventDescriptionData
onSpeechStartSpeech recognition started{ error: false }
onSpeechEndSpeech recognition ended{ error: false }
onSpeechResultsFinal results received{ value: ['recognized text'] }
onSpeechPartialResultsPartial results (live){ value: ['partial text'] }
onSpeechErrorError occurred{ error: { code, message } }
onSpeechVolumeChangedVolume/pitch changed{ value: number }
onSpeechRecognizedSpeech was recognized{ isFinal: boolean }

Permissions

Android

Add to AndroidManifest.xml:

<uses-permission android:name="android.permission.RECORD_AUDIO" />

The library automatically requests permission when starting recognition.

iOS

Add to Info.plist:

<key>NSMicrophoneUsageDescription</key>
<string>This app needs microphone access for speech recognition</string>
<key>NSSpeechRecognitionUsageDescription</key>
<string>This app needs speech recognition access</string>

Platform Notes

Android

  • Auto-stops after user stops speaking
  • Requires Google Search app for speech recognition on most devices
  • Check available services with Voice.getSpeechRecognitionServices()

iOS

  • Does NOT auto-stop - call Voice.stop() when done
  • Speech recognition only works on physical devices (not simulators)
  • Requires iOS 10+

Expo Support

This library requires custom native code and cannot be used with Expo Go. Use a development build or eject.

Add to your app.json:

{
  "expo": {
    "plugins": ["@dev-amirzubair/react-native-voice"]
  }
}

Troubleshooting

Android: No speech recognition services found

Install the Google Search app from Play Store.

iOS: Speech recognition not working on simulator

Use a physical iOS device - simulators don't support speech recognition.

Events not firing

Make sure you set up event handlers before calling Voice.start().

Credits

This library is based on @react-native-voice/voice by the React Native Voice contributors. Special thanks to:

  • @wenkesj (original author)
  • @jamsch
  • All original contributors

License

MIT

版本与发布记录

@dev-amirzubair/react-native-voice 共发布 5 个版本,首次发布于 2025/11/25;过去 12 个月发布了 5 个版本。

版本发布日期距今
1.0.4latest2025/11/2511 个月前
1.0.32025/11/2511 个月前
1.0.22025/11/2511 个月前
1.0.12025/11/2511 个月前
1.0.02025/11/2511 个月前

关于 @dev-amirzubair/react-native-voice 的常见问题

@dev-amirzubair/react-native-voice 是什么?

React Native Voice library for iOS and Android - Fork with New Architecture, Bridgeless mode, and React Native 0.76+ support

如何安装 @dev-amirzubair/react-native-voice?

在项目目录运行 npm install @dev-amirzubair/react-native-voice,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:react-native(>=0.71.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@dev-amirzubair/react-native-voice 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@dev-amirzubair/react-native-voice 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@dev-amirzubair/react-native-voice 可以商用吗?

@dev-amirzubair/react-native-voice 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@dev-amirzubair/react-native-voice 的下载量有多少?

根据 npm 官方下载统计,@dev-amirzubair/react-native-voice 在 2026/10/12 – 2026/11/10 这 30 天内被下载 4,328 次,日均约 144 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@dev-amirzubair/react-native-voice 还在维护吗?

最新版本 1.0.4 发布于 2025/11/25(11 个月前);至今共发布 5 个版本,其中过去 12 个月发布了 5 个;首次发布于 2025/11/25。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。