react-native-sherpa-onnx 0.3.0 → 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 +35 -26
- package/android/prebuilt-download.gradle +27 -14
- package/android/src/main/cpp/CMakeLists.txt +51 -17
- 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 -8
- 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 -2
- 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
- package/android/codegen.gradle +0 -57
|
@@ -7,7 +7,6 @@ import com.facebook.react.bridge.ReadableMap
|
|
|
7
7
|
import com.facebook.react.bridge.Arguments
|
|
8
8
|
import com.facebook.react.module.annotations.ReactModule
|
|
9
9
|
import com.facebook.react.modules.core.DeviceEventManagerModule
|
|
10
|
-
import com.facebook.fbreact.specs.NativeSherpaOnnxSpec
|
|
11
10
|
|
|
12
11
|
@ReactModule(name = SherpaOnnxModule.NAME)
|
|
13
12
|
class SherpaOnnxModule(reactContext: ReactApplicationContext) :
|
|
@@ -47,12 +46,13 @@ class SherpaOnnxModule(reactContext: ReactApplicationContext) :
|
|
|
47
46
|
},
|
|
48
47
|
NAME
|
|
49
48
|
)
|
|
49
|
+
private val onlineSttHelper = SherpaOnnxOnlineSttHelper(reactApplicationContext, NAME)
|
|
50
50
|
private val ttsHelper = SherpaOnnxTtsHelper(
|
|
51
51
|
reactApplicationContext,
|
|
52
52
|
{ modelDir, modelType -> Companion.nativeDetectTtsModel(modelDir, modelType) },
|
|
53
|
-
{ instanceId, samples, sampleRate, progress, isFinal -> emitTtsStreamChunk(instanceId, samples, sampleRate, progress, isFinal) },
|
|
54
|
-
{ instanceId, message -> emitTtsStreamError(instanceId, message) },
|
|
55
|
-
{ 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) }
|
|
56
56
|
)
|
|
57
57
|
private val archiveHelper = SherpaOnnxArchiveHelper()
|
|
58
58
|
|
|
@@ -62,6 +62,7 @@ class SherpaOnnxModule(reactContext: ReactApplicationContext) :
|
|
|
62
62
|
|
|
63
63
|
override fun onCatalystInstanceDestroy() {
|
|
64
64
|
super.onCatalystInstanceDestroy()
|
|
65
|
+
onlineSttHelper.shutdown()
|
|
65
66
|
ttsHelper.shutdown()
|
|
66
67
|
}
|
|
67
68
|
|
|
@@ -382,6 +383,107 @@ class SherpaOnnxModule(reactContext: ReactApplicationContext) :
|
|
|
382
383
|
sttHelper.unloadStt(instanceId, promise)
|
|
383
384
|
}
|
|
384
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
|
+
|
|
385
487
|
// ==================== STT Methods ====================
|
|
386
488
|
|
|
387
489
|
/**
|
|
@@ -577,8 +679,8 @@ class SherpaOnnxModule(reactContext: ReactApplicationContext) :
|
|
|
577
679
|
/**
|
|
578
680
|
* Generate speech in streaming mode (emits chunk events).
|
|
579
681
|
*/
|
|
580
|
-
override fun generateTtsStream(instanceId: String, text: String, options: ReadableMap?, promise: Promise) {
|
|
581
|
-
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)
|
|
582
684
|
}
|
|
583
685
|
|
|
584
686
|
/**
|
|
@@ -611,6 +713,7 @@ class SherpaOnnxModule(reactContext: ReactApplicationContext) :
|
|
|
611
713
|
|
|
612
714
|
private fun emitTtsStreamChunk(
|
|
613
715
|
instanceId: String,
|
|
716
|
+
requestId: String,
|
|
614
717
|
samples: FloatArray,
|
|
615
718
|
sampleRate: Int,
|
|
616
719
|
progress: Float,
|
|
@@ -624,6 +727,7 @@ class SherpaOnnxModule(reactContext: ReactApplicationContext) :
|
|
|
624
727
|
}
|
|
625
728
|
val payload = Arguments.createMap()
|
|
626
729
|
payload.putString("instanceId", instanceId)
|
|
730
|
+
payload.putString("requestId", requestId)
|
|
627
731
|
payload.putArray("samples", samplesArray)
|
|
628
732
|
payload.putInt("sampleRate", sampleRate)
|
|
629
733
|
payload.putDouble("progress", progress.toDouble())
|
|
@@ -631,20 +735,22 @@ class SherpaOnnxModule(reactContext: ReactApplicationContext) :
|
|
|
631
735
|
eventEmitter.emit("ttsStreamChunk", payload)
|
|
632
736
|
}
|
|
633
737
|
|
|
634
|
-
private fun emitTtsStreamError(instanceId: String, message: String) {
|
|
738
|
+
private fun emitTtsStreamError(instanceId: String, requestId: String, message: String) {
|
|
635
739
|
val eventEmitter = reactApplicationContext
|
|
636
740
|
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
|
|
637
741
|
val payload = Arguments.createMap()
|
|
638
742
|
payload.putString("instanceId", instanceId)
|
|
743
|
+
payload.putString("requestId", requestId)
|
|
639
744
|
payload.putString("message", message)
|
|
640
745
|
eventEmitter.emit("ttsStreamError", payload)
|
|
641
746
|
}
|
|
642
747
|
|
|
643
|
-
private fun emitTtsStreamEnd(instanceId: String, cancelled: Boolean) {
|
|
748
|
+
private fun emitTtsStreamEnd(instanceId: String, requestId: String, cancelled: Boolean) {
|
|
644
749
|
val eventEmitter = reactApplicationContext
|
|
645
750
|
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
|
|
646
751
|
val payload = Arguments.createMap()
|
|
647
752
|
payload.putString("instanceId", instanceId)
|
|
753
|
+
payload.putString("requestId", requestId)
|
|
648
754
|
payload.putBoolean("cancelled", cancelled)
|
|
649
755
|
eventEmitter.emit("ttsStreamEnd", payload)
|
|
650
756
|
}
|