react-native-sherpa-onnx 0.3.1 → 0.3.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.
- package/README.md +21 -7
- package/SherpaOnnx.podspec +1 -1
- package/android/build.gradle +30 -1
- package/android/prebuilt-download.gradle +27 -14
- package/android/src/main/cpp/CMakeLists.txt +50 -16
- package/android/src/main/cpp/jni/archive/sherpa-onnx-archive-helper.cpp +14 -0
- package/android/src/main/cpp/jni/model_detect/sherpa-onnx-model-detect-helper.cpp +16 -0
- package/android/src/main/cpp/jni/model_detect/sherpa-onnx-model-detect-helper.h +3 -0
- package/android/src/main/cpp/jni/model_detect/sherpa-onnx-model-detect-stt.cpp +19 -2
- package/android/src/main/cpp/jni/model_detect/sherpa-onnx-model-detect.h +2 -1
- package/android/src/main/cpp/jni/model_detect/sherpa-onnx-stt-wrapper.cpp +1 -0
- package/android/src/main/java/com/sherpaonnx/SherpaOnnxModule.kt +114 -7
- package/android/src/main/java/com/sherpaonnx/SherpaOnnxOnlineSttHelper.kt +535 -0
- package/android/src/main/java/com/sherpaonnx/SherpaOnnxTtsHelper.kt +10 -10
- package/ios/SherpaOnnx+OnlineSTT.mm +365 -0
- package/ios/SherpaOnnx+TTS.mm +35 -9
- package/ios/SherpaOnnx.mm +6 -0
- package/ios/model_detect/sherpa-onnx-model-detect-helper.h +3 -0
- package/ios/model_detect/sherpa-onnx-model-detect-helper.mm +16 -0
- package/ios/model_detect/sherpa-onnx-model-detect-stt.mm +19 -2
- package/ios/model_detect/sherpa-onnx-model-detect.h +2 -1
- package/ios/online_stt/sherpa-onnx-online-stt-wrapper.h +85 -0
- package/ios/online_stt/sherpa-onnx-online-stt-wrapper.mm +270 -0
- package/lib/module/NativeSherpaOnnx.js.map +1 -1
- package/lib/module/index.js +2 -2
- package/lib/module/stt/index.js +4 -0
- package/lib/module/stt/index.js.map +1 -1
- package/lib/module/stt/streaming.js +257 -0
- package/lib/module/stt/streaming.js.map +1 -0
- package/lib/module/stt/streamingTypes.js +38 -0
- package/lib/module/stt/streamingTypes.js.map +1 -0
- package/lib/module/tts/index.js +4 -43
- package/lib/module/tts/index.js.map +1 -1
- package/lib/module/tts/streaming.js +220 -0
- package/lib/module/tts/streaming.js.map +1 -0
- package/lib/module/tts/streamingTypes.js +4 -0
- package/lib/module/tts/streamingTypes.js.map +1 -0
- package/lib/module/tts/types.js +8 -1
- package/lib/module/tts/types.js.map +1 -1
- package/lib/typescript/src/NativeSherpaOnnx.d.ts +66 -1
- package/lib/typescript/src/NativeSherpaOnnx.d.ts.map +1 -1
- package/lib/typescript/src/stt/index.d.ts +3 -0
- package/lib/typescript/src/stt/index.d.ts.map +1 -1
- package/lib/typescript/src/stt/streaming.d.ts +42 -0
- package/lib/typescript/src/stt/streaming.d.ts.map +1 -0
- package/lib/typescript/src/stt/streamingTypes.d.ts +122 -0
- package/lib/typescript/src/stt/streamingTypes.d.ts.map +1 -0
- package/lib/typescript/src/tts/index.d.ts +3 -1
- package/lib/typescript/src/tts/index.d.ts.map +1 -1
- package/lib/typescript/src/tts/streaming.d.ts +24 -0
- package/lib/typescript/src/tts/streaming.d.ts.map +1 -0
- package/lib/typescript/src/tts/streamingTypes.d.ts +27 -0
- package/lib/typescript/src/tts/streamingTypes.d.ts.map +1 -0
- package/lib/typescript/src/tts/types.d.ts +19 -6
- package/lib/typescript/src/tts/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/NativeSherpaOnnx.ts +95 -0
- package/src/index.tsx +2 -2
- package/src/stt/index.ts +17 -0
- package/src/stt/streaming.ts +361 -0
- package/src/stt/streamingTypes.ts +151 -0
- package/src/tts/index.ts +6 -66
- package/src/tts/streaming.ts +336 -0
- package/src/tts/streamingTypes.ts +54 -0
- package/src/tts/types.ts +20 -10
|
@@ -46,12 +46,13 @@ class SherpaOnnxModule(reactContext: ReactApplicationContext) :
|
|
|
46
46
|
},
|
|
47
47
|
NAME
|
|
48
48
|
)
|
|
49
|
+
private val onlineSttHelper = SherpaOnnxOnlineSttHelper(reactApplicationContext, NAME)
|
|
49
50
|
private val ttsHelper = SherpaOnnxTtsHelper(
|
|
50
51
|
reactApplicationContext,
|
|
51
52
|
{ modelDir, modelType -> Companion.nativeDetectTtsModel(modelDir, modelType) },
|
|
52
|
-
{ instanceId, samples, sampleRate, progress, isFinal -> emitTtsStreamChunk(instanceId, samples, sampleRate, progress, isFinal) },
|
|
53
|
-
{ instanceId, message -> emitTtsStreamError(instanceId, message) },
|
|
54
|
-
{ instanceId, cancelled -> emitTtsStreamEnd(instanceId, cancelled) }
|
|
53
|
+
{ instanceId, requestId, samples, sampleRate, progress, isFinal -> emitTtsStreamChunk(instanceId, requestId, samples, sampleRate, progress, isFinal) },
|
|
54
|
+
{ instanceId, requestId, message -> emitTtsStreamError(instanceId, requestId, message) },
|
|
55
|
+
{ instanceId, requestId, cancelled -> emitTtsStreamEnd(instanceId, requestId, cancelled) }
|
|
55
56
|
)
|
|
56
57
|
private val archiveHelper = SherpaOnnxArchiveHelper()
|
|
57
58
|
|
|
@@ -61,6 +62,7 @@ class SherpaOnnxModule(reactContext: ReactApplicationContext) :
|
|
|
61
62
|
|
|
62
63
|
override fun onCatalystInstanceDestroy() {
|
|
63
64
|
super.onCatalystInstanceDestroy()
|
|
65
|
+
onlineSttHelper.shutdown()
|
|
64
66
|
ttsHelper.shutdown()
|
|
65
67
|
}
|
|
66
68
|
|
|
@@ -381,6 +383,107 @@ class SherpaOnnxModule(reactContext: ReactApplicationContext) :
|
|
|
381
383
|
sttHelper.unloadStt(instanceId, promise)
|
|
382
384
|
}
|
|
383
385
|
|
|
386
|
+
// ==================== Online (streaming) STT Methods ====================
|
|
387
|
+
|
|
388
|
+
override fun initializeOnlineSttWithOptions(instanceId: String, options: ReadableMap, promise: Promise) {
|
|
389
|
+
val modelDir = options.getString("modelDir")
|
|
390
|
+
if (modelDir.isNullOrEmpty()) {
|
|
391
|
+
promise.reject("INIT_ERROR", "modelDir is required")
|
|
392
|
+
return
|
|
393
|
+
}
|
|
394
|
+
val modelType = options.getString("modelType") ?: "transducer"
|
|
395
|
+
val enableEndpoint = if (options.hasKey("enableEndpoint")) options.getBoolean("enableEndpoint") else true
|
|
396
|
+
val decodingMethod = options.getString("decodingMethod") ?: "greedy_search"
|
|
397
|
+
val maxActivePaths = if (options.hasKey("maxActivePaths")) options.getDouble("maxActivePaths").toInt() else 4
|
|
398
|
+
val hotwordsFile = if (options.hasKey("hotwordsFile")) options.getString("hotwordsFile") else null
|
|
399
|
+
val hotwordsScore = if (options.hasKey("hotwordsScore")) options.getDouble("hotwordsScore") else null
|
|
400
|
+
val numThreads = if (options.hasKey("numThreads")) options.getDouble("numThreads") else null
|
|
401
|
+
val provider = if (options.hasKey("provider")) options.getString("provider") else null
|
|
402
|
+
val ruleFsts = if (options.hasKey("ruleFsts")) options.getString("ruleFsts") else null
|
|
403
|
+
val ruleFars = if (options.hasKey("ruleFars")) options.getString("ruleFars") else null
|
|
404
|
+
val blankPenalty = if (options.hasKey("blankPenalty")) options.getDouble("blankPenalty") else null
|
|
405
|
+
val debug = if (options.hasKey("debug")) options.getBoolean("debug") else null
|
|
406
|
+
val rule1MustContainNonSilence = if (options.hasKey("rule1MustContainNonSilence")) options.getBoolean("rule1MustContainNonSilence") else null
|
|
407
|
+
val rule1MinTrailingSilence = if (options.hasKey("rule1MinTrailingSilence")) options.getDouble("rule1MinTrailingSilence") else null
|
|
408
|
+
val rule1MinUtteranceLength = if (options.hasKey("rule1MinUtteranceLength")) options.getDouble("rule1MinUtteranceLength") else null
|
|
409
|
+
val rule2MustContainNonSilence = if (options.hasKey("rule2MustContainNonSilence")) options.getBoolean("rule2MustContainNonSilence") else null
|
|
410
|
+
val rule2MinTrailingSilence = if (options.hasKey("rule2MinTrailingSilence")) options.getDouble("rule2MinTrailingSilence") else null
|
|
411
|
+
val rule2MinUtteranceLength = if (options.hasKey("rule2MinUtteranceLength")) options.getDouble("rule2MinUtteranceLength") else null
|
|
412
|
+
val rule3MustContainNonSilence = if (options.hasKey("rule3MustContainNonSilence")) options.getBoolean("rule3MustContainNonSilence") else null
|
|
413
|
+
val rule3MinTrailingSilence = if (options.hasKey("rule3MinTrailingSilence")) options.getDouble("rule3MinTrailingSilence") else null
|
|
414
|
+
val rule3MinUtteranceLength = if (options.hasKey("rule3MinUtteranceLength")) options.getDouble("rule3MinUtteranceLength") else null
|
|
415
|
+
onlineSttHelper.initializeOnlineStt(
|
|
416
|
+
instanceId,
|
|
417
|
+
modelDir,
|
|
418
|
+
modelType,
|
|
419
|
+
enableEndpoint,
|
|
420
|
+
decodingMethod,
|
|
421
|
+
maxActivePaths,
|
|
422
|
+
hotwordsFile,
|
|
423
|
+
hotwordsScore,
|
|
424
|
+
numThreads,
|
|
425
|
+
provider,
|
|
426
|
+
ruleFsts,
|
|
427
|
+
ruleFars,
|
|
428
|
+
blankPenalty,
|
|
429
|
+
debug,
|
|
430
|
+
rule1MustContainNonSilence,
|
|
431
|
+
rule1MinTrailingSilence,
|
|
432
|
+
rule1MinUtteranceLength,
|
|
433
|
+
rule2MustContainNonSilence,
|
|
434
|
+
rule2MinTrailingSilence,
|
|
435
|
+
rule2MinUtteranceLength,
|
|
436
|
+
rule3MustContainNonSilence,
|
|
437
|
+
rule3MinTrailingSilence,
|
|
438
|
+
rule3MinUtteranceLength,
|
|
439
|
+
promise
|
|
440
|
+
)
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
override fun createSttStream(instanceId: String, streamId: String, hotwords: String?, promise: Promise) {
|
|
444
|
+
onlineSttHelper.createSttStream(instanceId, streamId, hotwords, promise)
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
override fun acceptSttWaveform(streamId: String, samples: ReadableArray, sampleRate: Double, promise: Promise) {
|
|
448
|
+
onlineSttHelper.acceptSttWaveform(streamId, samples, sampleRate.toInt(), promise)
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
override fun sttStreamInputFinished(streamId: String, promise: Promise) {
|
|
452
|
+
onlineSttHelper.sttStreamInputFinished(streamId, promise)
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
override fun decodeSttStream(streamId: String, promise: Promise) {
|
|
456
|
+
onlineSttHelper.decodeSttStream(streamId, promise)
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
override fun isSttStreamReady(streamId: String, promise: Promise) {
|
|
460
|
+
onlineSttHelper.isSttStreamReady(streamId, promise)
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
override fun getSttStreamResult(streamId: String, promise: Promise) {
|
|
464
|
+
onlineSttHelper.getSttStreamResult(streamId, promise)
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
override fun isSttStreamEndpoint(streamId: String, promise: Promise) {
|
|
468
|
+
onlineSttHelper.isSttStreamEndpoint(streamId, promise)
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
override fun resetSttStream(streamId: String, promise: Promise) {
|
|
472
|
+
onlineSttHelper.resetSttStream(streamId, promise)
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
override fun releaseSttStream(streamId: String, promise: Promise) {
|
|
476
|
+
onlineSttHelper.releaseSttStream(streamId, promise)
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
override fun unloadOnlineStt(instanceId: String, promise: Promise) {
|
|
480
|
+
onlineSttHelper.unloadOnlineStt(instanceId, promise)
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
override fun processSttAudioChunk(streamId: String, samples: ReadableArray, sampleRate: Double, promise: Promise) {
|
|
484
|
+
onlineSttHelper.processSttAudioChunk(streamId, samples, sampleRate.toInt(), promise)
|
|
485
|
+
}
|
|
486
|
+
|
|
384
487
|
// ==================== STT Methods ====================
|
|
385
488
|
|
|
386
489
|
/**
|
|
@@ -576,8 +679,8 @@ class SherpaOnnxModule(reactContext: ReactApplicationContext) :
|
|
|
576
679
|
/**
|
|
577
680
|
* Generate speech in streaming mode (emits chunk events).
|
|
578
681
|
*/
|
|
579
|
-
override fun generateTtsStream(instanceId: String, text: String, options: ReadableMap?, promise: Promise) {
|
|
580
|
-
ttsHelper.generateTtsStream(instanceId, text, options, promise)
|
|
682
|
+
override fun generateTtsStream(instanceId: String, requestId: String, text: String, options: ReadableMap?, promise: Promise) {
|
|
683
|
+
ttsHelper.generateTtsStream(instanceId, requestId, text, options, promise)
|
|
581
684
|
}
|
|
582
685
|
|
|
583
686
|
/**
|
|
@@ -610,6 +713,7 @@ class SherpaOnnxModule(reactContext: ReactApplicationContext) :
|
|
|
610
713
|
|
|
611
714
|
private fun emitTtsStreamChunk(
|
|
612
715
|
instanceId: String,
|
|
716
|
+
requestId: String,
|
|
613
717
|
samples: FloatArray,
|
|
614
718
|
sampleRate: Int,
|
|
615
719
|
progress: Float,
|
|
@@ -623,6 +727,7 @@ class SherpaOnnxModule(reactContext: ReactApplicationContext) :
|
|
|
623
727
|
}
|
|
624
728
|
val payload = Arguments.createMap()
|
|
625
729
|
payload.putString("instanceId", instanceId)
|
|
730
|
+
payload.putString("requestId", requestId)
|
|
626
731
|
payload.putArray("samples", samplesArray)
|
|
627
732
|
payload.putInt("sampleRate", sampleRate)
|
|
628
733
|
payload.putDouble("progress", progress.toDouble())
|
|
@@ -630,20 +735,22 @@ class SherpaOnnxModule(reactContext: ReactApplicationContext) :
|
|
|
630
735
|
eventEmitter.emit("ttsStreamChunk", payload)
|
|
631
736
|
}
|
|
632
737
|
|
|
633
|
-
private fun emitTtsStreamError(instanceId: String, message: String) {
|
|
738
|
+
private fun emitTtsStreamError(instanceId: String, requestId: String, message: String) {
|
|
634
739
|
val eventEmitter = reactApplicationContext
|
|
635
740
|
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
|
|
636
741
|
val payload = Arguments.createMap()
|
|
637
742
|
payload.putString("instanceId", instanceId)
|
|
743
|
+
payload.putString("requestId", requestId)
|
|
638
744
|
payload.putString("message", message)
|
|
639
745
|
eventEmitter.emit("ttsStreamError", payload)
|
|
640
746
|
}
|
|
641
747
|
|
|
642
|
-
private fun emitTtsStreamEnd(instanceId: String, cancelled: Boolean) {
|
|
748
|
+
private fun emitTtsStreamEnd(instanceId: String, requestId: String, cancelled: Boolean) {
|
|
643
749
|
val eventEmitter = reactApplicationContext
|
|
644
750
|
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
|
|
645
751
|
val payload = Arguments.createMap()
|
|
646
752
|
payload.putString("instanceId", instanceId)
|
|
753
|
+
payload.putString("requestId", requestId)
|
|
647
754
|
payload.putBoolean("cancelled", cancelled)
|
|
648
755
|
eventEmitter.emit("ttsStreamEnd", payload)
|
|
649
756
|
}
|