react-native-sherpa-onnx 0.4.0 → 0.4.2

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 (95) hide show
  1. package/README.md +3 -0
  2. package/android/src/main/assets/model_licenses/alignment-models-license-status.csv +5 -0
  3. package/android/src/main/cpp/CMakeLists.txt +3 -0
  4. package/android/src/main/cpp/jni/model_detect/sherpa-onnx-alignment-wrapper.cpp +66 -0
  5. package/android/src/main/cpp/jni/model_detect/sherpa-onnx-alignment-wrapper.h +17 -0
  6. package/android/src/main/cpp/jni/model_detect/sherpa-onnx-model-detect-alignment.cpp +108 -0
  7. package/android/src/main/cpp/jni/model_detect/sherpa-onnx-model-detect.h +30 -0
  8. package/android/src/main/cpp/jni/model_detect/sherpa-onnx-validate-alignment.cpp +66 -0
  9. package/android/src/main/cpp/jni/model_detect/sherpa-onnx-validate-alignment.h +30 -0
  10. package/android/src/main/cpp/jni/module/sherpa-onnx-module-jni.cpp +21 -0
  11. package/android/src/main/java/com/sherpaonnx/SherpaOnnxAlignmentHelper.kt +555 -0
  12. package/android/src/main/java/com/sherpaonnx/SherpaOnnxModule.kt +76 -0
  13. package/android/src/main/java/com/sherpaonnx/SherpaOnnxTextSegmenter.kt +330 -0
  14. package/android/src/main/java/com/sherpaonnx/SherpaOnnxTtsHelper.kt +180 -23
  15. package/ios/Resources/model_licenses/alignment-models-license-status.csv +5 -0
  16. package/ios/SherpaOnnx+Alignment.mm +704 -0
  17. package/ios/SherpaOnnx+STT.mm +6 -0
  18. package/ios/SherpaOnnx+TTS.mm +624 -50
  19. package/ios/model_detect/sherpa-onnx-model-detect-alignment.mm +108 -0
  20. package/ios/model_detect/sherpa-onnx-model-detect.h +31 -0
  21. package/ios/model_detect/sherpa-onnx-validate-alignment.h +30 -0
  22. package/ios/model_detect/sherpa-onnx-validate-alignment.mm +66 -0
  23. package/ios/stt/sherpa-onnx-stt-wrapper.h +3 -1
  24. package/ios/stt/sherpa-onnx-stt-wrapper.mm +6 -0
  25. package/lib/module/NativeSherpaOnnx.js.map +1 -1
  26. package/lib/module/alignment/index.js +27 -0
  27. package/lib/module/alignment/index.js.map +1 -0
  28. package/lib/module/alignment/types.js +2 -0
  29. package/lib/module/alignment/types.js.map +1 -0
  30. package/lib/module/alignment/vocab.js +40 -0
  31. package/lib/module/alignment/vocab.js.map +1 -0
  32. package/lib/module/download/paths.js +9 -1
  33. package/lib/module/download/paths.js.map +1 -1
  34. package/lib/module/download/registry.js +17 -1
  35. package/lib/module/download/registry.js.map +1 -1
  36. package/lib/module/download/types.js +1 -0
  37. package/lib/module/download/types.js.map +1 -1
  38. package/lib/module/index.js +6 -4
  39. package/lib/module/index.js.map +1 -1
  40. package/lib/module/licenses.js +8 -2
  41. package/lib/module/licenses.js.map +1 -1
  42. package/lib/module/stt/types.js.map +1 -1
  43. package/lib/module/tts/index.js +68 -2
  44. package/lib/module/tts/index.js.map +1 -1
  45. package/lib/module/tts/subtitles.js +400 -0
  46. package/lib/module/tts/subtitles.js.map +1 -0
  47. package/lib/module/tts/tempAudio.js +17 -0
  48. package/lib/module/tts/tempAudio.js.map +1 -0
  49. package/lib/module/tts/types.js.map +1 -1
  50. package/lib/typescript/src/NativeSherpaOnnx.d.ts +34 -3
  51. package/lib/typescript/src/NativeSherpaOnnx.d.ts.map +1 -1
  52. package/lib/typescript/src/alignment/index.d.ts +8 -0
  53. package/lib/typescript/src/alignment/index.d.ts.map +1 -0
  54. package/lib/typescript/src/alignment/types.d.ts +23 -0
  55. package/lib/typescript/src/alignment/types.d.ts.map +1 -0
  56. package/lib/typescript/src/alignment/vocab.d.ts +5 -0
  57. package/lib/typescript/src/alignment/vocab.d.ts.map +1 -0
  58. package/lib/typescript/src/download/paths.d.ts +5 -2
  59. package/lib/typescript/src/download/paths.d.ts.map +1 -1
  60. package/lib/typescript/src/download/registry.d.ts.map +1 -1
  61. package/lib/typescript/src/download/types.d.ts +2 -1
  62. package/lib/typescript/src/download/types.d.ts.map +1 -1
  63. package/lib/typescript/src/index.d.ts +1 -0
  64. package/lib/typescript/src/index.d.ts.map +1 -1
  65. package/lib/typescript/src/licenses.d.ts.map +1 -1
  66. package/lib/typescript/src/stt/types.d.ts +5 -2
  67. package/lib/typescript/src/stt/types.d.ts.map +1 -1
  68. package/lib/typescript/src/tts/index.d.ts +2 -1
  69. package/lib/typescript/src/tts/index.d.ts.map +1 -1
  70. package/lib/typescript/src/tts/subtitles.d.ts +24 -0
  71. package/lib/typescript/src/tts/subtitles.d.ts.map +1 -0
  72. package/lib/typescript/src/tts/tempAudio.d.ts +3 -0
  73. package/lib/typescript/src/tts/tempAudio.d.ts.map +1 -0
  74. package/lib/typescript/src/tts/types.d.ts +68 -2
  75. package/lib/typescript/src/tts/types.d.ts.map +1 -1
  76. package/package.json +6 -1
  77. package/scripts/alignment-models/README.md +90 -0
  78. package/scripts/alignment-models/build_and_upload.js +724 -0
  79. package/scripts/alignment-models/sources.csv +5 -0
  80. package/scripts/alignment-models/sync_alignment_license_status.js +123 -0
  81. package/src/NativeSherpaOnnx.ts +35 -3
  82. package/src/alignment/index.ts +41 -0
  83. package/src/alignment/types.ts +22 -0
  84. package/src/alignment/vocab.ts +38 -0
  85. package/src/download/paths.ts +18 -5
  86. package/src/download/registry.ts +23 -3
  87. package/src/download/types.ts +1 -0
  88. package/src/index.tsx +6 -4
  89. package/src/licenses.ts +12 -1
  90. package/src/stt/types.ts +5 -2
  91. package/src/tts/index.ts +110 -3
  92. package/src/tts/subtitles.ts +611 -0
  93. package/src/tts/tempAudio.ts +31 -0
  94. package/src/tts/types.ts +79 -2
  95. package/third_party/sherpa-onnx-prebuilt/IOS_RELEASE_TAG +1 -1
