react-native-sherpa-onnx 0.3.8 → 0.3.9

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 (78) hide show
  1. package/README.md +4 -2
  2. package/SherpaOnnx.podspec +4 -1
  3. package/android/prebuilt-download.gradle +23 -23
  4. package/android/src/main/assets/model_licenses/asr-models-license-status.csv +1 -0
  5. package/android/src/main/cpp/jni/model_detect/sherpa-onnx-model-detect-helper.cpp +23 -0
  6. package/android/src/main/cpp/jni/model_detect/sherpa-onnx-model-detect-helper.h +9 -0
  7. package/android/src/main/cpp/jni/model_detect/sherpa-onnx-model-detect-stt.cpp +51 -8
  8. package/android/src/main/cpp/jni/model_detect/sherpa-onnx-model-detect.h +10 -0
  9. package/android/src/main/cpp/jni/model_detect/sherpa-onnx-stt-wrapper.cpp +5 -0
  10. package/android/src/main/cpp/jni/model_detect/sherpa-onnx-validate-stt.cpp +11 -0
  11. package/android/src/main/java/com/sherpaonnx/SherpaOnnxArchiveHelper.kt +110 -35
  12. package/android/src/main/java/com/sherpaonnx/SherpaOnnxExtractionNotificationHelper.kt +102 -0
  13. package/android/src/main/java/com/sherpaonnx/SherpaOnnxModule.kt +92 -18
  14. package/android/src/main/java/com/sherpaonnx/SherpaOnnxSttHelper.kt +22 -0
  15. package/ios/Resources/model_licenses/asr-models-license-status.csv +1 -0
  16. package/ios/SherpaOnnx+STT.mm +13 -1
  17. package/ios/SherpaOnnx.mm +87 -17
  18. package/ios/model_detect/sherpa-onnx-model-detect-helper.h +5 -0
  19. package/ios/model_detect/sherpa-onnx-model-detect-helper.mm +23 -0
  20. package/ios/model_detect/sherpa-onnx-model-detect-stt.mm +51 -7
  21. package/ios/model_detect/sherpa-onnx-model-detect.h +10 -0
  22. package/ios/model_detect/sherpa-onnx-validate-stt.mm +11 -0
  23. package/ios/stt/sherpa-onnx-stt-wrapper.h +11 -1
  24. package/ios/stt/sherpa-onnx-stt-wrapper.mm +30 -2
  25. package/ios/tts/sherpa-onnx-tts-wrapper.mm +16 -0
  26. package/lib/module/NativeSherpaOnnx.js.map +1 -1
  27. package/lib/module/download/postDownloadProcessing.js +17 -4
  28. package/lib/module/download/postDownloadProcessing.js.map +1 -1
  29. package/lib/module/extraction/extractTarBz2.js +2 -2
  30. package/lib/module/extraction/extractTarBz2.js.map +1 -1
  31. package/lib/module/extraction/extractTarZst.js +2 -2
  32. package/lib/module/extraction/extractTarZst.js.map +1 -1
  33. package/lib/module/extraction/index.js +10 -5
  34. package/lib/module/extraction/index.js.map +1 -1
  35. package/lib/module/stt/index.js +4 -2
  36. package/lib/module/stt/index.js.map +1 -1
  37. package/lib/module/stt/streaming.js +2 -1
  38. package/lib/module/stt/streaming.js.map +1 -1
  39. package/lib/module/stt/types.js +3 -1
  40. package/lib/module/stt/types.js.map +1 -1
  41. package/lib/module/tts/index.js +4 -2
  42. package/lib/module/tts/index.js.map +1 -1
  43. package/lib/module/tts/streaming.js +3 -1
  44. package/lib/module/tts/streaming.js.map +1 -1
  45. package/lib/typescript/src/NativeSherpaOnnx.d.ts +25 -9
  46. package/lib/typescript/src/NativeSherpaOnnx.d.ts.map +1 -1
  47. package/lib/typescript/src/download/postDownloadProcessing.d.ts +9 -0
  48. package/lib/typescript/src/download/postDownloadProcessing.d.ts.map +1 -1
  49. package/lib/typescript/src/extraction/extractTarBz2.d.ts +2 -1
  50. package/lib/typescript/src/extraction/extractTarBz2.d.ts.map +1 -1
  51. package/lib/typescript/src/extraction/extractTarZst.d.ts +2 -1
  52. package/lib/typescript/src/extraction/extractTarZst.d.ts.map +1 -1
  53. package/lib/typescript/src/extraction/index.d.ts +1 -1
  54. package/lib/typescript/src/extraction/index.d.ts.map +1 -1
  55. package/lib/typescript/src/extraction/types.d.ts +12 -0
  56. package/lib/typescript/src/extraction/types.d.ts.map +1 -1
  57. package/lib/typescript/src/stt/index.d.ts +1 -1
  58. package/lib/typescript/src/stt/index.d.ts.map +1 -1
  59. package/lib/typescript/src/stt/streaming.d.ts.map +1 -1
  60. package/lib/typescript/src/stt/types.d.ts +16 -1
  61. package/lib/typescript/src/stt/types.d.ts.map +1 -1
  62. package/lib/typescript/src/tts/index.d.ts.map +1 -1
  63. package/lib/typescript/src/tts/streaming.d.ts.map +1 -1
  64. package/package.json +1 -1
  65. package/scripts/ci/update_model_license_csv.sh +16 -16
  66. package/src/NativeSherpaOnnx.ts +37 -10
  67. package/src/download/postDownloadProcessing.ts +24 -1
  68. package/src/extraction/extractTarBz2.ts +7 -2
  69. package/src/extraction/extractTarZst.ts +7 -2
  70. package/src/extraction/index.ts +29 -6
  71. package/src/extraction/types.ts +16 -0
  72. package/src/stt/index.ts +8 -7
  73. package/src/stt/streaming.ts +7 -1
  74. package/src/stt/types.ts +18 -0
  75. package/src/tts/index.ts +7 -7
  76. package/src/tts/streaming.ts +6 -3
  77. package/third_party/sherpa-onnx-prebuilt/ANDROID_RELEASE_TAG +1 -1
  78. package/third_party/sherpa-onnx-prebuilt/IOS_RELEASE_TAG +1 -1
