@gmessier/nitro-speech 0.0.6 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +90 -9
  2. package/package.json +21 -5
package/README.md CHANGED
@@ -1,11 +1,27 @@
1
1
  # nitro-speech
2
2
 
3
+ [![npm version](https://img.shields.io/npm/v/@gmessier/nitro-speech.svg)](https://www.npmjs.com/package/@gmessier/nitro-speech)
4
+ [![license](https://img.shields.io/npm/l/@gmessier/nitro-speech.svg)](https://github.com/NotGeorgeMessier/nitro-speech/blob/main/LICENSE)
5
+ [![npm downloads](https://img.shields.io/npm/dm/@gmessier/nitro-speech.svg)](https://www.npmjs.com/package/@gmessier/nitro-speech)
6
+
3
7
  > **⚠️ Work in Progress**
4
8
  >
5
- > This library is under active development.
9
+ > This library is under active development. (Last version is stable)
6
10
 
7
11
  Speech recognition for React Native, powered by [Nitro Modules](https://github.com/mrousavy/nitro).
8
12
 
13
+ ## Table of Contents
14
+
15
+ - [Installation](#installation)
16
+ - [Permissions](#permissions)
17
+ - [Features](#features)
18
+ - [Usage](#usage)
19
+ - [Recommended: useRecognizer Hook](#recommended-userecognizer-hook)
20
+ - [Alternative: Static Recognizer](#alternative-static-recognizer-not-safe)
21
+ - [API Reference](#api-reference)
22
+ - [Requirements](#requirements)
23
+ - [Troubleshooting](#troubleshooting)
24
+
9
25
  ## Installation
10
26
 
11
27
  ```bash
@@ -16,6 +32,16 @@ yarn add @gmessier/nitro-speech react-native-nitro-modules
16
32
  bun add @gmessier/nitro-speech react-native-nitro-modules
17
33
  ```
18
34
 
35
+ ### Expo
36
+
37
+ This library works with Expo. You need to run prebuild to generate native code:
38
+
39
+ ```bash
40
+ npx expo prebuild
41
+ ```
42
+
43
+ **Note**: Make sure New Arch is enabled in your Expo configuration before running prebuild.
44
+
19
45
  ### iOS
20
46
 
21
47
  ```bash
@@ -54,17 +80,17 @@ Both permissions are required for speech recognition to work on iOS.
54
80
  | Feature | Description | iOS | Android |
55
81
  |---------|-------------|-----|---------|
56
82
  | **Real-time transcription** | Get partial results as the user speaks, enabling live UI updates | ✅ | ✅ |
57
- | **Auto-stop on silence** | Automatically stops recognition after configurable inactivity period (default: 8s) | ✅ (flag) | ✅ (flag) |
83
+ | **Auto-stop on silence** | Automatically stops recognition after configurable inactivity period (default: 8s) | ✅ | ✅ |
58
84
  | **Auto-finish progress** | Progress callbacks showing countdown until auto-stop | ✅ | ❌ *(TODO)* |
59
- | **Locale support** | Configure speech recognizer for different languages | ✅ (flag) | ✅ (flag) |
85
+ | **Locale support** | Configure speech recognizer for different languages | ✅ | ✅ |
60
86
  | **Background handling** | Auto-stop when app loses focus/goes to background | ✅ | Not Safe *(TODO)* |
61
- | **Contextual strings** | Domain-specific vocabulary for improved accuracy | ✅ (flag) | ✅ (flag) |
62
- | **Repeating word filter** | Removes consecutive duplicate words from artifacts | ✅ (flag) | ✅ (flag) |
87
+ | **Contextual strings** | Domain-specific vocabulary for improved accuracy | ✅ | ✅ |
88
+ | **Repeating word filter** | Removes consecutive duplicate words from artifacts | ✅ | ✅ |
63
89
  | **Permission handling** | Dedicated `onPermissionDenied` callback | ✅ | ✅ |
64
- | **Automatic punctuation** | Adds punctuation to transcription (iOS 16+) | ✅ (flag) | Auto |
65
- | **Language model selection** | Choose between web search vs free-form models | | ✅ (flag) |
66
- | **Offensive word masking** | Control whether offensive words are masked | Auto | ✅ (flag) |
67
- | **Formatting quality** | Prefer quality vs speed in formatting | | ✅ (flag) |
90
+ | **Automatic punctuation** | Adds punctuation to transcription (iOS 16+) | ✅ | Auto |
91
+ | **Language model selection** | Choose between web search vs free-form models | Auto | ✅ |
92
+ | **Offensive word masking** | Control whether offensive words are masked | Auto | ✅ |
93
+ | **Formatting quality** | Prefer quality vs speed in formatting | Auto | ✅ |
68
94
 
69
95
  ## Usage
70
96
 
@@ -182,6 +208,57 @@ The `Recognizer.dispose()` method is **NOT SAFE** and should rarely be used. Hyb
182
208
 
183
209
  **See:** [Nitro dispose() documentation](https://nitro.margelo.com/docs/hybrid-objects#dispose)
184
210
 
211
+ ## API Reference
212
+
213
+ ### `useRecognizer(callbacks)`
214
+
215
+ A React hook that provides lifecycle-aware access to the speech recognizer.
216
+
217
+ #### Parameters
218
+
219
+ - `callbacks` (object):
220
+ - `onReadyForSpeech?: () => void` - Called when speech recognition starts
221
+ - `onResult?: (textBatches: string[]) => void` - Called every time when partial result is ready (array of text batches)
222
+ - `onRecordingStopped?: () => void` - Called when recording stops
223
+ - `onAutoFinishProgress?: (timeLeftMs: number) => void` - Called each second during auto-finish countdown
224
+ - `onError?: (message: string) => void` - Called when an error occurs
225
+ - `onPermissionDenied?: () => void` - Called if microphone permission is denied
226
+
227
+ #### Returns
228
+
229
+ - `startListening(params: SpeechToTextParams)` - Start speech recognition with the given parameters
230
+ - `stopListening()` - Stop speech recognition
231
+ - `addAutoFinishTime(additionalTimeMs?: number)` - Add time to the auto-finish timer (or reset to original if no parameter)
232
+ - `updateAutoFinishTime(newTimeMs: number, withRefresh?: boolean)` - Update the auto-finish timer
233
+
234
+ ### `SpeechToTextParams`
235
+
236
+ Configuration object for speech recognition.
237
+
238
+ #### Common Parameters
239
+
240
+ - `locale?: string` - Language locale (default: `"en-US"`)
241
+ - `autoFinishRecognitionMs?: number` - Auto-stop timeout in milliseconds (default: `8000`)
242
+ - `contextualStrings?: string[]` - Array of domain-specific words for better recognition
243
+ - `disableRepeatingFilter?: boolean` - Disable filter that removes consecutive duplicate words (default: `false`)
244
+
245
+ #### iOS-Specific Parameters
246
+
247
+ - `iosAddPunctuation?: boolean` - Add punctuation to results (iOS 16+, default: `true`)
248
+
249
+ #### Android-Specific Parameters
250
+
251
+ - `androidMaskOffensiveWords?: boolean` - Mask offensive words (Android 13+, default: `false`)
252
+ - `androidFormattingPreferQuality?: boolean` - Prefer quality over latency (Android 13+, default: `false`)
253
+ - `androidUseWebSearchModel?: boolean` - Use web search language model instead of free-form (default: `false`)
254
+ - `androidDisableBatchHandling?: boolean` - Disable default batch handling (may add many empty batches, default: `false`)
255
+
256
+ ## Requirements
257
+
258
+ - React Native >= 0.76
259
+ - New Arch Only
260
+ - react-native-nitro-modules
261
+
185
262
  ## Troubleshooting
186
263
 
187
264
  ### Android Gradle sync issues
@@ -192,6 +269,10 @@ If you're having issues with Android Gradle sync, try running the prebuild for t
192
269
  cd android && ./gradlew :react-native-nitro-modules:preBuild
193
270
  ```
194
271
 
272
+ ## License
273
+
274
+ MIT
275
+
195
276
  ## TODO
196
277
 
197
278
  - [ ] (Android) Timer till the auto finish is called
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@gmessier/nitro-speech",
3
- "version": "0.0.6",
4
- "description": "nitro-speech",
3
+ "version": "0.1.0",
4
+ "description": "React Native Speech Recognition Library powered by Nitro Modules",
5
5
  "main": "./lib/commonjs/index.js",
6
6
  "module": "./lib/module/index.js",
7
7
  "types": "./lib/typescript/index.d.ts",
@@ -40,15 +40,31 @@
40
40
  "react-native",
41
41
  "speech",
42
42
  "recognition",
43
- "nitro"
43
+ "speech-recognition",
44
+ "speech-to-text",
45
+ "stt",
46
+ "voice",
47
+ "voice-recognition",
48
+ "transcription",
49
+ "audio",
50
+ "microphone",
51
+ "nitro",
52
+ "nitro-modules"
44
53
  ],
45
54
  "repository": {
46
55
  "type": "git",
47
- "url": "git+https://github.com/NotGeorgeMessier/nitro-speech"
56
+ "url": "git+https://github.com/NotGeorgeMessier/nitro-speech.git"
57
+ },
58
+ "bugs": {
59
+ "url": "https://github.com/NotGeorgeMessier/nitro-speech/issues"
48
60
  },
49
61
  "author": "George Messier",
50
- "homepage": "https://github.com/NotGeorgeMessier/nitro-speech",
62
+ "homepage": "https://github.com/NotGeorgeMessier/nitro-speech#readme",
51
63
  "license": "MIT",
64
+ "engines": {
65
+ "node": ">=14"
66
+ },
67
+ "sideEffects": false,
52
68
  "publishConfig": {
53
69
  "registry": "https://registry.npmjs.org/"
54
70
  },