react-native-nitro-onnx 0.1.1 → 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/README.md +101 -31
- package/android/CMakeLists.txt +5 -3
- 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 +24 -15
- package/cpp/AsrEngine.cpp +150 -58
- package/cpp/AsrEngine.hpp +12 -7
- package/cpp/AudioFileReader.cpp +4 -0
- package/cpp/ModelSingleton.hpp +14 -0
- package/cpp/NitroOnnxSpeech.cpp +8 -9
- package/cpp/NitroOnnxSpeech.hpp +0 -6
- package/cpp/OfflineAsr.cpp +9 -12
- 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 +13 -10
- package/cpp/StreamingAsr.hpp +1 -1
- package/cpp/Tts.cpp +38 -10
- package/cpp/Tts.hpp +2 -1
- package/cpp/TtsEngine.cpp +15 -7
- package/cpp/TtsEngine.hpp +18 -5
- package/cpp/Vad.cpp +11 -11
- package/cpp/Vad.hpp +1 -1
- package/cpp/VadEngine.cpp +26 -33
- package/cpp/VadEngine.hpp +8 -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/package.json +4 -3
- package/scripts/generate-version.js +22 -0
- package/src/specs/OnnxSpeech.nitro.ts +25 -8
- package/cpp/ThreadPool.cpp +0 -41
- package/cpp/ThreadPool.hpp +0 -62
|
@@ -118,7 +118,12 @@ export interface AsrModelConfig {
|
|
|
118
118
|
encoder?: string;
|
|
119
119
|
decoder?: string;
|
|
120
120
|
joiner?: string;
|
|
121
|
-
/**
|
|
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
|
+
*/
|
|
122
127
|
model?: string;
|
|
123
128
|
/** NeMo config file (.yaml). */
|
|
124
129
|
config?: string;
|
|
@@ -136,7 +141,7 @@ export interface AsrModelConfig {
|
|
|
136
141
|
debug?: boolean;
|
|
137
142
|
/**
|
|
138
143
|
* Execution provider for ONNX Runtime.
|
|
139
|
-
* Default: "
|
|
144
|
+
* Default: "nnapi" on Android (or "qnn" when built with -DQNN_ROOT),
|
|
140
145
|
* "coreml" on iOS (Apple Neural Engine, unsupported ops fall back to CPU).
|
|
141
146
|
* Pass "cpu" explicitly to disable NPU acceleration.
|
|
142
147
|
*/
|
|
@@ -258,9 +263,8 @@ export interface TtsModelConfig {
|
|
|
258
263
|
debug?: boolean;
|
|
259
264
|
/**
|
|
260
265
|
* Execution provider for ONNX Runtime.
|
|
261
|
-
* Default: "
|
|
262
|
-
*
|
|
263
|
-
* Pass "cpu" explicitly to disable NPU acceleration.
|
|
266
|
+
* Default: "cpu" on Android / Linux, "coreml" on iOS.
|
|
267
|
+
* Pass a provider explicitly to enable NPU acceleration.
|
|
264
268
|
*/
|
|
265
269
|
provider?: string;
|
|
266
270
|
}
|
|
@@ -279,7 +283,13 @@ export interface Tts extends HybridObject<SpeechPlatforms> {
|
|
|
279
283
|
isLoaded(): boolean;
|
|
280
284
|
/** Synthesize text into audio on a background thread. Optional speed override. */
|
|
281
285
|
synthesize(text: string, speed?: number): Promise<TtsResult>;
|
|
282
|
-
/**
|
|
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
|
+
*/
|
|
283
293
|
synthesizeWithSpeaker(text: string, speakerId: string, speed?: number): Promise<TtsResult>;
|
|
284
294
|
/** Save TTS result as a WAV file at the given path. */
|
|
285
295
|
saveWav(result: TtsResult, path: string): Promise<void>;
|
|
@@ -313,9 +323,16 @@ export interface SpeakerManager extends HybridObject<SpeechPlatforms> {
|
|
|
313
323
|
isLoaded(): boolean;
|
|
314
324
|
/** Compute an embedding from reference 16 kHz mono f32 PCM audio. */
|
|
315
325
|
computeEmbedding(samples: ArrayBuffer): Promise<ArrayBuffer>;
|
|
316
|
-
/**
|
|
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
|
+
*/
|
|
317
331
|
registerSpeaker(id: string, name: string, embedding: ArrayBuffer): Promise<RegisteredSpeaker>;
|
|
318
|
-
/**
|
|
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
|
+
*/
|
|
319
336
|
registerSpeakerFromFile(id: string, name: string, path: string): Promise<RegisteredSpeaker>;
|
|
320
337
|
/** List registered speakers. */
|
|
321
338
|
listSpeakers(): Promise<RegisteredSpeaker[]>;
|
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
|