react-native-nitro-onnx 0.1.0 → 0.1.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/NitroOnnxSpeech.podspec +3 -1
- package/README.md +146 -41
- package/android/CMakeLists.txt +54 -1
- package/android/build.gradle +6 -0
- package/android/src/main/AndroidManifest.xml +0 -2
- package/android/src/main/cpp/cpp-adapter.cpp +2 -2
- package/android/src/main/java/com/margelo/nitro/onnx/speech/OnnxSpeechPackage.kt +26 -17
- package/cpp/AsrEngine.cpp +154 -59
- package/cpp/AsrEngine.hpp +19 -6
- package/cpp/AudioFileReader.cpp +4 -0
- package/cpp/ModelSingleton.hpp +14 -0
- package/cpp/NitroOnnxSpeech.cpp +37 -18
- package/cpp/NitroOnnxSpeech.hpp +1 -7
- package/cpp/OfflineAsr.cpp +17 -8
- package/cpp/OfflineAsr.hpp +1 -1
- package/cpp/ResourceDir.cpp +5 -5
- package/cpp/ResourceDir.hpp +5 -4
- package/cpp/SpeakerEngine.cpp +38 -28
- package/cpp/SpeakerEngine.hpp +14 -13
- package/cpp/SpeakerManager.cpp +16 -14
- package/cpp/SpeakerManager.hpp +2 -1
- package/cpp/SpeakerRecord.cpp +125 -0
- package/cpp/SpeakerRecord.hpp +42 -0
- package/cpp/StreamingAsr.cpp +20 -9
- package/cpp/StreamingAsr.hpp +1 -1
- package/cpp/Tts.cpp +44 -10
- package/cpp/Tts.hpp +2 -1
- package/cpp/TtsEngine.cpp +17 -9
- package/cpp/TtsEngine.hpp +24 -5
- package/cpp/Vad.cpp +12 -11
- package/cpp/Vad.hpp +1 -1
- package/cpp/VadEngine.cpp +27 -33
- package/cpp/VadEngine.hpp +9 -10
- package/cpp/Version.hpp +7 -0
- package/ios/OnnxSpeechInitializer.mm +18 -6
- package/lib/specs/OnnxSpeech.nitro.d.ts +43 -6
- package/lib/specs/OnnxSpeech.nitro.d.ts.map +1 -1
- package/nitrogen/generated/shared/c++/AsrModelConfig.hpp +10 -2
- package/nitrogen/generated/shared/c++/HybridOnnxSpeechSpec.cpp +1 -1
- package/nitrogen/generated/shared/c++/HybridOnnxSpeechSpec.hpp +1 -1
- package/nitrogen/generated/shared/c++/TtsModelConfig.hpp +10 -2
- package/nitrogen/generated/shared/c++/VadConfig.hpp +6 -2
- package/package.json +4 -3
- package/scripts/generate-version.js +22 -0
- package/src/specs/OnnxSpeech.nitro.ts +43 -6
- package/cpp/ThreadPool.cpp +0 -41
- package/cpp/ThreadPool.hpp +0 -62
|
@@ -33,6 +33,8 @@ export interface VadConfig {
|
|
|
33
33
|
minSpeechDurationMs?: number;
|
|
34
34
|
/** How many milliseconds of audio to keep before onSpeechStart. Default: 300. */
|
|
35
35
|
preBufferMs?: number;
|
|
36
|
+
/** Enable sherpa-onnx debug logging for this model. Default: false. */
|
|
37
|
+
debug?: boolean;
|
|
36
38
|
}
|
|
37
39
|
/** VAD segment delivered after speech ends or on explicit pull. */
|
|
38
40
|
export interface VadSegment {
|
|
@@ -82,7 +84,12 @@ export interface AsrModelConfig {
|
|
|
82
84
|
encoder?: string;
|
|
83
85
|
decoder?: string;
|
|
84
86
|
joiner?: string;
|
|
85
|
-
/**
|
|
87
|
+
/**
|
|
88
|
+
* Single-model families (Paraformer / Wenet / Telespeech / Dolphin / NeMo / SenseVoice).
|
|
89
|
+
* Moonshine: `model` is preprocessor.onnx, `encoder` is encoder.onnx,
|
|
90
|
+
* `decoder` is uncached_decoder.onnx (or merged_decoder.onnx when `joiner` is unset),
|
|
91
|
+
* `joiner` is cached_decoder.onnx.
|
|
92
|
+
*/
|
|
86
93
|
model?: string;
|
|
87
94
|
/** NeMo config file (.yaml). */
|
|
88
95
|
config?: string;
|
|
@@ -96,6 +103,15 @@ export interface AsrModelConfig {
|
|
|
96
103
|
language?: string;
|
|
97
104
|
/** SenseVoice: whether to use itn. */
|
|
98
105
|
useItn?: boolean;
|
|
106
|
+
/** Enable sherpa-onnx debug logging for this model. Default: false. */
|
|
107
|
+
debug?: boolean;
|
|
108
|
+
/**
|
|
109
|
+
* Execution provider for ONNX Runtime.
|
|
110
|
+
* Default: "nnapi" on Android (or "qnn" when built with -DQNN_ROOT),
|
|
111
|
+
* "coreml" on iOS (Apple Neural Engine, unsupported ops fall back to CPU).
|
|
112
|
+
* Pass "cpu" explicitly to disable NPU acceleration.
|
|
113
|
+
*/
|
|
114
|
+
provider?: string;
|
|
99
115
|
}
|
|
100
116
|
export interface AsrResult {
|
|
101
117
|
text: string;
|
|
@@ -194,6 +210,14 @@ export interface TtsModelConfig {
|
|
|
194
210
|
speakerId?: number;
|
|
195
211
|
/** Speed factor, e.g. 1.0. */
|
|
196
212
|
speed?: number;
|
|
213
|
+
/** Enable sherpa-onnx debug logging for this model. Default: false. */
|
|
214
|
+
debug?: boolean;
|
|
215
|
+
/**
|
|
216
|
+
* Execution provider for ONNX Runtime.
|
|
217
|
+
* Default: "cpu" on Android / Linux, "coreml" on iOS.
|
|
218
|
+
* Pass a provider explicitly to enable NPU acceleration.
|
|
219
|
+
*/
|
|
220
|
+
provider?: string;
|
|
197
221
|
}
|
|
198
222
|
export interface TtsResult {
|
|
199
223
|
/** Synthesized audio as 16 kHz mono f32 PCM (or configured output sample rate). */
|
|
@@ -208,7 +232,13 @@ export interface Tts extends HybridObject<SpeechPlatforms> {
|
|
|
208
232
|
isLoaded(): boolean;
|
|
209
233
|
/** Synthesize text into audio on a background thread. Optional speed override. */
|
|
210
234
|
synthesize(text: string, speed?: number): Promise<TtsResult>;
|
|
211
|
-
/**
|
|
235
|
+
/**
|
|
236
|
+
* Synthesize with a speaker reference.
|
|
237
|
+
* `speakerId` is either a numeric model speaker index ("0", "1", ... for
|
|
238
|
+
* Kokoro/VITS multi-speaker) or a registered speaker ID from
|
|
239
|
+
* `registerSpeaker` / `registerSpeakerFromFile` (zero-shot models such as
|
|
240
|
+
* Pocket require the reference audio stored by `registerSpeakerFromFile`).
|
|
241
|
+
*/
|
|
212
242
|
synthesizeWithSpeaker(text: string, speakerId: string, speed?: number): Promise<TtsResult>;
|
|
213
243
|
/** Save TTS result as a WAV file at the given path. */
|
|
214
244
|
saveWav(result: TtsResult, path: string): Promise<void>;
|
|
@@ -235,9 +265,16 @@ export interface SpeakerManager extends HybridObject<SpeechPlatforms> {
|
|
|
235
265
|
isLoaded(): boolean;
|
|
236
266
|
/** Compute an embedding from reference 16 kHz mono f32 PCM audio. */
|
|
237
267
|
computeEmbedding(samples: ArrayBuffer): Promise<ArrayBuffer>;
|
|
238
|
-
/**
|
|
268
|
+
/**
|
|
269
|
+
* Register a speaker embedding for later TTS use.
|
|
270
|
+
* Note: embedding-only records cannot drive zero-shot TTS; use
|
|
271
|
+
* `registerSpeakerFromFile` when you need voice cloning with Pocket.
|
|
272
|
+
*/
|
|
239
273
|
registerSpeaker(id: string, name: string, embedding: ArrayBuffer): Promise<RegisteredSpeaker>;
|
|
240
|
-
/**
|
|
274
|
+
/**
|
|
275
|
+
* Register from a reference audio file. Stores both the speaker embedding
|
|
276
|
+
* and the reference audio required by zero-shot TTS models.
|
|
277
|
+
*/
|
|
241
278
|
registerSpeakerFromFile(id: string, name: string, path: string): Promise<RegisteredSpeaker>;
|
|
242
279
|
/** List registered speakers. */
|
|
243
280
|
listSpeakers(): Promise<RegisteredSpeaker[]>;
|
|
@@ -258,7 +295,7 @@ export interface OnnxSpeech extends HybridObject<SpeechPlatforms> {
|
|
|
258
295
|
createSpeakerManager(): SpeakerManager;
|
|
259
296
|
/** Get the module version. */
|
|
260
297
|
readonly version: string;
|
|
261
|
-
/**
|
|
262
|
-
|
|
298
|
+
/** Returns the Qualcomm SoC model (e.g. "SM8550") on Android, or empty string on iOS / non-Qualcomm. */
|
|
299
|
+
getQualcommSoc(): string;
|
|
263
300
|
}
|
|
264
301
|
//# sourceMappingURL=OnnxSpeech.nitro.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OnnxSpeech.nitro.d.ts","sourceRoot":"","sources":["../../src/specs/OnnxSpeech.nitro.ts"],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Aa,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACzC,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACzB;AAMD,MAAM,WAAW,UAAW,SAAQ,YAAY,CAAC,eAAe,CAAC;IAC/D,6BAA6B;IAC7B,SAAS,IAAI,GAAG,CAAC;IACjB,sCAAsC;IACtC,gBAAgB,IAAI,UAAU,CAAC;IAC/B,uCAAuC;IACvC,kBAAkB,IAAI,YAAY,CAAC;IACnC,6BAA6B;IAC7B,SAAS,IAAI,GAAG,CAAC;IACjB,kDAAkD;IAClD,oBAAoB,IAAI,cAAc,CAAC;IACvC,8BAA8B;IAC9B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,wGAAwG;IACxG,cAAc,IAAI,MAAM,CAAC;CAC1B"}
|
|
@@ -57,10 +57,12 @@ namespace margelo::nitro::onnx::speech {
|
|
|
57
57
|
std::optional<double> maxActivePaths SWIFT_PRIVATE;
|
|
58
58
|
std::optional<std::string> language SWIFT_PRIVATE;
|
|
59
59
|
std::optional<bool> useItn SWIFT_PRIVATE;
|
|
60
|
+
std::optional<bool> debug SWIFT_PRIVATE;
|
|
61
|
+
std::optional<std::string> provider SWIFT_PRIVATE;
|
|
60
62
|
|
|
61
63
|
public:
|
|
62
64
|
AsrModelConfig() = default;
|
|
63
|
-
explicit AsrModelConfig(AsrModelType type, std::string modelDir, std::string tokensPath, std::optional<std::string> whisperEncoder, std::optional<std::string> whisperDecoder, std::optional<std::string> encoder, std::optional<std::string> decoder, std::optional<std::string> joiner, std::optional<std::string> model, std::optional<std::string> config, std::optional<double> numThreads, std::optional<std::string> decodingMethod, std::optional<double> maxActivePaths, std::optional<std::string> language, std::optional<bool> useItn): type(type), modelDir(modelDir), tokensPath(tokensPath), whisperEncoder(whisperEncoder), whisperDecoder(whisperDecoder), encoder(encoder), decoder(decoder), joiner(joiner), model(model), config(config), numThreads(numThreads), decodingMethod(decodingMethod), maxActivePaths(maxActivePaths), language(language), useItn(useItn) {}
|
|
65
|
+
explicit AsrModelConfig(AsrModelType type, std::string modelDir, std::string tokensPath, std::optional<std::string> whisperEncoder, std::optional<std::string> whisperDecoder, std::optional<std::string> encoder, std::optional<std::string> decoder, std::optional<std::string> joiner, std::optional<std::string> model, std::optional<std::string> config, std::optional<double> numThreads, std::optional<std::string> decodingMethod, std::optional<double> maxActivePaths, std::optional<std::string> language, std::optional<bool> useItn, std::optional<bool> debug, std::optional<std::string> provider): type(type), modelDir(modelDir), tokensPath(tokensPath), whisperEncoder(whisperEncoder), whisperDecoder(whisperDecoder), encoder(encoder), decoder(decoder), joiner(joiner), model(model), config(config), numThreads(numThreads), decodingMethod(decodingMethod), maxActivePaths(maxActivePaths), language(language), useItn(useItn), debug(debug), provider(provider) {}
|
|
64
66
|
|
|
65
67
|
public:
|
|
66
68
|
friend bool operator==(const AsrModelConfig& lhs, const AsrModelConfig& rhs) = default;
|
|
@@ -90,7 +92,9 @@ namespace margelo::nitro {
|
|
|
90
92
|
JSIConverter<std::optional<std::string>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "decodingMethod"))),
|
|
91
93
|
JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "maxActivePaths"))),
|
|
92
94
|
JSIConverter<std::optional<std::string>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "language"))),
|
|
93
|
-
JSIConverter<std::optional<bool>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "useItn")))
|
|
95
|
+
JSIConverter<std::optional<bool>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "useItn"))),
|
|
96
|
+
JSIConverter<std::optional<bool>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "debug"))),
|
|
97
|
+
JSIConverter<std::optional<std::string>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "provider")))
|
|
94
98
|
);
|
|
95
99
|
}
|
|
96
100
|
static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::onnx::speech::AsrModelConfig& arg) {
|
|
@@ -110,6 +114,8 @@ namespace margelo::nitro {
|
|
|
110
114
|
obj.setProperty(runtime, PropNameIDCache::get(runtime, "maxActivePaths"), JSIConverter<std::optional<double>>::toJSI(runtime, arg.maxActivePaths));
|
|
111
115
|
obj.setProperty(runtime, PropNameIDCache::get(runtime, "language"), JSIConverter<std::optional<std::string>>::toJSI(runtime, arg.language));
|
|
112
116
|
obj.setProperty(runtime, PropNameIDCache::get(runtime, "useItn"), JSIConverter<std::optional<bool>>::toJSI(runtime, arg.useItn));
|
|
117
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "debug"), JSIConverter<std::optional<bool>>::toJSI(runtime, arg.debug));
|
|
118
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "provider"), JSIConverter<std::optional<std::string>>::toJSI(runtime, arg.provider));
|
|
113
119
|
return obj;
|
|
114
120
|
}
|
|
115
121
|
static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
|
|
@@ -135,6 +141,8 @@ namespace margelo::nitro {
|
|
|
135
141
|
if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "maxActivePaths")))) return false;
|
|
136
142
|
if (!JSIConverter<std::optional<std::string>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "language")))) return false;
|
|
137
143
|
if (!JSIConverter<std::optional<bool>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "useItn")))) return false;
|
|
144
|
+
if (!JSIConverter<std::optional<bool>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "debug")))) return false;
|
|
145
|
+
if (!JSIConverter<std::optional<std::string>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "provider")))) return false;
|
|
138
146
|
return true;
|
|
139
147
|
}
|
|
140
148
|
};
|
|
@@ -20,7 +20,7 @@ namespace margelo::nitro::onnx::speech {
|
|
|
20
20
|
prototype.registerHybridMethod("createStreamingAsr", &HybridOnnxSpeechSpec::createStreamingAsr);
|
|
21
21
|
prototype.registerHybridMethod("createTts", &HybridOnnxSpeechSpec::createTts);
|
|
22
22
|
prototype.registerHybridMethod("createSpeakerManager", &HybridOnnxSpeechSpec::createSpeakerManager);
|
|
23
|
-
prototype.registerHybridMethod("
|
|
23
|
+
prototype.registerHybridMethod("getQualcommSoc", &HybridOnnxSpeechSpec::getQualcommSoc);
|
|
24
24
|
});
|
|
25
25
|
}
|
|
26
26
|
|
|
@@ -68,7 +68,7 @@ namespace margelo::nitro::onnx::speech {
|
|
|
68
68
|
virtual std::shared_ptr<HybridStreamingAsrSpec> createStreamingAsr() = 0;
|
|
69
69
|
virtual std::shared_ptr<HybridTtsSpec> createTts() = 0;
|
|
70
70
|
virtual std::shared_ptr<HybridSpeakerManagerSpec> createSpeakerManager() = 0;
|
|
71
|
-
virtual
|
|
71
|
+
virtual std::string getQualcommSoc() = 0;
|
|
72
72
|
|
|
73
73
|
protected:
|
|
74
74
|
// Hybrid Setup
|
|
@@ -66,10 +66,12 @@ namespace margelo::nitro::onnx::speech {
|
|
|
66
66
|
std::optional<double> outputSampleRate SWIFT_PRIVATE;
|
|
67
67
|
std::optional<double> speakerId SWIFT_PRIVATE;
|
|
68
68
|
std::optional<double> speed SWIFT_PRIVATE;
|
|
69
|
+
std::optional<bool> debug SWIFT_PRIVATE;
|
|
70
|
+
std::optional<std::string> provider SWIFT_PRIVATE;
|
|
69
71
|
|
|
70
72
|
public:
|
|
71
73
|
TtsModelConfig() = default;
|
|
72
|
-
explicit TtsModelConfig(TtsModelType type, std::string modelDir, std::optional<std::string> model, std::optional<std::string> acousticModel, std::optional<std::string> vocoder, std::optional<std::string> tokens, std::optional<std::string> lexicon, std::optional<std::string> voices, std::optional<std::string> espeakNgData, std::optional<std::string> dictDir, std::optional<std::string> lmMain, std::optional<std::string> lmFlow, std::optional<std::string> textConditioner, std::optional<std::string> pocketEncoder, std::optional<std::string> pocketDecoder, std::optional<std::string> vocabJson, std::optional<std::string> tokenScoresJson, std::optional<std::string> zipvoiceEncoder, std::optional<std::string> zipvoiceDecoder, std::optional<std::string> config, std::optional<double> numThreads, std::optional<double> outputSampleRate, std::optional<double> speakerId, std::optional<double> speed): type(type), modelDir(modelDir), model(model), acousticModel(acousticModel), vocoder(vocoder), tokens(tokens), lexicon(lexicon), voices(voices), espeakNgData(espeakNgData), dictDir(dictDir), lmMain(lmMain), lmFlow(lmFlow), textConditioner(textConditioner), pocketEncoder(pocketEncoder), pocketDecoder(pocketDecoder), vocabJson(vocabJson), tokenScoresJson(tokenScoresJson), zipvoiceEncoder(zipvoiceEncoder), zipvoiceDecoder(zipvoiceDecoder), config(config), numThreads(numThreads), outputSampleRate(outputSampleRate), speakerId(speakerId), speed(speed) {}
|
|
74
|
+
explicit TtsModelConfig(TtsModelType type, std::string modelDir, std::optional<std::string> model, std::optional<std::string> acousticModel, std::optional<std::string> vocoder, std::optional<std::string> tokens, std::optional<std::string> lexicon, std::optional<std::string> voices, std::optional<std::string> espeakNgData, std::optional<std::string> dictDir, std::optional<std::string> lmMain, std::optional<std::string> lmFlow, std::optional<std::string> textConditioner, std::optional<std::string> pocketEncoder, std::optional<std::string> pocketDecoder, std::optional<std::string> vocabJson, std::optional<std::string> tokenScoresJson, std::optional<std::string> zipvoiceEncoder, std::optional<std::string> zipvoiceDecoder, std::optional<std::string> config, std::optional<double> numThreads, std::optional<double> outputSampleRate, std::optional<double> speakerId, std::optional<double> speed, std::optional<bool> debug, std::optional<std::string> provider): type(type), modelDir(modelDir), model(model), acousticModel(acousticModel), vocoder(vocoder), tokens(tokens), lexicon(lexicon), voices(voices), espeakNgData(espeakNgData), dictDir(dictDir), lmMain(lmMain), lmFlow(lmFlow), textConditioner(textConditioner), pocketEncoder(pocketEncoder), pocketDecoder(pocketDecoder), vocabJson(vocabJson), tokenScoresJson(tokenScoresJson), zipvoiceEncoder(zipvoiceEncoder), zipvoiceDecoder(zipvoiceDecoder), config(config), numThreads(numThreads), outputSampleRate(outputSampleRate), speakerId(speakerId), speed(speed), debug(debug), provider(provider) {}
|
|
73
75
|
|
|
74
76
|
public:
|
|
75
77
|
friend bool operator==(const TtsModelConfig& lhs, const TtsModelConfig& rhs) = default;
|
|
@@ -108,7 +110,9 @@ namespace margelo::nitro {
|
|
|
108
110
|
JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "numThreads"))),
|
|
109
111
|
JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "outputSampleRate"))),
|
|
110
112
|
JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "speakerId"))),
|
|
111
|
-
JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "speed")))
|
|
113
|
+
JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "speed"))),
|
|
114
|
+
JSIConverter<std::optional<bool>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "debug"))),
|
|
115
|
+
JSIConverter<std::optional<std::string>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "provider")))
|
|
112
116
|
);
|
|
113
117
|
}
|
|
114
118
|
static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::onnx::speech::TtsModelConfig& arg) {
|
|
@@ -137,6 +141,8 @@ namespace margelo::nitro {
|
|
|
137
141
|
obj.setProperty(runtime, PropNameIDCache::get(runtime, "outputSampleRate"), JSIConverter<std::optional<double>>::toJSI(runtime, arg.outputSampleRate));
|
|
138
142
|
obj.setProperty(runtime, PropNameIDCache::get(runtime, "speakerId"), JSIConverter<std::optional<double>>::toJSI(runtime, arg.speakerId));
|
|
139
143
|
obj.setProperty(runtime, PropNameIDCache::get(runtime, "speed"), JSIConverter<std::optional<double>>::toJSI(runtime, arg.speed));
|
|
144
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "debug"), JSIConverter<std::optional<bool>>::toJSI(runtime, arg.debug));
|
|
145
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "provider"), JSIConverter<std::optional<std::string>>::toJSI(runtime, arg.provider));
|
|
140
146
|
return obj;
|
|
141
147
|
}
|
|
142
148
|
static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
|
|
@@ -171,6 +177,8 @@ namespace margelo::nitro {
|
|
|
171
177
|
if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "outputSampleRate")))) return false;
|
|
172
178
|
if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "speakerId")))) return false;
|
|
173
179
|
if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "speed")))) return false;
|
|
180
|
+
if (!JSIConverter<std::optional<bool>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "debug")))) return false;
|
|
181
|
+
if (!JSIConverter<std::optional<std::string>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "provider")))) return false;
|
|
174
182
|
return true;
|
|
175
183
|
}
|
|
176
184
|
};
|
|
@@ -45,10 +45,11 @@ namespace margelo::nitro::onnx::speech {
|
|
|
45
45
|
std::optional<double> minSilenceDurationMs SWIFT_PRIVATE;
|
|
46
46
|
std::optional<double> minSpeechDurationMs SWIFT_PRIVATE;
|
|
47
47
|
std::optional<double> preBufferMs SWIFT_PRIVATE;
|
|
48
|
+
std::optional<bool> debug SWIFT_PRIVATE;
|
|
48
49
|
|
|
49
50
|
public:
|
|
50
51
|
VadConfig() = default;
|
|
51
|
-
explicit VadConfig(std::optional<std::string> modelPath, std::optional<double> threshold, std::optional<double> minSilenceDurationMs, std::optional<double> minSpeechDurationMs, std::optional<double> preBufferMs): modelPath(modelPath), threshold(threshold), minSilenceDurationMs(minSilenceDurationMs), minSpeechDurationMs(minSpeechDurationMs), preBufferMs(preBufferMs) {}
|
|
52
|
+
explicit VadConfig(std::optional<std::string> modelPath, std::optional<double> threshold, std::optional<double> minSilenceDurationMs, std::optional<double> minSpeechDurationMs, std::optional<double> preBufferMs, std::optional<bool> debug): modelPath(modelPath), threshold(threshold), minSilenceDurationMs(minSilenceDurationMs), minSpeechDurationMs(minSpeechDurationMs), preBufferMs(preBufferMs), debug(debug) {}
|
|
52
53
|
|
|
53
54
|
public:
|
|
54
55
|
friend bool operator==(const VadConfig& lhs, const VadConfig& rhs) = default;
|
|
@@ -68,7 +69,8 @@ namespace margelo::nitro {
|
|
|
68
69
|
JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "threshold"))),
|
|
69
70
|
JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "minSilenceDurationMs"))),
|
|
70
71
|
JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "minSpeechDurationMs"))),
|
|
71
|
-
JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "preBufferMs")))
|
|
72
|
+
JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "preBufferMs"))),
|
|
73
|
+
JSIConverter<std::optional<bool>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "debug")))
|
|
72
74
|
);
|
|
73
75
|
}
|
|
74
76
|
static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::onnx::speech::VadConfig& arg) {
|
|
@@ -78,6 +80,7 @@ namespace margelo::nitro {
|
|
|
78
80
|
obj.setProperty(runtime, PropNameIDCache::get(runtime, "minSilenceDurationMs"), JSIConverter<std::optional<double>>::toJSI(runtime, arg.minSilenceDurationMs));
|
|
79
81
|
obj.setProperty(runtime, PropNameIDCache::get(runtime, "minSpeechDurationMs"), JSIConverter<std::optional<double>>::toJSI(runtime, arg.minSpeechDurationMs));
|
|
80
82
|
obj.setProperty(runtime, PropNameIDCache::get(runtime, "preBufferMs"), JSIConverter<std::optional<double>>::toJSI(runtime, arg.preBufferMs));
|
|
83
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "debug"), JSIConverter<std::optional<bool>>::toJSI(runtime, arg.debug));
|
|
81
84
|
return obj;
|
|
82
85
|
}
|
|
83
86
|
static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
|
|
@@ -93,6 +96,7 @@ namespace margelo::nitro {
|
|
|
93
96
|
if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "minSilenceDurationMs")))) return false;
|
|
94
97
|
if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "minSpeechDurationMs")))) return false;
|
|
95
98
|
if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "preBufferMs")))) return false;
|
|
99
|
+
if (!JSIConverter<std::optional<bool>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "debug")))) return false;
|
|
96
100
|
return true;
|
|
97
101
|
}
|
|
98
102
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-nitro-onnx",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "React Native Nitro module wrapping sherpa-onnx for local ASR, TTS, VAD and voice cloning",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://github.com/zydbkqf/react-native-nitro-onnx",
|
|
@@ -10,8 +10,9 @@
|
|
|
10
10
|
"types": "lib/index.d.ts",
|
|
11
11
|
"source": "src/index.ts",
|
|
12
12
|
"scripts": {
|
|
13
|
-
"postinstall": "node scripts/prepare-sherpa-onnx.js",
|
|
14
|
-
"prespecs": "node scripts/prepare-sherpa-onnx.js",
|
|
13
|
+
"postinstall": "node scripts/generate-version.js && node scripts/prepare-sherpa-onnx.js",
|
|
14
|
+
"prespecs": "node scripts/generate-version.js && node scripts/prepare-sherpa-onnx.js",
|
|
15
|
+
"version": "node scripts/generate-version.js",
|
|
15
16
|
"build": "tsc",
|
|
16
17
|
"specs": "nitrogen",
|
|
17
18
|
"test": "jest",
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// ------------------------------------------------------------------------------
|
|
3
|
+
// Generates cpp/Version.hpp from package.json so getVersion() never drifts.
|
|
4
|
+
// ------------------------------------------------------------------------------
|
|
5
|
+
import fs from "node:fs";
|
|
6
|
+
import path from "node:path";
|
|
7
|
+
import { fileURLToPath } from "node:url";
|
|
8
|
+
|
|
9
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
10
|
+
const root = path.resolve(__dirname, "..");
|
|
11
|
+
const pkg = JSON.parse(fs.readFileSync(path.join(root, "package.json"), "utf8"));
|
|
12
|
+
const outPath = path.join(root, "cpp", "Version.hpp");
|
|
13
|
+
const contents = `// ------------------------------------------------------------------------------
|
|
14
|
+
// Version.hpp
|
|
15
|
+
// Generated from package.json by scripts/generate-version.js. DO NOT EDIT.
|
|
16
|
+
// ------------------------------------------------------------------------------
|
|
17
|
+
#pragma once
|
|
18
|
+
|
|
19
|
+
#define NITRO_ONNX_SPEECH_VERSION "${pkg.version}"
|
|
20
|
+
`;
|
|
21
|
+
fs.writeFileSync(outPath, contents);
|
|
22
|
+
console.log(`[generate-version] wrote ${outPath} (${pkg.version})`);
|
|
@@ -47,6 +47,8 @@ export interface VadConfig {
|
|
|
47
47
|
minSpeechDurationMs?: number;
|
|
48
48
|
/** How many milliseconds of audio to keep before onSpeechStart. Default: 300. */
|
|
49
49
|
preBufferMs?: number;
|
|
50
|
+
/** Enable sherpa-onnx debug logging for this model. Default: false. */
|
|
51
|
+
debug?: boolean;
|
|
50
52
|
}
|
|
51
53
|
|
|
52
54
|
/** VAD segment delivered after speech ends or on explicit pull. */
|
|
@@ -116,7 +118,12 @@ export interface AsrModelConfig {
|
|
|
116
118
|
encoder?: string;
|
|
117
119
|
decoder?: string;
|
|
118
120
|
joiner?: string;
|
|
119
|
-
/**
|
|
121
|
+
/**
|
|
122
|
+
* Single-model families (Paraformer / Wenet / Telespeech / Dolphin / NeMo / SenseVoice).
|
|
123
|
+
* Moonshine: `model` is preprocessor.onnx, `encoder` is encoder.onnx,
|
|
124
|
+
* `decoder` is uncached_decoder.onnx (or merged_decoder.onnx when `joiner` is unset),
|
|
125
|
+
* `joiner` is cached_decoder.onnx.
|
|
126
|
+
*/
|
|
120
127
|
model?: string;
|
|
121
128
|
/** NeMo config file (.yaml). */
|
|
122
129
|
config?: string;
|
|
@@ -130,6 +137,15 @@ export interface AsrModelConfig {
|
|
|
130
137
|
language?: string;
|
|
131
138
|
/** SenseVoice: whether to use itn. */
|
|
132
139
|
useItn?: boolean;
|
|
140
|
+
/** Enable sherpa-onnx debug logging for this model. Default: false. */
|
|
141
|
+
debug?: boolean;
|
|
142
|
+
/**
|
|
143
|
+
* Execution provider for ONNX Runtime.
|
|
144
|
+
* Default: "nnapi" on Android (or "qnn" when built with -DQNN_ROOT),
|
|
145
|
+
* "coreml" on iOS (Apple Neural Engine, unsupported ops fall back to CPU).
|
|
146
|
+
* Pass "cpu" explicitly to disable NPU acceleration.
|
|
147
|
+
*/
|
|
148
|
+
provider?: string;
|
|
133
149
|
}
|
|
134
150
|
|
|
135
151
|
export interface AsrResult {
|
|
@@ -243,6 +259,14 @@ export interface TtsModelConfig {
|
|
|
243
259
|
speakerId?: number;
|
|
244
260
|
/** Speed factor, e.g. 1.0. */
|
|
245
261
|
speed?: number;
|
|
262
|
+
/** Enable sherpa-onnx debug logging for this model. Default: false. */
|
|
263
|
+
debug?: boolean;
|
|
264
|
+
/**
|
|
265
|
+
* Execution provider for ONNX Runtime.
|
|
266
|
+
* Default: "cpu" on Android / Linux, "coreml" on iOS.
|
|
267
|
+
* Pass a provider explicitly to enable NPU acceleration.
|
|
268
|
+
*/
|
|
269
|
+
provider?: string;
|
|
246
270
|
}
|
|
247
271
|
|
|
248
272
|
export interface TtsResult {
|
|
@@ -259,7 +283,13 @@ export interface Tts extends HybridObject<SpeechPlatforms> {
|
|
|
259
283
|
isLoaded(): boolean;
|
|
260
284
|
/** Synthesize text into audio on a background thread. Optional speed override. */
|
|
261
285
|
synthesize(text: string, speed?: number): Promise<TtsResult>;
|
|
262
|
-
/**
|
|
286
|
+
/**
|
|
287
|
+
* Synthesize with a speaker reference.
|
|
288
|
+
* `speakerId` is either a numeric model speaker index ("0", "1", ... for
|
|
289
|
+
* Kokoro/VITS multi-speaker) or a registered speaker ID from
|
|
290
|
+
* `registerSpeaker` / `registerSpeakerFromFile` (zero-shot models such as
|
|
291
|
+
* Pocket require the reference audio stored by `registerSpeakerFromFile`).
|
|
292
|
+
*/
|
|
263
293
|
synthesizeWithSpeaker(text: string, speakerId: string, speed?: number): Promise<TtsResult>;
|
|
264
294
|
/** Save TTS result as a WAV file at the given path. */
|
|
265
295
|
saveWav(result: TtsResult, path: string): Promise<void>;
|
|
@@ -293,9 +323,16 @@ export interface SpeakerManager extends HybridObject<SpeechPlatforms> {
|
|
|
293
323
|
isLoaded(): boolean;
|
|
294
324
|
/** Compute an embedding from reference 16 kHz mono f32 PCM audio. */
|
|
295
325
|
computeEmbedding(samples: ArrayBuffer): Promise<ArrayBuffer>;
|
|
296
|
-
/**
|
|
326
|
+
/**
|
|
327
|
+
* Register a speaker embedding for later TTS use.
|
|
328
|
+
* Note: embedding-only records cannot drive zero-shot TTS; use
|
|
329
|
+
* `registerSpeakerFromFile` when you need voice cloning with Pocket.
|
|
330
|
+
*/
|
|
297
331
|
registerSpeaker(id: string, name: string, embedding: ArrayBuffer): Promise<RegisteredSpeaker>;
|
|
298
|
-
/**
|
|
332
|
+
/**
|
|
333
|
+
* Register from a reference audio file. Stores both the speaker embedding
|
|
334
|
+
* and the reference audio required by zero-shot TTS models.
|
|
335
|
+
*/
|
|
299
336
|
registerSpeakerFromFile(id: string, name: string, path: string): Promise<RegisteredSpeaker>;
|
|
300
337
|
/** List registered speakers. */
|
|
301
338
|
listSpeakers(): Promise<RegisteredSpeaker[]>;
|
|
@@ -321,6 +358,6 @@ export interface OnnxSpeech extends HybridObject<SpeechPlatforms> {
|
|
|
321
358
|
createSpeakerManager(): SpeakerManager;
|
|
322
359
|
/** Get the module version. */
|
|
323
360
|
readonly version: string;
|
|
324
|
-
/**
|
|
325
|
-
|
|
361
|
+
/** Returns the Qualcomm SoC model (e.g. "SM8550") on Android, or empty string on iOS / non-Qualcomm. */
|
|
362
|
+
getQualcommSoc(): string;
|
|
326
363
|
}
|
package/cpp/ThreadPool.cpp
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
// ------------------------------------------------------------------------------
|
|
2
|
-
// ThreadPool.cpp
|
|
3
|
-
// ------------------------------------------------------------------------------
|
|
4
|
-
#include "ThreadPool.hpp"
|
|
5
|
-
|
|
6
|
-
namespace margelo::nitro::onnx::speech {
|
|
7
|
-
|
|
8
|
-
ThreadPool::ThreadPool(size_t threadCount) {
|
|
9
|
-
for (size_t i = 0; i < threadCount; ++i) {
|
|
10
|
-
workers_.emplace_back([this]() {
|
|
11
|
-
for (;;) {
|
|
12
|
-
std::function<void()> task;
|
|
13
|
-
{
|
|
14
|
-
std::unique_lock<std::mutex> lock(queueMutex_);
|
|
15
|
-
condition_.wait(lock, [this]() { return stop_ || !tasks_.empty(); });
|
|
16
|
-
if (stop_ && tasks_.empty()) {
|
|
17
|
-
return;
|
|
18
|
-
}
|
|
19
|
-
task = std::move(tasks_.front());
|
|
20
|
-
tasks_.pop();
|
|
21
|
-
}
|
|
22
|
-
task();
|
|
23
|
-
}
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
ThreadPool::~ThreadPool() {
|
|
29
|
-
{
|
|
30
|
-
std::unique_lock<std::mutex> lock(queueMutex_);
|
|
31
|
-
stop_ = true;
|
|
32
|
-
}
|
|
33
|
-
condition_.notify_all();
|
|
34
|
-
for (std::thread& worker : workers_) {
|
|
35
|
-
if (worker.joinable()) {
|
|
36
|
-
worker.join();
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
} // namespace margelo::nitro::onnx::speech
|
package/cpp/ThreadPool.hpp
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
// ------------------------------------------------------------------------------
|
|
2
|
-
// ThreadPool.hpp
|
|
3
|
-
// A fixed-size thread pool used to run all heavy native inference tasks.
|
|
4
|
-
// Keeping inference off the JS thread is a core requirement of this module.
|
|
5
|
-
// ------------------------------------------------------------------------------
|
|
6
|
-
#pragma once
|
|
7
|
-
|
|
8
|
-
#include <atomic>
|
|
9
|
-
#include <condition_variable>
|
|
10
|
-
#include <functional>
|
|
11
|
-
#include <future>
|
|
12
|
-
#include <mutex>
|
|
13
|
-
#include <queue>
|
|
14
|
-
#include <thread>
|
|
15
|
-
#include <vector>
|
|
16
|
-
|
|
17
|
-
namespace margelo::nitro::onnx::speech {
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Minimal thread pool for background inference work.
|
|
21
|
-
* Tasks are enqueued as std::function<void()> and executed by worker threads.
|
|
22
|
-
*/
|
|
23
|
-
class ThreadPool final {
|
|
24
|
-
public:
|
|
25
|
-
explicit ThreadPool(size_t threadCount = std::thread::hardware_concurrency());
|
|
26
|
-
~ThreadPool();
|
|
27
|
-
|
|
28
|
-
ThreadPool(const ThreadPool&) = delete;
|
|
29
|
-
ThreadPool& operator=(const ThreadPool&) = delete;
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Schedule a task on the pool and obtain a future for the result.
|
|
33
|
-
* @tparam F Callable type.
|
|
34
|
-
* @tparam Args Argument types.
|
|
35
|
-
* @return std::future for the callable result.
|
|
36
|
-
*/
|
|
37
|
-
template <typename F, typename... Args>
|
|
38
|
-
auto enqueue(F&& f, Args&&... args) -> std::future<std::invoke_result_t<F, Args...>> {
|
|
39
|
-
using ReturnType = std::invoke_result_t<F, Args...>;
|
|
40
|
-
auto task = std::make_shared<std::packaged_task<ReturnType()>>(
|
|
41
|
-
std::bind(std::forward<F>(f), std::forward<Args>(args)...));
|
|
42
|
-
std::future<ReturnType> result = task->get_future();
|
|
43
|
-
{
|
|
44
|
-
std::unique_lock<std::mutex> lock(queueMutex_);
|
|
45
|
-
if (stop_) {
|
|
46
|
-
throw std::runtime_error("Cannot enqueue on stopped ThreadPool");
|
|
47
|
-
}
|
|
48
|
-
tasks_.emplace([task]() { (*task)(); });
|
|
49
|
-
}
|
|
50
|
-
condition_.notify_one();
|
|
51
|
-
return result;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
private:
|
|
55
|
-
std::vector<std::thread> workers_;
|
|
56
|
-
std::queue<std::function<void()>> tasks_;
|
|
57
|
-
std::mutex queueMutex_;
|
|
58
|
-
std::condition_variable condition_;
|
|
59
|
-
std::atomic<bool> stop_{false};
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
} // namespace margelo::nitro::onnx::speech
|