package/src/tts/types.ts CHANGED
@@ -179,6 +179,40 @@ export interface TtsUpdateOptions {
179
179
  modelOptions?: TtsModelOptions;
180
180
  }
181
181
 
182
+ export type SubtitleMode = 'off' | 'fast' | 'accurate';
183
+
184
+ export type SubtitleGranularity = 'sentence' | 'word' | 'character';
185
+
186
+ export interface SubtitleOptions {
187
+ /**
188
+ * Subtitle generation mode.
189
+ *
190
+ * - 'off': Do not generate subtitles/timestamps
191
+ * - 'fast': Estimated timing based on callback chunks (default)
192
+ * - 'accurate': wav2vec2 CTC forced alignment
193
+ *
194
+ * @default 'fast'
195
+ */
196
+ mode?: SubtitleMode;
197
+
198
+ /**
199
+ * Subtitle granularity.
200
+ *
201
+ * - 'sentence': sentence-level subtitles
202
+ * - 'word': word-level subtitles
203
+ * - 'character': character-level subtitles (only supported with mode: 'accurate')
204
+ *
205
+ * @default 'sentence'
206
+ */
207
+ granularity?: SubtitleGranularity;
208
+
209
+ /**
210
+ * Optional absolute path to an alignment ONNX model.
211
+ * Required when `mode: 'accurate'`.
212
+ */
213
+ alignmentModelPath?: string;
214
+ }
215
+
182
216
  /**
183
217
  * Options for TTS generation. Maps to Kotlin GenerationConfig when reference
184
218
  * audio or advanced options are used; otherwise simple sid/speed are used.
@@ -235,6 +269,11 @@ export interface TtsGenerationOptions {
235
269
  * Model-specific (e.g. temperature, chunk_size for Pocket).
236
270
  */
237
271
  extra?: Record<string, string>;
272
+
273
+ /**
274
+ * Subtitle/timestamp generation options.
275
+ */
276
+ subtitles?: SubtitleOptions;
238
277
  }
239
278
 
240
279
  /**
@@ -288,9 +327,47 @@ export interface GeneratedAudioWithTimestamps extends GeneratedAudio {
288
327
  subtitles: TtsSubtitleItem[];
289
328
 
290
329
  /**
291
- * True if timestamps are estimated rather than model-provided.
330
+ * Subtitle timing mode.
331
+ *
332
+ * - 'off': No subtitle timing requested/generated
333
+ * - 'estimated': Fast mode estimation
334
+ * - 'aligned': Accurate forced alignment mode
335
+ */
336
+ timingMode: 'off' | 'estimated' | 'aligned';
337
+ }
338
+
339
+ export interface SubtitleFromAudioOptions {
340
+ /**
341
+ * Subtitle generation mode.
342
+ */
343
+ mode: 'fast' | 'accurate';
344
+
345
+ /**
346
+ * Subtitle granularity.
347
+ *
348
+ * - 'sentence': sentence-level subtitles
349
+ * - 'word': word-level subtitles
350
+ * - 'character': character-level subtitles (only supported with mode: 'accurate')
351
+ *
352
+ * @default 'sentence'
292
353
  */
293
- estimated: boolean;
354
+ granularity?: SubtitleGranularity;
355
+
356
+ /**
357
+ * Optional language hint for future multi-language alignment variants.
358
+ */
359
+ language?: string;
360
+
361
+ /**
362
+ * Optional absolute path to an alignment ONNX model.
363
+ * Required when `mode: 'accurate'`.
364
+ */
365
+ alignmentModelPath?: string;
366
+ }
367
+
368
+ export interface SubtitleResult {
369
+ subtitles: TtsSubtitleItem[];
370
+ timingMode: 'estimated' | 'aligned';
294
371
  }
295
372
 
296
373
  /**
@@ -1 +1 @@
1
- sherpa-onnx-ios-v1.12.34-1
1
+ sherpa-onnx-ios-v1.12.34-2