@gmessier/nitro-speech 0.4.2 → 0.4.3

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.
package/README.md CHANGED
@@ -34,7 +34,7 @@
34
34
  - 👆 Configurable Haptic Feedback on start and finish
35
35
  - 🎚️ Speech-quality configurations:
36
36
  - Result is grouped by speech segments into Batches.
37
- - Param `iosPreset` - `shortForm` or `general` enables best transcriber for your situation
37
+ - Param `iosPreset` - enables best transcriber for your situation
38
38
  - Param `disableRepeatingFilter` - filters out consecutive duplicate words.
39
39
  - Param `androidDisableBatchHandling` - disables empty partial results
40
40
  - Many more, see `SpeechRecognitionConfig`
@@ -138,7 +138,7 @@ Both permissions are required for speech recognition to work on iOS.
138
138
  | **Language model selection** | Choose between web search vs free-form models | Auto | ✅ |
139
139
  | **Batch handling** | Filters out empty or repeated results | Auto | ✅ |
140
140
  | **Formatting quality** | Prefer quality vs speed in formatting | Auto | ✅ |
141
- | **Transcription preset** | `iosPreset` adapts for short phrases (`shortForm`) or `general` conversation | ✅ | Auto |
141
+ | **Transcription preset** | `iosPreset` adapts for different scenarios | ✅ | Auto |
142
142
  | **Automatic punctuation** | Adds punctuation to transcription (iOS 16+) | ✅ | Auto |
143
143
  | **Atypical speech hint** | Hint iOS that speech may include accent, lisp, or other confounding traits | ✅ | Auto |
144
144
  | **getSupportedLocalesIOS** | Supported locales for iOS (No available API for Android) | ✅ | X |
@@ -235,7 +235,7 @@ function MyComponent() {
235
235
  }
