react-native-sherpa-onnx 0.2.0 → 0.3.0
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 +232 -236
- package/SherpaOnnx.podspec +68 -64
- package/android/build.gradle +182 -192
- package/android/codegen.gradle +57 -0
- package/android/prebuilt-download.gradle +428 -0
- package/android/prebuilt-versions.gradle +43 -0
- package/android/proguard-rules.pro +10 -0
- package/android/src/main/assets/testModels/add_mul_add.onnx +28 -0
- package/android/src/main/assets/testModels/nnapi_internal_uint8_support.onnx +0 -0
- package/android/src/main/assets/testModels/qnn_multi_ctx_embed.onnx +0 -0
- package/android/src/main/cpp/CMakeLists.txt +166 -129
- package/android/src/main/cpp/CMakePresets.json +54 -0
- package/android/src/main/cpp/crypto/sha256.cpp +174 -0
- package/android/src/main/cpp/crypto/sha256.h +16 -0
- package/android/src/main/cpp/jni/archive/sherpa-onnx-archive-helper.cpp +404 -0
- package/android/src/main/cpp/jni/archive/sherpa-onnx-archive-helper.h +56 -0
- package/android/src/main/cpp/jni/archive/sherpa-onnx-archive-jni.cpp +181 -0
- package/android/src/main/cpp/jni/audio/sherpa-onnx-audio-convert-jni.cpp +888 -0
- package/{ios → android/src/main/cpp/jni/model_detect}/sherpa-onnx-common.h +18 -18
- package/android/src/main/cpp/jni/model_detect/sherpa-onnx-detect-jni-common.cpp +86 -0
- package/android/src/main/cpp/jni/model_detect/sherpa-onnx-detect-jni-common.h +20 -0
- package/android/src/main/cpp/jni/model_detect/sherpa-onnx-model-detect-helper.cpp +423 -0
- package/android/src/main/cpp/jni/model_detect/sherpa-onnx-model-detect-helper.h +55 -0
- package/android/src/main/cpp/jni/model_detect/sherpa-onnx-model-detect-stt.cpp +399 -0
- package/android/src/main/cpp/jni/model_detect/sherpa-onnx-model-detect-tts.cpp +238 -0
- package/{ios → android/src/main/cpp/jni/model_detect}/sherpa-onnx-model-detect.h +122 -89
- package/android/src/main/cpp/jni/model_detect/sherpa-onnx-stt-wrapper.cpp +99 -0
- package/android/src/main/cpp/jni/model_detect/sherpa-onnx-stt-wrapper.h +16 -0
- package/android/src/main/cpp/jni/model_detect/sherpa-onnx-tts-wrapper.cpp +78 -0
- package/android/src/main/cpp/jni/model_detect/sherpa-onnx-tts-wrapper.h +16 -0
- package/android/src/main/cpp/jni/module/sherpa-onnx-module-jni.cpp +190 -0
- package/android/src/main/cpp/jni/tts/sherpa-onnx-tts-zipvoice-jni.cpp +301 -0
- package/android/src/main/java/com/sherpaonnx/SherpaOnnxArchiveHelper.kt +94 -0
- package/android/src/main/java/com/sherpaonnx/{SherpaOnnxCoreHelper.kt → SherpaOnnxAssetHelper.kt} +350 -236
- package/android/src/main/java/com/sherpaonnx/SherpaOnnxModule.kt +791 -483
- package/android/src/main/java/com/sherpaonnx/SherpaOnnxSttHelper.kt +699 -109
- package/android/src/main/java/com/sherpaonnx/SherpaOnnxTtsHelper.kt +1123 -668
- package/android/src/main/java/com/sherpaonnx/ZipvoiceTtsWrapper.kt +187 -0
- package/ios/SherpaOnnx+Assets.h +11 -0
- package/ios/SherpaOnnx+Assets.mm +325 -0
- package/ios/SherpaOnnx+STT.mm +455 -118
- package/ios/SherpaOnnx+TTS.mm +1101 -712
- package/ios/SherpaOnnx.h +17 -6
- package/ios/SherpaOnnx.mm +206 -311
- package/ios/SherpaOnnx.xcconfig +19 -19
- package/ios/SherpaOnnxCoreMLHelper.swift +24 -0
- package/ios/archive/sherpa-onnx-archive-helper.h +21 -0
- package/ios/archive/sherpa-onnx-archive-helper.mm +296 -0
- package/ios/libarchive_darwin_config.h +153 -0
- package/{android/src/main/cpp/jni → ios/model_detect}/sherpa-onnx-common.h +18 -18
- package/ios/model_detect/sherpa-onnx-model-detect-helper.h +49 -0
- package/ios/model_detect/sherpa-onnx-model-detect-helper.mm +210 -0
- package/ios/model_detect/sherpa-onnx-model-detect-stt.mm +344 -0
- package/ios/model_detect/sherpa-onnx-model-detect-tts.mm +201 -0
- package/{android/src/main/cpp/jni → ios/model_detect}/sherpa-onnx-model-detect.h +117 -89
- package/ios/scripts/patch-libarchive-includes.sh +61 -0
- package/ios/scripts/setup-ios-libarchive.sh +98 -0
- package/ios/stt/sherpa-onnx-stt-wrapper.h +129 -0
- package/ios/stt/sherpa-onnx-stt-wrapper.mm +523 -0
- package/ios/{sherpa-onnx-tts-wrapper.h → tts/sherpa-onnx-tts-wrapper.h} +90 -85
- package/ios/{sherpa-onnx-tts-wrapper.mm → tts/sherpa-onnx-tts-wrapper.mm} +376 -345
- package/lib/module/NativeSherpaOnnx.js +3 -0
- package/lib/module/NativeSherpaOnnx.js.map +1 -1
- package/lib/module/audio/index.js +22 -0
- package/lib/module/audio/index.js.map +1 -0
- package/lib/module/diarization/index.js +1 -1
- package/lib/module/diarization/index.js.map +1 -1
- package/lib/module/download/ModelDownloadManager.js +918 -0
- package/lib/module/download/ModelDownloadManager.js.map +1 -0
- package/lib/module/download/extractTarBz2.js +53 -0
- package/lib/module/download/extractTarBz2.js.map +1 -0
- package/lib/module/download/index.js +6 -0
- package/lib/module/download/index.js.map +1 -0
- package/lib/module/download/validation.js +178 -0
- package/lib/module/download/validation.js.map +1 -0
- package/lib/module/enhancement/index.js +1 -1
- package/lib/module/enhancement/index.js.map +1 -1
- package/lib/module/index.js +41 -3
- package/lib/module/index.js.map +1 -1
- package/lib/module/separation/index.js +1 -1
- package/lib/module/separation/index.js.map +1 -1
- package/lib/module/stt/index.js +127 -60
- package/lib/module/stt/index.js.map +1 -1
- package/lib/module/stt/sttModelLanguages.js +512 -0
- package/lib/module/stt/sttModelLanguages.js.map +1 -0
- package/lib/module/stt/types.js +53 -1
- package/lib/module/stt/types.js.map +1 -1
- package/lib/module/tts/index.js +216 -289
- package/lib/module/tts/index.js.map +1 -1
- package/lib/module/tts/types.js +86 -1
- package/lib/module/tts/types.js.map +1 -1
- package/lib/module/types.js.map +1 -1
- package/lib/module/utils.js +86 -73
- package/lib/module/utils.js.map +1 -1
- package/lib/module/vad/index.js +1 -1
- package/lib/module/vad/index.js.map +1 -1
- package/lib/typescript/src/NativeSherpaOnnx.d.ts +192 -38
- package/lib/typescript/src/NativeSherpaOnnx.d.ts.map +1 -1
- package/lib/typescript/src/audio/index.d.ts +13 -0
- package/lib/typescript/src/audio/index.d.ts.map +1 -0
- package/lib/typescript/src/diarization/index.d.ts +3 -2
- package/lib/typescript/src/diarization/index.d.ts.map +1 -1
- package/lib/typescript/src/download/ModelDownloadManager.d.ts +108 -0
- package/lib/typescript/src/download/ModelDownloadManager.d.ts.map +1 -0
- package/lib/typescript/src/download/extractTarBz2.d.ts +14 -0
- package/lib/typescript/src/download/extractTarBz2.d.ts.map +1 -0
- package/lib/typescript/src/download/index.d.ts +7 -0
- package/lib/typescript/src/download/index.d.ts.map +1 -0
- package/lib/typescript/src/download/validation.d.ts +57 -0
- package/lib/typescript/src/download/validation.d.ts.map +1 -0
- package/lib/typescript/src/enhancement/index.d.ts +3 -2
- package/lib/typescript/src/enhancement/index.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +26 -2
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/separation/index.d.ts +3 -2
- package/lib/typescript/src/separation/index.d.ts.map +1 -1
- package/lib/typescript/src/stt/index.d.ts +31 -43
- package/lib/typescript/src/stt/index.d.ts.map +1 -1
- package/lib/typescript/src/stt/sttModelLanguages.d.ts +52 -0
- package/lib/typescript/src/stt/sttModelLanguages.d.ts.map +1 -0
- package/lib/typescript/src/stt/types.d.ts +196 -9
- package/lib/typescript/src/stt/types.d.ts.map +1 -1
- package/lib/typescript/src/tts/index.d.ts +25 -211
- package/lib/typescript/src/tts/index.d.ts.map +1 -1
- package/lib/typescript/src/tts/types.d.ts +148 -25
- package/lib/typescript/src/tts/types.d.ts.map +1 -1
- package/lib/typescript/src/types.d.ts +0 -32
- package/lib/typescript/src/types.d.ts.map +1 -1
- package/lib/typescript/src/utils.d.ts +28 -13
- package/lib/typescript/src/utils.d.ts.map +1 -1
- package/lib/typescript/src/vad/index.d.ts +3 -2
- package/lib/typescript/src/vad/index.d.ts.map +1 -1
- package/package.json +250 -222
- package/scripts/check-qnn-support.sh +78 -0
- package/scripts/setup-ios-framework.sh +379 -282
- package/src/NativeSherpaOnnx.ts +474 -251
- package/src/audio/index.ts +32 -0
- package/src/diarization/index.ts +4 -2
- package/src/download/ModelDownloadManager.ts +1325 -0
- package/src/download/extractTarBz2.ts +78 -0
- package/src/download/index.ts +43 -0
- package/src/download/validation.ts +279 -0
- package/src/enhancement/index.ts +4 -2
- package/src/index.tsx +78 -27
- package/src/separation/index.ts +4 -2
- package/src/stt/index.ts +249 -89
- package/src/stt/sttModelLanguages.ts +237 -0
- package/src/stt/types.ts +263 -9
- package/src/tts/index.ts +470 -458
- package/src/tts/types.ts +373 -218
- package/src/types.ts +0 -44
- package/src/utils.ts +145 -131
- package/src/vad/index.ts +4 -2
- package/third_party/ffmpeg_prebuilt/ANDROID_RELEASE_TAG +1 -0
- package/third_party/libarchive_prebuilt/ANDROID_RELEASE_TAG +1 -0
- package/third_party/libarchive_prebuilt/IOS_RELEASE_TAG +1 -0
- package/third_party/sherpa-onnx-prebuilt/ANDROID_RELEASE_TAG +1 -0
- package/third_party/sherpa-onnx-prebuilt/IOS_RELEASE_TAG +1 -0
- package/android/src/main/cpp/include/sherpa-onnx/c-api/c-api.h +0 -1918
- package/android/src/main/cpp/include/sherpa-onnx/c-api/cxx-api.h +0 -841
- package/android/src/main/cpp/jni/sherpa-onnx-model-detect.cpp +0 -541
- package/android/src/main/cpp/jni/sherpa-onnx-stt-jni.cpp +0 -336
- package/android/src/main/cpp/jni/sherpa-onnx-stt-wrapper.cpp +0 -222
- package/android/src/main/cpp/jni/sherpa-onnx-stt-wrapper.h +0 -68
- package/android/src/main/cpp/jni/sherpa-onnx-tts-jni.cpp +0 -823
- package/android/src/main/cpp/jni/sherpa-onnx-tts-wrapper.cpp +0 -387
- package/android/src/main/cpp/jni/sherpa-onnx-tts-wrapper.h +0 -147
- package/ios/Frameworks/sherpa_onnx.xcframework.zip +0 -0
- package/ios/include/sherpa-onnx/c-api/c-api.h +0 -1918
- package/ios/include/sherpa-onnx/c-api/cxx-api.h +0 -841
- package/ios/sherpa-onnx-model-detect.mm +0 -441
- package/ios/sherpa-onnx-stt-wrapper.h +0 -48
- package/ios/sherpa-onnx-stt-wrapper.mm +0 -201
- package/scripts/copy-headers.js +0 -184
- package/scripts/setup-assets.js +0 -323
package/src/stt/types.ts
CHANGED
|
@@ -1,4 +1,139 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ModelPathConfig } from '../types';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Supported STT model types.
|
|
5
|
+
* Must match ParseSttModelType() in android/.../sherpa-onnx-model-detect-stt.cpp.
|
|
6
|
+
*/
|
|
7
|
+
export type STTModelType =
|
|
8
|
+
| 'transducer'
|
|
9
|
+
| 'nemo_transducer'
|
|
10
|
+
| 'paraformer'
|
|
11
|
+
| 'nemo_ctc'
|
|
12
|
+
| 'wenet_ctc'
|
|
13
|
+
| 'sense_voice'
|
|
14
|
+
| 'zipformer_ctc'
|
|
15
|
+
| 'ctc'
|
|
16
|
+
| 'whisper'
|
|
17
|
+
| 'funasr_nano'
|
|
18
|
+
| 'fire_red_asr'
|
|
19
|
+
| 'moonshine'
|
|
20
|
+
| 'dolphin'
|
|
21
|
+
| 'canary'
|
|
22
|
+
| 'omnilingual'
|
|
23
|
+
| 'medasr'
|
|
24
|
+
| 'telespeech_ctc'
|
|
25
|
+
| 'auto';
|
|
26
|
+
|
|
27
|
+
/** Model types that support hotwords (contextual biasing). Transducer and NeMo transducer support hotwords in sherpa-onnx (NeMo: see k2-fsa/sherpa-onnx#3077). */
|
|
28
|
+
export const STT_HOTWORDS_MODEL_TYPES: readonly STTModelType[] = [
|
|
29
|
+
'transducer',
|
|
30
|
+
'nemo_transducer',
|
|
31
|
+
] as const;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Returns true only for model types that support hotwords (transducer, nemo_transducer).
|
|
35
|
+
* Use this to show/hide hotword options in the UI or to validate before init/setSttConfig.
|
|
36
|
+
*/
|
|
37
|
+
export function sttSupportsHotwords(modelType: STTModelType | string): boolean {
|
|
38
|
+
return modelType === 'transducer' || modelType === 'nemo_transducer';
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** Runtime list of supported STT model types (must match ParseSttModelType in native). */
|
|
42
|
+
export const STT_MODEL_TYPES: readonly STTModelType[] = [
|
|
43
|
+
'transducer',
|
|
44
|
+
'nemo_transducer',
|
|
45
|
+
'paraformer',
|
|
46
|
+
'nemo_ctc',
|
|
47
|
+
'wenet_ctc',
|
|
48
|
+
'sense_voice',
|
|
49
|
+
'zipformer_ctc',
|
|
50
|
+
'ctc',
|
|
51
|
+
'whisper',
|
|
52
|
+
'funasr_nano',
|
|
53
|
+
'fire_red_asr',
|
|
54
|
+
'moonshine',
|
|
55
|
+
'dolphin',
|
|
56
|
+
'canary',
|
|
57
|
+
'omnilingual',
|
|
58
|
+
'medasr',
|
|
59
|
+
'telespeech_ctc',
|
|
60
|
+
'auto',
|
|
61
|
+
] as const;
|
|
62
|
+
|
|
63
|
+
/** Result of initializeSTT(). decodingMethod is set when init succeeds (e.g. "greedy_search" or "modified_beam_search"; auto-set when hotwords are used). */
|
|
64
|
+
export interface SttInitResult {
|
|
65
|
+
success: boolean;
|
|
66
|
+
detectedModels: Array<{ type: string; modelDir: string }>;
|
|
67
|
+
modelType?: string;
|
|
68
|
+
decodingMethod?: string;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// ========== Model-specific options (only applied when that model type is loaded) ==========
|
|
72
|
+
|
|
73
|
+
/** Options for Whisper models. Applied only when modelType is 'whisper'. */
|
|
74
|
+
export interface SttWhisperModelOptions {
|
|
75
|
+
/** Language code (e.g. "en", "de"). Used with multilingual models. Default: "en". */
|
|
76
|
+
language?: string;
|
|
77
|
+
/** "transcribe" or "translate". Default: "transcribe". With "translate", result text is English. */
|
|
78
|
+
task?: 'transcribe' | 'translate';
|
|
79
|
+
/** Padding at end of samples. Kotlin default 1000; C++ default -1. */
|
|
80
|
+
tailPaddings?: number;
|
|
81
|
+
/** Token-level timestamps. Android only; ignored on iOS. */
|
|
82
|
+
enableTokenTimestamps?: boolean;
|
|
83
|
+
/** Segment-level timestamps. Android only; ignored on iOS. */
|
|
84
|
+
enableSegmentTimestamps?: boolean;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** Options for SenseVoice models. Applied only when modelType is 'sense_voice'. */
|
|
88
|
+
export interface SttSenseVoiceModelOptions {
|
|
89
|
+
/** Language hint. */
|
|
90
|
+
language?: string;
|
|
91
|
+
/** Inverse text normalization. Default: true (Kotlin), false (C++). */
|
|
92
|
+
useItn?: boolean;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/** Options for Canary models. Applied only when modelType is 'canary'. */
|
|
96
|
+
export interface SttCanaryModelOptions {
|
|
97
|
+
/** Source language code. Default: "en". */
|
|
98
|
+
srcLang?: string;
|
|
99
|
+
/** Target language code. Default: "en". */
|
|
100
|
+
tgtLang?: string;
|
|
101
|
+
/** Use punctuation. Default: true. */
|
|
102
|
+
usePnc?: boolean;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/** Options for FunASR Nano models. Applied only when modelType is 'funasr_nano'. */
|
|
106
|
+
export interface SttFunAsrNanoModelOptions {
|
|
107
|
+
/** System prompt. Default: "You are a helpful assistant." */
|
|
108
|
+
systemPrompt?: string;
|
|
109
|
+
/** User prompt prefix. Default: "语音转写:" */
|
|
110
|
+
userPrompt?: string;
|
|
111
|
+
/** Max new tokens. Default: 512. */
|
|
112
|
+
maxNewTokens?: number;
|
|
113
|
+
/** Temperature. Default: 1e-6. */
|
|
114
|
+
temperature?: number;
|
|
115
|
+
/** Top-p. Default: 0.8. */
|
|
116
|
+
topP?: number;
|
|
117
|
+
/** Random seed. Default: 42. */
|
|
118
|
+
seed?: number;
|
|
119
|
+
/** Language hint. */
|
|
120
|
+
language?: string;
|
|
121
|
+
/** Inverse text normalization. Default: true. */
|
|
122
|
+
itn?: boolean;
|
|
123
|
+
/** Hotwords string. */
|
|
124
|
+
hotwords?: string;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Model-specific STT options. Only the block for the actually loaded model type is applied;
|
|
129
|
+
* others are ignored (e.g. whisper options have no effect when a paraformer model is loaded).
|
|
130
|
+
*/
|
|
131
|
+
export interface SttModelOptions {
|
|
132
|
+
whisper?: SttWhisperModelOptions;
|
|
133
|
+
senseVoice?: SttSenseVoiceModelOptions;
|
|
134
|
+
canary?: SttCanaryModelOptions;
|
|
135
|
+
funasrNano?: SttFunAsrNanoModelOptions;
|
|
136
|
+
}
|
|
2
137
|
|
|
3
138
|
/**
|
|
4
139
|
* STT-specific initialization options
|
|
@@ -7,7 +142,7 @@ export interface STTInitializeOptions {
|
|
|
7
142
|
/**
|
|
8
143
|
* Model directory path configuration
|
|
9
144
|
*/
|
|
10
|
-
modelPath:
|
|
145
|
+
modelPath: ModelPathConfig;
|
|
11
146
|
|
|
12
147
|
/**
|
|
13
148
|
* Model quantization preference
|
|
@@ -19,24 +154,143 @@ export interface STTInitializeOptions {
|
|
|
19
154
|
|
|
20
155
|
/**
|
|
21
156
|
* Explicit model type specification for STT models
|
|
22
|
-
* - 'transducer': Force detection as
|
|
157
|
+
* - 'transducer': Force detection as Transducer model
|
|
158
|
+
* - 'zipformer_ctc' | 'ctc': Force detection as Zipformer CTC model
|
|
23
159
|
* - 'paraformer': Force detection as Paraformer model
|
|
24
160
|
* - 'nemo_ctc': Force detection as NeMo CTC model
|
|
25
161
|
* - 'whisper': Force detection as Whisper model
|
|
26
162
|
* - 'wenet_ctc': Force detection as WeNet CTC model
|
|
27
163
|
* - 'sense_voice': Force detection as SenseVoice model
|
|
28
164
|
* - 'funasr_nano': Force detection as FunASR Nano model
|
|
165
|
+
* - 'fire_red_asr': FireRed ASR (encoder/decoder)
|
|
166
|
+
* - 'moonshine': Moonshine (preprocess, encode, uncached_decode, cached_decode)
|
|
167
|
+
* - 'dolphin': Dolphin (single model)
|
|
168
|
+
* - 'canary': Canary (encoder/decoder)
|
|
169
|
+
* - 'omnilingual': Omnilingual CTC (single model)
|
|
170
|
+
* - 'medasr': MedASR CTC (single model)
|
|
171
|
+
* - 'telespeech_ctc': TeleSpeech CTC (single model)
|
|
29
172
|
* - 'auto': Automatic detection based on files (default)
|
|
30
173
|
*/
|
|
31
|
-
modelType?:
|
|
174
|
+
modelType?: STTModelType;
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* Enable debug logging in native layer and sherpa-onnx (config.model_config.debug).
|
|
178
|
+
* When true, wrapper and JNI emit verbose logs (config dumps, file checks, init/transcribe flow).
|
|
179
|
+
* Default: false.
|
|
180
|
+
*/
|
|
181
|
+
debug?: boolean;
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Path to hotwords file for keyword boosting (Kotlin OfflineRecognizerConfig.hotwordsFile).
|
|
185
|
+
*/
|
|
186
|
+
hotwordsFile?: string;
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* Hotwords score/weight (Kotlin OfflineRecognizerConfig.hotwordsScore).
|
|
190
|
+
* Default in Kotlin: 1.5.
|
|
191
|
+
*/
|
|
192
|
+
hotwordsScore?: number;
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* Modeling unit for hotwords tokenization (Kotlin OfflineModelConfig.modelingUnit).
|
|
196
|
+
* Only used when hotwords are set and model is transducer/nemo_transducer.
|
|
197
|
+
* Must match how the model was trained: 'bpe' (e.g. English zipformer), 'cjkchar' (e.g. Chinese conformer), 'cjkchar+bpe' (bilingual zh-en).
|
|
198
|
+
* See docs/stt.md "When to use which modelingUnit" and sherpa-onnx hotwords docs.
|
|
199
|
+
*/
|
|
200
|
+
modelingUnit?: 'cjkchar' | 'bpe' | 'cjkchar+bpe';
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* Path to BPE vocabulary file for hotwords (Kotlin OfflineModelConfig.bpeVocab).
|
|
204
|
+
* Required when modelingUnit is 'bpe' or 'cjkchar+bpe'. Sentencepiece .vocab export (bpe.vocab), not the hotwords file.
|
|
205
|
+
*/
|
|
206
|
+
bpeVocab?: string;
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* Number of threads for inference (Kotlin OfflineModelConfig.numThreads).
|
|
210
|
+
* Default in Kotlin: 1.
|
|
211
|
+
*/
|
|
212
|
+
numThreads?: number;
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* Provider string (e.g. "cpu"). Stored in config only; no special logic on change.
|
|
216
|
+
* Kotlin OfflineModelConfig.provider.
|
|
217
|
+
*/
|
|
218
|
+
provider?: string;
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* Path to rule FSTs (Kotlin OfflineRecognizerConfig.ruleFsts).
|
|
222
|
+
*/
|
|
223
|
+
ruleFsts?: string;
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* Path to rule FARs (Kotlin OfflineRecognizerConfig.ruleFars).
|
|
227
|
+
*/
|
|
228
|
+
ruleFars?: string;
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* Dither for feature extraction (Kotlin FeatureConfig.dither). Default 0.
|
|
232
|
+
*/
|
|
233
|
+
dither?: number;
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* Model-specific options. Only options for the loaded model type are applied.
|
|
237
|
+
* E.g. when modelType is 'whisper', only modelOptions.whisper is used.
|
|
238
|
+
*/
|
|
239
|
+
modelOptions?: SttModelOptions;
|
|
32
240
|
}
|
|
33
241
|
|
|
34
242
|
/**
|
|
35
|
-
*
|
|
243
|
+
* Full recognition result from offline STT (maps to Kotlin OfflineRecognizerResult).
|
|
36
244
|
*/
|
|
37
|
-
export interface
|
|
38
|
-
/**
|
|
39
|
-
* Transcribed text
|
|
40
|
-
*/
|
|
245
|
+
export interface SttRecognitionResult {
|
|
246
|
+
/** Transcribed text. */
|
|
41
247
|
text: string;
|
|
248
|
+
/** Token strings. */
|
|
249
|
+
tokens: string[];
|
|
250
|
+
/** Timestamps per token (model-dependent). */
|
|
251
|
+
timestamps: number[];
|
|
252
|
+
/** Detected or specified language (model-dependent). */
|
|
253
|
+
lang: string;
|
|
254
|
+
/** Emotion label (model-dependent, e.g. SenseVoice). */
|
|
255
|
+
emotion: string;
|
|
256
|
+
/** Event label (model-dependent). */
|
|
257
|
+
event: string;
|
|
258
|
+
/** Durations (valid for TDT models). */
|
|
259
|
+
durations: number[];
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
/**
|
|
263
|
+
* Instance-based STT engine returned by createSTT().
|
|
264
|
+
* Call destroy() when done to free native resources.
|
|
265
|
+
*/
|
|
266
|
+
export interface SttEngine {
|
|
267
|
+
readonly instanceId: string;
|
|
268
|
+
transcribeFile(filePath: string): Promise<SttRecognitionResult>;
|
|
269
|
+
transcribeSamples(
|
|
270
|
+
samples: number[],
|
|
271
|
+
sampleRate: number
|
|
272
|
+
): Promise<SttRecognitionResult>;
|
|
273
|
+
setConfig(options: SttRuntimeConfig): Promise<void>;
|
|
274
|
+
destroy(): Promise<void>;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
/**
|
|
278
|
+
* Runtime config for the offline recognizer (Kotlin OfflineRecognizerConfig).
|
|
279
|
+
* Only fields that can be updated via setConfig are included.
|
|
280
|
+
*/
|
|
281
|
+
export interface SttRuntimeConfig {
|
|
282
|
+
/** Decoding method (e.g. greedy_search). */
|
|
283
|
+
decodingMethod?: string;
|
|
284
|
+
/** Max active paths (beam search). */
|
|
285
|
+
maxActivePaths?: number;
|
|
286
|
+
/** Path to hotwords file. */
|
|
287
|
+
hotwordsFile?: string;
|
|
288
|
+
/** Hotwords score. */
|
|
289
|
+
hotwordsScore?: number;
|
|
290
|
+
/** Blank penalty. */
|
|
291
|
+
blankPenalty?: number;
|
|
292
|
+
/** Path to rule FSTs. */
|
|
293
|
+
ruleFsts?: string;
|
|
294
|
+
/** Path to rule FARs. */
|
|
295
|
+
ruleFars?: string;
|
|
42
296
|
}
|