@@ -1,5 +1,6 @@
1
1
  import { DeviceEventEmitter } from 'react-native';
2
2
  import SherpaOnnx from '../NativeSherpaOnnx';
3
+ import type { ExtractNotificationArgs } from './types';
3
4
 
4
5
  export type ExtractProgressEvent = {
5
6
  bytes: number;
@@ -19,7 +20,8 @@ export async function extractTarBz2(
19
20
  targetPath: string,
20
21
  force = true,
21
22
  onProgress?: (event: ExtractProgressEvent) => void,
22
- signal?: AbortSignal
23
+ signal?: AbortSignal,
24
+ notification?: ExtractNotificationArgs
23
25
  ): Promise<ExtractResult> {
24
26
  let subscription: { remove: () => void } | null = null;
25
27
  let removeAbortListener: (() => void) | null = null;
@@ -62,7 +64,10 @@ export async function extractTarBz2(
62
64
  const result = await SherpaOnnx.extractTarBz2(
63
65
  sourcePath,
64
66
  targetPath,
65
- force
67
+ force,
68
+ notification?.showNotificationsEnabled,
69
+ notification?.notificationTitle,
70
+ notification?.notificationText
66
71
  );
67
72
  if (!result.success) {
68
73
  const message = result.reason || 'Extraction failed';
@@ -1,5 +1,6 @@
1
1
  import { DeviceEventEmitter } from 'react-native';
2
2
  import SherpaOnnx from '../NativeSherpaOnnx';
3
+ import type { ExtractNotificationArgs } from './types';
3
4
 
4
5
  export type ExtractProgressEvent = {
5
6
  bytes: number;
@@ -19,7 +20,8 @@ export async function extractTarZst(
19
20
  targetPath: string,
20
21
  force = true,
21
22
  onProgress?: (event: ExtractProgressEvent) => void,
22
- signal?: AbortSignal
23
+ signal?: AbortSignal,
24
+ notification?: ExtractNotificationArgs
23
25
  ): Promise<ExtractResult> {
24
26
  let subscription: { remove: () => void } | null = null;
25
27
  let removeAbortListener: (() => void) | null = null;
@@ -61,7 +63,10 @@ export async function extractTarZst(
61
63
  const result = await SherpaOnnx.extractTarZst(
62
64
  sourcePath,
63
65
  targetPath,
64
- force
66
+ force,
67
+ notification?.showNotificationsEnabled,
68
+ notification?.notificationTitle,
69
+ notification?.notificationText
65
70
  );
66
71
  if (!result.success) {
67
72
  const message = result.reason || 'Extraction failed';
@@ -17,6 +17,7 @@ import { extractTarBz2 } from './extractTarBz2';
17
17
  import type {
18
18
  BundledArchive,
19
19
  ExtractArchiveOptions,
20
+ ExtractNotificationArgs,
20
21
  ExtractResult,
21
22
  ExtractProgressEvent,
22
23
  } from './types';
@@ -24,6 +25,7 @@ import type {
24
25
  export type {
25
26
  BundledArchive,
26
27
  ExtractArchiveOptions,
28
+ ExtractNotificationArgs,
27
29
  ExtractResult,
28
30
  ExtractProgressEvent,
29
31
  } from './types';
@@ -160,6 +162,11 @@ export async function extractArchive(
160
162
  const force = options?.force !== false;
161
163
  const onProgress = options?.onProgress;
162
164
  const signal = options?.signal;
165
+ const notification = {
166
+ showNotificationsEnabled: options?.showNotificationsEnabled,
167
+ notificationTitle: options?.notificationTitle,
168
+ notificationText: options?.notificationText,
169
+ };
163
170
 
164
171
  if (signal?.aborted) {
165
172
  const err = new Error('Extraction aborted');
@@ -173,7 +180,14 @@ export async function extractArchive(
173
180
  archive.archivePath.startsWith('asset_packs/'));
174
181
 
175
182
  if (useAssetStream) {
176
- return extractFromAsset(archive, targetPath, force, onProgress, signal);
183
+ return extractFromAsset(
184
+ archive,
185
+ targetPath,
186
+ force,
187
+ onProgress,
188
+ signal,
189
+ notification
190
+ );
177
191
  }
178
192
 
179
193
  if (archive.format === 'tar.zst') {
@@ -182,7 +196,8 @@ export async function extractArchive(
182
196
  targetPath,
183
197
  force,
184
198
  onProgress,
185
- signal
199
+ signal,
200
+ notification
186
201
  );
187
202
  }
188
203
  return extractTarBz2(
@@ -190,7 +205,8 @@ export async function extractArchive(
190
205
  targetPath,
191
206
  force,
192
207
  onProgress,
193
- signal
208
+ signal,
209
+ notification
194
210
  );
195
211
  }
196
212
 
@@ -201,7 +217,8 @@ async function extractFromAsset(
201
217
  targetPath: string,
202
218
  force: boolean,
203
219
  onProgress?: (event: ExtractProgressEvent) => void,
204
- signal?: AbortSignal
220
+ signal?: AbortSignal,
221
+ notification?: ExtractNotificationArgs
205
222
  ): Promise<ExtractResult> {
206
223
  const eventName =
207
224
  archive.format === 'tar.zst'
@@ -245,12 +262,18 @@ async function extractFromAsset(
245
262
  ? await SherpaOnnx.extractTarZstFromAsset(
246
263
  archive.archivePath,
247
264
  targetPath,
248
- force
265
+ force,
266
+ notification?.showNotificationsEnabled,
267
+ notification?.notificationTitle,
268
+ notification?.notificationText
249
269
  )
250
270
  : await SherpaOnnx.extractTarBz2FromAsset(
251
271
  archive.archivePath,
252
272
  targetPath,
253
- force
273
+ force,
274
+ notification?.showNotificationsEnabled,
275
+ notification?.notificationTitle,
276
+ notification?.notificationText
254
277
  );
255
278
 
256
279
  if (!result.success) {
@@ -60,4 +60,20 @@ export type ExtractArchiveOptions = {
60
60
  onProgress?: (event: ExtractProgressEvent) => void;
61
61
  /** AbortSignal to cancel the extraction. */
62
62
  signal?: AbortSignal;
63
+ /**
64
+ * **Android:** When true (default), the native layer posts a system notification with extraction
65
+ * progress. Set to false to disable (e.g. first-run bundled-model prep with in-app UI only).
66
+ * **iOS:** Accepted for API parity; no notification is shown.
67
+ */
68
+ showNotificationsEnabled?: boolean;
69
+ /** **Android:** Notification title. Default: generic “unpacking” title. Ignored on iOS. */
70
+ notificationTitle?: string;
71
+ /** **Android:** Notification body (progress text is appended). Default: generic. Ignored on iOS. */
72
+ notificationText?: string;
63
73
  };
74
+
75
+ /** Subset of `ExtractArchiveOptions` passed through to path- and asset-stream extractors. */
76
+ export type ExtractNotificationArgs = Pick<
77
+ ExtractArchiveOptions,
78
+ 'showNotificationsEnabled' | 'notificationTitle' | 'notificationText'
79
+ >;
package/src/stt/index.ts CHANGED
@@ -67,10 +67,7 @@ export async function detectSttModel(
67
67
  options?.preferInt8,
68
68
  options?.modelType
69
69
  );
70
- const err =
71
- typeof (raw as { error?: unknown }).error === 'string'
72
- ? String((raw as { error: string }).error).trim()
73
- : '';
70
+ const err = typeof raw.error === 'string' ? raw.error.trim() : '';
74
71
  return {
75
72
  success: raw.success,
76
73
  ...(err.length > 0 ? { error: err } : {}),
@@ -170,10 +167,13 @@ export async function createSTT(
170
167
  );
171
168
 
172
169
  if (!result.success) {
170
+ const nativeError =
171
+ typeof result.error === 'string' ? result.error.trim() : '';
172
+ const detected = JSON.stringify(result.detectedModels ?? []);
173
173
  throw new Error(
174
- `STT initialization failed: ${JSON.stringify(
175
- result.detectedModels ?? []
176
- )}`
174
+ nativeError.length > 0
175
+ ? `STT initialization failed: ${nativeError}`
176
+ : `STT initialization failed: ${detected}`
177
177
  );
178
178
  }
179
179
 
@@ -259,6 +259,7 @@ export type {
259
259
  STTInitializeOptions,
260
260
  STTModelType,
261
261
  SttModelOptions,
262
+ SttQwen3AsrModelOptions,
262
263
  SttRecognitionResult,
263
264
  SttRuntimeConfig,
264
265
  SttEngine,
@@ -231,7 +231,13 @@ export async function createStreamingSTT(
231
231
  );
232
232
 
233
233
  if (!result.success) {
234
- throw new Error(`Streaming STT initialization failed for ${instanceId}`);
234
+ const nativeError =
235
+ typeof result.error === 'string' ? result.error.trim() : '';
236
+ throw new Error(
237
+ nativeError.length > 0
238
+ ? `Streaming STT initialization failed: ${nativeError}`
239
+ : `Streaming STT initialization failed for ${instanceId}`
240
+ );
235
241
  }
236
242
 
237
243
  const enableInputNormalization = options.enableInputNormalization !== false;
package/src/stt/types.ts CHANGED
@@ -15,6 +15,7 @@ export type STTModelType =
15
15
  | 'ctc'
16
16
  | 'whisper'
17
17
  | 'funasr_nano'
18
+ | 'qwen3_asr'
18
19
  | 'fire_red_asr'
19
20
  | 'moonshine'
20
21
  | 'dolphin'
@@ -50,6 +51,7 @@ export const STT_MODEL_TYPES: readonly STTModelType[] = [
50
51
  'ctc',
51
52
  'whisper',
52
53
  'funasr_nano',
54
+ 'qwen3_asr',
53
55
  'fire_red_asr',
54
56
  'moonshine',
55
57
  'dolphin',
@@ -124,6 +126,20 @@ export interface SttFunAsrNanoModelOptions {
124
126
  hotwords?: string;
125
127
  }
126
128
 
129
+ /** Options for Qwen3 ASR models. Applied only when modelType is 'qwen3_asr'. */
130
+ export interface SttQwen3AsrModelOptions {
131
+ /** Max total sequence length. Default: 512. */
132
+ maxTotalLen?: number;
133
+ /** Max new tokens to generate. Default: 128. */
134
+ maxNewTokens?: number;
135
+ /** Sampling temperature. Default: 1e-6. */
136
+ temperature?: number;
137
+ /** Top-p sampling. Default: 0.8. */
138
+ topP?: number;
139
+ /** Random seed. Default: 42. */
140
+ seed?: number;
141
+ }
142
+
127
143
  /**
128
144
  * Model-specific STT options. Only the block for the actually loaded model type is applied;
129
145
  * others are ignored (e.g. whisper options have no effect when a paraformer model is loaded).
@@ -133,6 +149,7 @@ export interface SttModelOptions {
133
149
  senseVoice?: SttSenseVoiceModelOptions;
134
150
  canary?: SttCanaryModelOptions;
135
151
  funasrNano?: SttFunAsrNanoModelOptions;
152
+ qwen3Asr?: SttQwen3AsrModelOptions;
136
153
  }
137
154
 
138
155
  /**
@@ -162,6 +179,7 @@ export interface STTInitializeOptions {
162
179
  * - 'wenet_ctc': Force detection as WeNet CTC model
163
180
  * - 'sense_voice': Force detection as SenseVoice model
164
181
  * - 'funasr_nano': Force detection as FunASR Nano model
182
+ * - 'qwen3_asr': Force detection as Qwen3 ASR
165
183
  * - 'fire_red_asr': FireRed ASR (encoder/decoder)
166
184
  * - 'moonshine': Moonshine (preprocess, encode, uncached_decode, cached_decode)
167
185
  * - 'dolphin': Dolphin (single model)
package/src/tts/index.ts CHANGED
@@ -112,10 +112,7 @@ export async function detectTtsModel(
112
112
  }> {
113
113
  const resolvedPath = await resolveModelPath(modelPath);
114
114
  const raw = await SherpaOnnx.detectTtsModel(resolvedPath, options?.modelType);
115
- const err =
116
- typeof (raw as { error?: unknown }).error === 'string'
117
- ? String((raw as { error: string }).error).trim()
118
- : '';
115
+ const err = typeof raw.error === 'string' ? raw.error.trim() : '';
119
116
  return {
120
117
  success: raw.success,
121
118
  ...(err.length > 0 ? { error: err } : {}),
@@ -243,10 +240,13 @@ export async function createTTS(
243
240
  );
244
241
 
245
242
  if (!result.success) {
243
+ const nativeError =
244
+ typeof result.error === 'string' ? result.error.trim() : '';
245
+ const detected = JSON.stringify(result.detectedModels ?? []);
246
246
  throw new Error(
247
- `TTS initialization failed: ${JSON.stringify(
248
- result.detectedModels ?? []
249
- )}`
247
+ nativeError.length > 0
248
+ ? `TTS initialization failed: ${nativeError}`
249
+ : `TTS initialization failed: ${detected}`
250
250
  );
251
251
  }
252
252
 
@@ -192,10 +192,13 @@ export async function createStreamingTTS(
192
192
  );
193
193
 
194
194
  if (!result.success) {
195
+ const nativeError =
196
+ typeof result.error === 'string' ? result.error.trim() : '';
197
+ const detected = JSON.stringify(result.detectedModels ?? []);
195
198
  throw new Error(
196
- `TTS initialization failed: ${JSON.stringify(
197
- result.detectedModels ?? []
198
- )}`
199
+ nativeError.length > 0
200
+ ? `Streaming TTS initialization failed: ${nativeError}`
201
+ : `Streaming TTS initialization failed: ${detected}`
199
202
  );
200
203
  }
201
204
 
@@ -1 +1 @@
1
- sherpa-onnx-android-v1.12.31-1
1
+ sherpa-onnx-android-v1.12.34-1
@@ -1 +1 @@
1
- sherpa-onnx-ios-v1.12.31-1
1
+ sherpa-onnx-ios-v1.12.34-1