236
236
  ```
237
237
 
238
- On iOS 26+, the recognizer prefers the newer `SpeechTranscriber` path for general cases. Setting `iosPreset: 'shortForm'`, `iosAddPunctuation: false`, or `iosAtypicalSpeech: true` switches priority to `DictationTranscriber` that is better suited for short utterances or non-standard speech patterns.
238
+ On iOS 26+, the recognizer prefers the newer `SpeechTranscriber` path for general cases. Setting `iosPreset: 'shortForm' OR 'speed'`, `iosAddPunctuation: false`, or `iosAtypicalSpeech: true` switches priority to `DictationTranscriber` that is better suited for short utterances or non-standard speech patterns.
239
239
 
240
240
  ### With React Navigation (important)
241
241
 
@@ -20,7 +20,7 @@ final class AudioLevelTracker {
20
20
 
21
21
  var currentSample: AudioLevelSample?
22
22
 
23
- private let lg = Lg(prefix: "RecognizerEngine")
23
+ private let lg = Lg(prefix: "RecognizerEngine", disable: true)
24
24
 
25
25
  func reset() {
26
26
  smoothedLevel = 0
@@ -39,6 +39,7 @@ final class Coordinator {
39
39
  }
40
40
 
41
41
  if params?.iosPreset == IosPreset.shortform
42
+ || params?.iosPreset == IosPreset.speed
42
43
  || params?.iosAddPunctuation == false
43
44
  || params?.iosAtypicalSpeech == true {
44
45
  // DictationTranscriber priority
@@ -7,10 +7,13 @@ class HybridRecognizer: HybridRecognizerSpec {
7
7
  var onReadyForSpeech: (() -> Void)?
8
8
  var onRecordingStopped: (() -> Void)?
9
9
  var onResult: (([String]) -> Void)?
10
+ var onResultFallback: (([String]) -> Void)?
10
11
  var onAutoFinishProgress: ((Double) -> Void)?
12
+ var onAutoFinishProgressFallback: ((Double) -> Void)?
11
13
  var onError: ((String) -> Void)?
12
14
  var onPermissionDenied: (() -> Void)?
13
15
  var onVolumeChange: ((VolumeChangeEvent) -> Void)?
16
+ var onVolumeChangeFallback: ((VolumeChangeEvent) -> Void)?
14
17
 
15
18
  private let coordinator = Coordinator()
16
19
  private var paramsHash: String?
@@ -154,12 +157,29 @@ extension HybridRecognizer: RecognizerDelegate {
154
157
 
155
158
  func result(batches: [String]) {
156
159
  self.lg.log("[onResult] \(batches)")
157
- self.onResult?(batches)
160
+ if onResult != nil {
161
+ onResultFallback = onResult
162
+ }
163
+
164
+ if (onResultFallback == nil) {
165
+ self.lg.log("onResultFallback -> nil")
166
+ }
167
+
168
+ onResultFallback?(batches)
158
169
  }
159
170
 
160
171
  func autoFinishProgress(timeLeftMs: Double) {
161
172
  self.lg.log("[onAutoFinishProgress] \(timeLeftMs)ms")
162
- self.onAutoFinishProgress?(timeLeftMs)
173
+
174
+ if onAutoFinishProgress != nil {
175
+ onAutoFinishProgressFallback = onAutoFinishProgress
176
+ }
177
+
178
+ if (onAutoFinishProgressFallback == nil) {
179
+ self.lg.log("onAutoFinishProgressFallback -> nil")
180
+ }
181
+
182
+ onAutoFinishProgressFallback?(timeLeftMs)
163
183
  }
164
184
 
165
185
  func error(message: String) {
@@ -174,7 +194,15 @@ extension HybridRecognizer: RecognizerDelegate {
174
194
 
175
195
  func volumeChange(event: VolumeChangeEvent) {
176
196
  // self.lg.log("[onVolumeChange] \(event.rawVolume)")
177
- self.onVolumeChange?(event)
197
+ if onVolumeChange != nil {
198
+ onVolumeChangeFallback = onVolumeChange
199
+ }
200
+
201
+ if (onVolumeChangeFallback == nil) {
202
+ self.lg.log("onVolumeChangeFallback -> nil")
203
+ }
204
+
205
+ onVolumeChangeFallback?(event)
178
206
  }
179
207
 
180
208
  func reselectEngine(forPrewarm: Bool) {
@@ -5,7 +5,7 @@ final class AutoStopper {
5
5
  private static let defaultProgressIntervalMs = 1000.0
6
6
  private static let minProgressIntervalMs = 50.0
7
7
 
8
- private let lg = Lg(prefix: "AutoStopper", disable: false)
8
+ private let lg = Lg(prefix: "AutoStopper", disable: true)
9
9
 
10
10
  private let queue = DispatchQueue(label: "com.margelo.nitrospeech.autostopper")
11
11
 
@@ -44,7 +44,8 @@ enum Utils {
44
44
  }
45
45
  let preset = switch params.iosPreset {
46
46
  case nil: "n"
47
- case .shortform: "s"
47
+ // Both presets prioritize Dictation
48
+ case .shortform, .speed: "s"
48
49
  case .general: "g"
49
50
  }
50
51
  let atypicalSpeech = switch params.iosAtypicalSpeech {
@@ -22,7 +22,7 @@ interface ParamsAndroid {
22
22
  */
23
23
  androidDisableBatchHandling?: boolean;
24
24
  }
25
- type IosPreset = 'shortform' | 'general';
25
+ type IosPreset = 'shortform' | 'general' | 'speed';
26
26
  interface ParamsIOS {
27
27
  /**
28
28
  * Add punctuation to speech recognition results
@@ -33,9 +33,11 @@ interface ParamsIOS {
33
33
  */
34
34
  iosAddPunctuation?: boolean;
35
35
  /**
36
- * `"shortForm"` - for a short phrase or sentence, also disables punctuation
36
+ * `"shortForm"` - For a short phrase or sentence, also disables punctuation
37
37
  *
38
- * `"general"` - for longer speeches, more accurate but delayed response
38
+ * `"speed"` - Gives priority to speed over accuracy
39
+ *
40
+ * `"general"` - For longer speeches, more accurate but delayed response
39
41
  *
40
42
  * @since iOS 26.0+
41
43
  *
@@ -48,6 +48,9 @@ namespace margelo::nitro::nitrospeech {
48
48
  case IosPreset::GENERAL:
49
49
  static const auto fieldGENERAL = clazz->getStaticField<JIosPreset>("GENERAL");
50
50
  return clazz->getStaticFieldValue(fieldGENERAL);
51
+ case IosPreset::SPEED:
52
+ static const auto fieldSPEED = clazz->getStaticField<JIosPreset>("SPEED");
53
+ return clazz->getStaticFieldValue(fieldSPEED);
51
54
  default:
52
55
  std::string stringValue = std::to_string(static_cast<int>(value));
53
56
  throw std::invalid_argument("Invalid enum value (" + stringValue + "!");
@@ -17,7 +17,8 @@ import com.facebook.proguard.annotations.DoNotStrip
17
17
  @Keep
18
18
  enum class IosPreset(@DoNotStrip @Keep val value: Int) {
19
19
  SHORTFORM(0),
20
- GENERAL(1);
20
+ GENERAL(1),
21
+ SPEED(2);
21
22
 
22
23
  companion object
23
24
  }
@@ -21,6 +21,8 @@ public extension IosPreset {
21
21
  self = .shortform
22
22
  case "general":
23
23
  self = .general
24
+ case "speed":
25
+ self = .speed
24
26
  default:
25
27
  return nil
26
28
  }
@@ -35,6 +37,8 @@ public extension IosPreset {
35
37
  return "shortform"
36
38
  case .general:
37
39
  return "general"
40
+ case .speed:
41
+ return "speed"
38
42
  }
39
43
  }
40
44
  }
@@ -31,6 +31,7 @@ namespace margelo::nitro::nitrospeech {
31
31
  enum class IosPreset {
32
32
  SHORTFORM SWIFT_NAME(shortform) = 0,
33
33
  GENERAL SWIFT_NAME(general) = 1,
34
+ SPEED SWIFT_NAME(speed) = 2,
34
35
  } CLOSED_ENUM;
35
36
 
36
37
  } // namespace margelo::nitro::nitrospeech
@@ -45,6 +46,7 @@ namespace margelo::nitro {
45
46
  switch (hashString(unionValue.c_str(), unionValue.size())) {
46
47
  case hashString("shortform"): return margelo::nitro::nitrospeech::IosPreset::SHORTFORM;
47
48
  case hashString("general"): return margelo::nitro::nitrospeech::IosPreset::GENERAL;
49
+ case hashString("speed"): return margelo::nitro::nitrospeech::IosPreset::SPEED;
48
50
  default: [[unlikely]]
49
51
  throw std::invalid_argument("Cannot convert \"" + unionValue + "\" to enum IosPreset - invalid value!");
50
52
  }
@@ -53,6 +55,7 @@ namespace margelo::nitro {
53
55
  switch (arg) {
54
56
  case margelo::nitro::nitrospeech::IosPreset::SHORTFORM: return JSIConverter<std::string>::toJSI(runtime, "shortform");
55
57
  case margelo::nitro::nitrospeech::IosPreset::GENERAL: return JSIConverter<std::string>::toJSI(runtime, "general");
58
+ case margelo::nitro::nitrospeech::IosPreset::SPEED: return JSIConverter<std::string>::toJSI(runtime, "speed");
56
59
  default: [[unlikely]]
57
60
  throw std::invalid_argument("Cannot convert IosPreset to JS - invalid value: "
58
61
  + std::to_string(static_cast<int>(arg)) + "!");
@@ -66,6 +69,7 @@ namespace margelo::nitro {
66
69
  switch (hashString(unionValue.c_str(), unionValue.size())) {
67
70
  case hashString("shortform"):
68
71
  case hashString("general"):
72
+ case hashString("speed"):
69
73
  return true;
70
74
  default:
71
75
  return false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gmessier/nitro-speech",
3
- "version": "0.4.2",
3
+ "version": "0.4.3",
4
4
  "description": "React Native Real-time Speech Recognition Library powered by Nitro Modules",
5
5
  "main": "./lib/index.js",
6
6
  "module": "./lib/index.js",
@@ -23,7 +23,7 @@ interface ParamsAndroid {
23
23
  androidDisableBatchHandling?: boolean
24
24
  }
25
25
 
26
- type IosPreset = 'shortform' | 'general'
26
+ type IosPreset = 'shortform' | 'general' | 'speed'
27
27
 
28
28
  interface ParamsIOS {
29
29
  /**
@@ -35,9 +35,11 @@ interface ParamsIOS {
35
35
  */
36
36
  iosAddPunctuation?: boolean
37
37
  /**
38
- * `"shortForm"` - for a short phrase or sentence, also disables punctuation
38
+ * `"shortForm"` - For a short phrase or sentence, also disables punctuation
39
39
  *
40
- * `"general"` - for longer speeches, more accurate but delayed response
40
+ * `"speed"` - Gives priority to speed over accuracy
41
+ *
42
+ * `"general"` - For longer speeches, more accurate but delayed response
41
43
  *
42
44
  * @since iOS 26.0+
43
45
  *