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
package/cpp/TtsEngine.cpp
CHANGED
|
@@ -51,9 +51,6 @@ ModelSingleton<const SherpaOnnxOfflineTts> gTtsCache;
|
|
|
51
51
|
|
|
52
52
|
} // namespace
|
|
53
53
|
|
|
54
|
-
TtsEngine::TtsEngine(std::shared_ptr<ThreadPool> threadPool)
|
|
55
|
-
: threadPool_(std::move(threadPool)) {}
|
|
56
|
-
|
|
57
54
|
TtsEngine::~TtsEngine() {
|
|
58
55
|
unload();
|
|
59
56
|
}
|
|
@@ -62,8 +59,7 @@ void TtsEngine::load(const TtsEngineConfig& config) {
|
|
|
62
59
|
unload();
|
|
63
60
|
config_ = config;
|
|
64
61
|
|
|
65
|
-
|
|
66
|
-
auto cached = gTtsCache.getOrCreate(key, [this](const std::string&) {
|
|
62
|
+
auto cached = gTtsCache.getOrCreate(config_.cacheSignature(), [this](const std::string&) {
|
|
67
63
|
SherpaOnnxOfflineTtsConfig c;
|
|
68
64
|
std::memset(&c, 0, sizeof(c));
|
|
69
65
|
|
|
@@ -75,7 +71,6 @@ void TtsEngine::load(const TtsEngineConfig& config) {
|
|
|
75
71
|
std::string voices = joinPath(config_.modelDir, config_.voices);
|
|
76
72
|
std::string espeakNgData = joinPath(config_.modelDir, config_.espeakNgData);
|
|
77
73
|
std::string dictDir = joinPath(config_.modelDir, config_.dictDir);
|
|
78
|
-
std::string configPath = joinPath(config_.modelDir, config_.config);
|
|
79
74
|
|
|
80
75
|
std::string lmMain = joinPath(config_.modelDir, config_.lmMain);
|
|
81
76
|
std::string lmFlow = joinPath(config_.modelDir, config_.lmFlow);
|
|
@@ -171,10 +166,17 @@ bool TtsEngine::isLoaded() const {
|
|
|
171
166
|
return tts_ != nullptr;
|
|
172
167
|
}
|
|
173
168
|
|
|
174
|
-
TtsEngineResult TtsEngine::synthesize(
|
|
169
|
+
TtsEngineResult TtsEngine::synthesize(
|
|
170
|
+
const std::string& text,
|
|
171
|
+
int32_t speakerId,
|
|
172
|
+
float speed,
|
|
173
|
+
const TtsReferenceAudio* referenceAudio) {
|
|
175
174
|
if (tts_ == nullptr) {
|
|
176
175
|
throw std::runtime_error("TTS not loaded");
|
|
177
176
|
}
|
|
177
|
+
if (text.empty()) {
|
|
178
|
+
throw std::invalid_argument("TTS text must not be empty");
|
|
179
|
+
}
|
|
178
180
|
|
|
179
181
|
const int32_t sid = speakerId >= 0 ? speakerId : config_.speakerId;
|
|
180
182
|
const float playbackSpeed = speed > 0.0f ? speed : config_.speed;
|
|
@@ -183,6 +185,12 @@ TtsEngineResult TtsEngine::synthesize(const std::string& text, int32_t speakerId
|
|
|
183
185
|
std::memset(&genConfig, 0, sizeof(genConfig));
|
|
184
186
|
genConfig.sid = sid;
|
|
185
187
|
genConfig.speed = playbackSpeed;
|
|
188
|
+
if (referenceAudio != nullptr && !referenceAudio->samples.empty()) {
|
|
189
|
+
genConfig.reference_audio = referenceAudio->samples.data();
|
|
190
|
+
genConfig.reference_audio_len = static_cast<int32_t>(referenceAudio->samples.size());
|
|
191
|
+
genConfig.reference_sample_rate =
|
|
192
|
+
referenceAudio->sampleRate > 0 ? referenceAudio->sampleRate : 16000;
|
|
193
|
+
}
|
|
186
194
|
|
|
187
195
|
const SherpaOnnxGeneratedAudio* audio = SherpaOnnxOfflineTtsGenerateWithConfig(
|
|
188
196
|
tts_.get(), text.c_str(), &genConfig, nullptr, nullptr);
|
package/cpp/TtsEngine.hpp
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
// ------------------------------------------------------------------------------
|
|
2
2
|
// TtsEngine.hpp
|
|
3
3
|
// Text-to-speech wrapper backed by sherpa-onnx OfflineTts.
|
|
4
|
-
// Supports Kokoro, VITS, Matcha, Pocket and ZipVoice
|
|
4
|
+
// Supports Kokoro, VITS, Matcha, Pocket and ZipVoice models.
|
|
5
5
|
// ------------------------------------------------------------------------------
|
|
6
6
|
#pragma once
|
|
7
7
|
|
|
8
8
|
#include "AudioUtils.hpp"
|
|
9
9
|
#include "ModelSingleton.hpp"
|
|
10
|
-
#include "ThreadPool.hpp"
|
|
11
10
|
|
|
12
11
|
#include "TtsModelType.hpp"
|
|
13
12
|
|
|
@@ -51,6 +50,11 @@ struct TtsEngineConfig {
|
|
|
51
50
|
#else
|
|
52
51
|
std::string provider = "cpu";
|
|
53
52
|
#endif
|
|
53
|
+
|
|
54
|
+
std::string cacheSignature() const {
|
|
55
|
+
return modelDir + "|" + std::to_string(static_cast<int>(type)) + "|" + provider + "|" +
|
|
56
|
+
std::to_string(numThreads) + "|" + std::to_string(outputSampleRate);
|
|
57
|
+
}
|
|
54
58
|
};
|
|
55
59
|
|
|
56
60
|
/** Native synthesis result (samples are kept as a float vector). */
|
|
@@ -60,10 +64,16 @@ struct TtsEngineResult {
|
|
|
60
64
|
double durationMs = 0.0;
|
|
61
65
|
};
|
|
62
66
|
|
|
67
|
+
/** Optional zero-shot reference audio for voice-cloning models (e.g. Pocket). */
|
|
68
|
+
struct TtsReferenceAudio {
|
|
69
|
+
std::vector<float> samples;
|
|
70
|
+
int32_t sampleRate = 16000;
|
|
71
|
+
};
|
|
72
|
+
|
|
63
73
|
/** Text-to-speech engine. */
|
|
64
74
|
class TtsEngine final {
|
|
65
75
|
public:
|
|
66
|
-
|
|
76
|
+
TtsEngine() = default;
|
|
67
77
|
~TtsEngine();
|
|
68
78
|
|
|
69
79
|
TtsEngine(const TtsEngine&) = delete;
|
|
@@ -71,11 +81,14 @@ class TtsEngine final {
|
|
|
71
81
|
|
|
72
82
|
void load(const TtsEngineConfig& config);
|
|
73
83
|
bool isLoaded() const;
|
|
74
|
-
TtsEngineResult synthesize(
|
|
84
|
+
TtsEngineResult synthesize(
|
|
85
|
+
const std::string& text,
|
|
86
|
+
int32_t speakerId,
|
|
87
|
+
float speed,
|
|
88
|
+
const TtsReferenceAudio* referenceAudio = nullptr);
|
|
75
89
|
void unload();
|
|
76
90
|
|
|
77
91
|
private:
|
|
78
|
-
std::shared_ptr<ThreadPool> threadPool_;
|
|
79
92
|
TtsEngineConfig config_;
|
|
80
93
|
std::shared_ptr<const SherpaOnnxOfflineTts> tts_;
|
|
81
94
|
};
|
package/cpp/Vad.cpp
CHANGED
|
@@ -32,8 +32,7 @@ std::vector<VadSegment> toVadSegments(const std::vector<VadEngineSegment>& nativ
|
|
|
32
32
|
|
|
33
33
|
} // namespace
|
|
34
34
|
|
|
35
|
-
Vad::Vad(
|
|
36
|
-
: HybridObject(TAG), engine_(std::move(threadPool)) {}
|
|
35
|
+
Vad::Vad() : HybridObject(TAG) {}
|
|
37
36
|
|
|
38
37
|
Vad::~Vad() {
|
|
39
38
|
engine_.dispose();
|
|
@@ -41,12 +40,12 @@ Vad::~Vad() {
|
|
|
41
40
|
|
|
42
41
|
std::shared_ptr<Promise<void>> Vad::initialize(const VadConfig& config) {
|
|
43
42
|
currentConfig_ = config;
|
|
44
|
-
return Promise<void>::async([
|
|
43
|
+
return Promise<void>::async([self = shared_cast<Vad>(), config]() {
|
|
45
44
|
// Use the bundled silero_vad.onnx when no custom path is provided.
|
|
46
45
|
const std::string& resDir = getResourceDir();
|
|
47
46
|
const std::string modelPath = config.modelPath.value_or(
|
|
48
47
|
resDir.empty() ? "silero_vad.onnx" : resDir + "/silero_vad.onnx");
|
|
49
|
-
engine_.initialize(
|
|
48
|
+
self->engine_.initialize(
|
|
50
49
|
{
|
|
51
50
|
.modelPath = modelPath,
|
|
52
51
|
.threshold = static_cast<float>(config.threshold.value_or(0.5)),
|
|
@@ -55,7 +54,7 @@ std::shared_ptr<Promise<void>> Vad::initialize(const VadConfig& config) {
|
|
|
55
54
|
.preBufferMs = static_cast<int32_t>(config.preBufferMs.value_or(300.0)),
|
|
56
55
|
.debug = config.debug.value_or(false),
|
|
57
56
|
},
|
|
58
|
-
|
|
57
|
+
self);
|
|
59
58
|
});
|
|
60
59
|
}
|
|
61
60
|
|
|
@@ -64,19 +63,20 @@ bool Vad::isInitialized() {
|
|
|
64
63
|
}
|
|
65
64
|
|
|
66
65
|
std::shared_ptr<Promise<void>> Vad::process(const std::shared_ptr<ArrayBuffer>& samples) {
|
|
67
|
-
return Promise<void>::async([
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
engine_.acceptWaveform(floatSamples);
|
|
66
|
+
return Promise<void>::async([self = shared_cast<Vad>(), samples]() {
|
|
67
|
+
auto floatSamples = bytesToFloatVector(samples->data(), samples->size());
|
|
68
|
+
self->engine_.acceptWaveform(std::move(floatSamples));
|
|
71
69
|
});
|
|
72
70
|
}
|
|
73
71
|
|
|
74
72
|
std::shared_ptr<Promise<std::vector<VadSegment>>> Vad::pullSegments() {
|
|
75
|
-
return Promise<std::vector<VadSegment>>::async([
|
|
73
|
+
return Promise<std::vector<VadSegment>>::async([self = shared_cast<Vad>()]() {
|
|
74
|
+
return toVadSegments(self->engine_.pullSegments());
|
|
75
|
+
});
|
|
76
76
|
}
|
|
77
77
|
|
|
78
78
|
std::shared_ptr<Promise<void>> Vad::reset() {
|
|
79
|
-
return Promise<void>::async([
|
|
79
|
+
return Promise<void>::async([self = shared_cast<Vad>()]() { self->engine_.reset(); });
|
|
80
80
|
}
|
|
81
81
|
|
|
82
82
|
std::optional<std::function<void(const VadSegment& /* segment */)>> Vad::getOnSpeechStart() {
|
package/cpp/Vad.hpp
CHANGED
package/cpp/VadEngine.cpp
CHANGED
|
@@ -5,7 +5,6 @@
|
|
|
5
5
|
|
|
6
6
|
#include "sherpa-onnx/c-api/c-api.h"
|
|
7
7
|
|
|
8
|
-
#include <algorithm>
|
|
9
8
|
#include <cstring>
|
|
10
9
|
#include <stdexcept>
|
|
11
10
|
|
|
@@ -17,9 +16,6 @@ constexpr int32_t kSampleRate = 16000;
|
|
|
17
16
|
|
|
18
17
|
} // namespace
|
|
19
18
|
|
|
20
|
-
VadEngine::VadEngine(std::shared_ptr<ThreadPool> threadPool)
|
|
21
|
-
: threadPool_(std::move(threadPool)) {}
|
|
22
|
-
|
|
23
19
|
VadEngine::~VadEngine() {
|
|
24
20
|
dispose();
|
|
25
21
|
}
|
|
@@ -30,7 +26,7 @@ void VadEngine::initialize(const VadEngineConfig& config, std::shared_ptr<VadLis
|
|
|
30
26
|
config_ = config;
|
|
31
27
|
listener_ = std::move(listener);
|
|
32
28
|
preBufferCapacity_ = static_cast<size_t>(msToSamples(config_.preBufferMs));
|
|
33
|
-
preBuffer_.
|
|
29
|
+
preBuffer_.clear();
|
|
34
30
|
streamMs_ = 0.0f;
|
|
35
31
|
inSpeech_ = false;
|
|
36
32
|
|
|
@@ -53,6 +49,7 @@ void VadEngine::initialize(const VadEngineConfig& config, std::shared_ptr<VadLis
|
|
|
53
49
|
|
|
54
50
|
initialized_ = true;
|
|
55
51
|
stop_ = false;
|
|
52
|
+
resetRequested_ = false;
|
|
56
53
|
processorThread_ = std::thread(&VadEngine::processLoop, this);
|
|
57
54
|
}
|
|
58
55
|
|
|
@@ -60,10 +57,10 @@ bool VadEngine::isInitialized() const {
|
|
|
60
57
|
return initialized_.load();
|
|
61
58
|
}
|
|
62
59
|
|
|
63
|
-
void VadEngine::acceptWaveform(
|
|
60
|
+
void VadEngine::acceptWaveform(std::vector<float> samples) {
|
|
64
61
|
{
|
|
65
62
|
std::lock_guard<std::mutex> lock(inputMutex_);
|
|
66
|
-
inputQueue_.emplace(samples);
|
|
63
|
+
inputQueue_.emplace(std::move(samples));
|
|
67
64
|
}
|
|
68
65
|
inputCv_.notify_one();
|
|
69
66
|
}
|
|
@@ -90,12 +87,9 @@ void VadEngine::reset() {
|
|
|
90
87
|
pendingSegments_.clear();
|
|
91
88
|
}
|
|
92
89
|
|
|
93
|
-
|
|
94
|
-
SherpaOnnxVoiceActivityDetectorClear(vad_);
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
// Defer speech-state clearing to the processor thread to avoid a data race.
|
|
90
|
+
// Clear the sherpa VAD on the processor thread to avoid racing with accept.
|
|
98
91
|
resetRequested_ = true;
|
|
92
|
+
inputCv_.notify_one();
|
|
99
93
|
}
|
|
100
94
|
|
|
101
95
|
void VadEngine::dispose() {
|
|
@@ -117,10 +111,21 @@ void VadEngine::processLoop() {
|
|
|
117
111
|
std::vector<float> chunk;
|
|
118
112
|
{
|
|
119
113
|
std::unique_lock<std::mutex> lock(inputMutex_);
|
|
120
|
-
inputCv_.wait(lock, [this]() { return stop_ || !inputQueue_.empty(); });
|
|
114
|
+
inputCv_.wait(lock, [this]() { return stop_ || resetRequested_ || !inputQueue_.empty(); });
|
|
121
115
|
if (stop_) {
|
|
122
116
|
break;
|
|
123
117
|
}
|
|
118
|
+
if (resetRequested_.exchange(false)) {
|
|
119
|
+
if (vad_) {
|
|
120
|
+
SherpaOnnxVoiceActivityDetectorClear(vad_);
|
|
121
|
+
}
|
|
122
|
+
inSpeech_ = false;
|
|
123
|
+
currentSpeechSamples_.clear();
|
|
124
|
+
streamMs_ = 0.0f;
|
|
125
|
+
}
|
|
126
|
+
if (inputQueue_.empty()) {
|
|
127
|
+
continue;
|
|
128
|
+
}
|
|
124
129
|
chunk = std::move(inputQueue_.front());
|
|
125
130
|
inputQueue_.pop();
|
|
126
131
|
}
|
|
@@ -129,20 +134,13 @@ void VadEngine::processLoop() {
|
|
|
129
134
|
continue;
|
|
130
135
|
}
|
|
131
136
|
|
|
132
|
-
if (resetRequested_.exchange(false)) {
|
|
133
|
-
inSpeech_ = false;
|
|
134
|
-
currentSpeechSamples_.clear();
|
|
135
|
-
streamMs_ = 0.0f;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
137
|
// Update the sliding pre-buffer with the newest chunk. This is the key
|
|
139
138
|
// mechanism that preserves leading audio for onSpeechStart/onSpeechEnd.
|
|
140
139
|
{
|
|
141
140
|
std::lock_guard<std::mutex> lock(preBufferMutex_);
|
|
142
141
|
preBuffer_.insert(preBuffer_.end(), chunk.begin(), chunk.end());
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
preBuffer_.erase(preBuffer_.begin(), preBuffer_.begin() + excess);
|
|
142
|
+
while (preBuffer_.size() > preBufferCapacity_) {
|
|
143
|
+
preBuffer_.pop_front();
|
|
146
144
|
}
|
|
147
145
|
}
|
|
148
146
|
|
|
@@ -151,6 +149,7 @@ void VadEngine::processLoop() {
|
|
|
151
149
|
streamMs_ += samplesToMs(static_cast<int32_t>(chunk.size()));
|
|
152
150
|
|
|
153
151
|
const bool speechDetected = SherpaOnnxVoiceActivityDetectorDetected(vad_) != 0;
|
|
152
|
+
std::shared_ptr<VadListener> listener = listener_.lock();
|
|
154
153
|
|
|
155
154
|
if (speechDetected && !inSpeech_) {
|
|
156
155
|
// Transition to speech: capture the sliding pre-buffer as the start of
|
|
@@ -160,15 +159,15 @@ void VadEngine::processLoop() {
|
|
|
160
159
|
currentSpeechStartMs_ = streamMs_ - samplesToMs(static_cast<int32_t>(chunk.size()));
|
|
161
160
|
{
|
|
162
161
|
std::lock_guard<std::mutex> lock(preBufferMutex_);
|
|
163
|
-
currentSpeechSamples_
|
|
162
|
+
currentSpeechSamples_.assign(preBuffer_.begin(), preBuffer_.end());
|
|
164
163
|
}
|
|
165
164
|
|
|
166
165
|
VadEngineSegment startSegment;
|
|
167
166
|
startSegment.startMs = currentSpeechStartMs_ - samplesToMs(static_cast<int32_t>(currentSpeechSamples_.size()));
|
|
168
167
|
startSegment.endMs = currentSpeechStartMs_;
|
|
169
168
|
startSegment.samples = currentSpeechSamples_;
|
|
170
|
-
if (
|
|
171
|
-
|
|
169
|
+
if (listener) {
|
|
170
|
+
listener->onSpeechStart(startSegment);
|
|
172
171
|
}
|
|
173
172
|
}
|
|
174
173
|
|
|
@@ -200,8 +199,8 @@ void VadEngine::processLoop() {
|
|
|
200
199
|
std::lock_guard<std::mutex> lock(outputMutex_);
|
|
201
200
|
pendingSegments_.push_back(endSegment);
|
|
202
201
|
}
|
|
203
|
-
if (
|
|
204
|
-
|
|
202
|
+
if (listener) {
|
|
203
|
+
listener->onSpeechEnd(endSegment);
|
|
205
204
|
}
|
|
206
205
|
|
|
207
206
|
inSpeech_ = false;
|
|
@@ -209,10 +208,4 @@ void VadEngine::processLoop() {
|
|
|
209
208
|
}
|
|
210
209
|
}
|
|
211
210
|
|
|
212
|
-
void VadEngine::flushPreBuffer(std::vector<float>& target) {
|
|
213
|
-
std::lock_guard<std::mutex> lock(preBufferMutex_);
|
|
214
|
-
target.insert(target.end(), preBuffer_.begin(), preBuffer_.end());
|
|
215
|
-
preBuffer_.clear();
|
|
216
|
-
}
|
|
217
|
-
|
|
218
211
|
} // namespace margelo::nitro::onnx::speech
|
package/cpp/VadEngine.hpp
CHANGED
|
@@ -12,9 +12,10 @@
|
|
|
12
12
|
#pragma once
|
|
13
13
|
|
|
14
14
|
#include "AudioUtils.hpp"
|
|
15
|
-
#include "ThreadPool.hpp"
|
|
16
15
|
|
|
16
|
+
#include <atomic>
|
|
17
17
|
#include <condition_variable>
|
|
18
|
+
#include <deque>
|
|
18
19
|
#include <memory>
|
|
19
20
|
#include <mutex>
|
|
20
21
|
#include <optional>
|
|
@@ -62,7 +63,7 @@ class VadListener {
|
|
|
62
63
|
*/
|
|
63
64
|
class VadEngine final {
|
|
64
65
|
public:
|
|
65
|
-
|
|
66
|
+
VadEngine() = default;
|
|
66
67
|
~VadEngine();
|
|
67
68
|
|
|
68
69
|
VadEngine(const VadEngine&) = delete;
|
|
@@ -74,8 +75,8 @@ class VadEngine final {
|
|
|
74
75
|
/** Return true if the VAD has been initialized. */
|
|
75
76
|
bool isInitialized() const;
|
|
76
77
|
|
|
77
|
-
/** Feed a chunk of 16 kHz mono f32 PCM audio. Non-blocking. */
|
|
78
|
-
void acceptWaveform(
|
|
78
|
+
/** Feed a chunk of 16 kHz mono f32 PCM audio. Non-blocking. Takes ownership. */
|
|
79
|
+
void acceptWaveform(std::vector<float> samples);
|
|
79
80
|
|
|
80
81
|
/** Return any buffered segments without waiting for speech end. */
|
|
81
82
|
std::vector<VadEngineSegment> pullSegments();
|
|
@@ -88,11 +89,8 @@ class VadEngine final {
|
|
|
88
89
|
|
|
89
90
|
private:
|
|
90
91
|
void processLoop();
|
|
91
|
-
void flushPreBuffer(std::vector<float>& target);
|
|
92
|
-
void emitSegment();
|
|
93
92
|
|
|
94
|
-
std::
|
|
95
|
-
std::shared_ptr<VadListener> listener_;
|
|
93
|
+
std::weak_ptr<VadListener> listener_;
|
|
96
94
|
|
|
97
95
|
const SherpaOnnxVoiceActivityDetector* vad_ = nullptr;
|
|
98
96
|
VadEngineConfig config_;
|
|
@@ -107,7 +105,7 @@ class VadEngine final {
|
|
|
107
105
|
|
|
108
106
|
// Sliding pre-buffer. Always holds the most recent N milliseconds of audio.
|
|
109
107
|
std::mutex preBufferMutex_;
|
|
110
|
-
std::
|
|
108
|
+
std::deque<float> preBuffer_;
|
|
111
109
|
size_t preBufferCapacity_ = 0;
|
|
112
110
|
|
|
113
111
|
// Output segments waiting to be pulled.
|
|
@@ -117,7 +115,7 @@ class VadEngine final {
|
|
|
117
115
|
// Processor thread.
|
|
118
116
|
std::thread processorThread_;
|
|
119
117
|
|
|
120
|
-
// Stream time tracking.
|
|
118
|
+
// Stream time tracking. Only touched by the processor thread.
|
|
121
119
|
float streamMs_ = 0.0f;
|
|
122
120
|
bool inSpeech_ = false;
|
|
123
121
|
float currentSpeechStartMs_ = 0.0f;
|
package/cpp/Version.hpp
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// ------------------------------------------------------------------------------
|
|
2
|
+
// Version.hpp
|
|
3
|
+
// Generated from package.json by scripts/generate-version.js. DO NOT EDIT.
|
|
4
|
+
// ------------------------------------------------------------------------------
|
|
5
|
+
#pragma once
|
|
6
|
+
|
|
7
|
+
#define NITRO_ONNX_SPEECH_VERSION "0.1.2"
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// ------------------------------------------------------------------------------
|
|
2
2
|
// OnnxSpeechInitializer.mm
|
|
3
3
|
// ------------------------------------------------------------------------------
|
|
4
|
-
// Sets up resource and
|
|
4
|
+
// Sets up resource and document directories for the C++ layer on iOS.
|
|
5
5
|
// Runs at +load time so paths are available before any HybridObject is created.
|
|
6
6
|
// ------------------------------------------------------------------------------
|
|
7
7
|
#import <Foundation/Foundation.h>
|
|
@@ -26,12 +26,24 @@
|
|
|
26
26
|
margelo::nitro::onnx::speech::setResourceDir([[mainBundle resourcePath] UTF8String]);
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
NSString
|
|
32
|
-
|
|
33
|
-
|
|
29
|
+
// Application Support (not Documents): speaker embeddings are derived data
|
|
30
|
+
// and must not be backed up to iCloud.
|
|
31
|
+
NSArray<NSString*>* supportPaths = NSSearchPathForDirectoriesInDomains(
|
|
32
|
+
NSApplicationSupportDirectory, NSUserDomainMask, YES);
|
|
33
|
+
NSString* documentDir = supportPaths.firstObject;
|
|
34
|
+
if (documentDir == nil) {
|
|
35
|
+
return;
|
|
34
36
|
}
|
|
37
|
+
|
|
38
|
+
NSError* error = nil;
|
|
39
|
+
[[NSFileManager defaultManager] createDirectoryAtPath:documentDir
|
|
40
|
+
withIntermediateDirectories:YES
|
|
41
|
+
attributes:nil
|
|
42
|
+
error:&error];
|
|
43
|
+
NSURL* dirURL = [NSURL fileURLWithPath:documentDir isDirectory:YES];
|
|
44
|
+
[dirURL setResourceValue:@YES forKey:NSURLIsExcludedFromBackupKey error:nil];
|
|
45
|
+
|
|
46
|
+
margelo::nitro::onnx::speech::setDocumentDir([documentDir UTF8String]);
|
|
35
47
|
}
|
|
36
48
|
|
|
37
49
|
@end
|
|
@@ -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"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAE/D,0EAA0E;AAC1E,MAAM,MAAM,eAAe,GAAG;IAAE,GAAG,EAAE,KAAK,CAAC;IAAC,OAAO,EAAE,KAAK,CAAA;CAAE,CAAC;AAM7D,qDAAqD;AACrD,MAAM,WAAW,WAAW;IAC1B,uDAAuD;IACvD,UAAU,EAAE,MAAM,CAAC;IACnB,2CAA2C;IAC3C,QAAQ,EAAE,MAAM,CAAC;IACjB,yBAAyB;IACzB,YAAY,EAAE,OAAO,GAAG,OAAO,CAAC;CACjC;AAED,8EAA8E;AAC9E,MAAM,WAAW,MAAM,CAAC,CAAC;IACvB,OAAO,EAAE,OAAO,CAAC;IACjB,IAAI,CAAC,EAAE,CAAC,CAAC;IACT,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAMD,MAAM,WAAW,SAAS;IACxB;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,sEAAsE;IACtE,SAAS,CAAC,EAAE,MAAM,CAAC;IAC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
"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})`);
|