一些检查失败了
automerge / automerge (push) Has been cancelled
react-native-android-build-apk / AssembleRelease (push) Has been cancelled
Build macOS M1 / Main (push) Has been cancelled
Joplin Continuous Integration / Main (macos-15-intel) (push) Has been cancelled
Joplin Continuous Integration / Main (ubuntu-22.04) (push) Has been cancelled
Joplin Continuous Integration / Main (ubuntu-22.04-arm) (push) Has been cancelled
Joplin Continuous Integration / Main (windows-11-vs2026-arm) (push) Has been cancelled
Joplin Continuous Integration / Main (windows-2025) (push) Has been cancelled
Joplin Continuous Integration / ServerDockerImage (ubuntu-22.04) (push) Has been cancelled
Joplin Continuous Integration / ServerDockerImage (ubuntu-22.04-arm) (push) Has been cancelled
Joplin UI tests / Main (ubuntu-22.04) (push) Has been cancelled
Joplin UI tests / Main (windows-2025) (push) Has been cancelled
Joplin UI tests / Mobile (push) Has been cancelled
Close stale issues / ProcessStaleIssues (push) Has been cancelled
49 行
1.4 KiB
C++
49 行
1.4 KiB
C++
#include "HybridWhisperSession.hpp"
|
|
#include "androidUtil.h"
|
|
#include <NitroModules/ArrayBuffer.hpp>
|
|
|
|
using namespace margelo::nitro::whispervoicetyping;
|
|
|
|
struct HybridWhisperSession::State_ {
|
|
State_(const SessionOptions& options)
|
|
: session_(options.modelPath, options.locale, options.prompt, options.shortAudioContext)
|
|
{};
|
|
|
|
void addAudio(ArrayBuffer& data);
|
|
|
|
std::mutex mutex_;
|
|
WhisperSession session_;
|
|
};
|
|
|
|
void HybridWhisperSession::State_::addAudio(ArrayBuffer& data) {
|
|
float* dataFloat = reinterpret_cast<float*>(data.data());
|
|
size_t sizeFloats = data.size() / sizeof(float);
|
|
|
|
if (dataFloat == nullptr) {
|
|
throw std::logic_error("Attempting to add audio from a source that has already been deleted.");
|
|
}
|
|
|
|
LOGD("Add audio (size %zu)", sizeFloats);
|
|
session_.addAudio(dataFloat, sizeFloats);
|
|
}
|
|
|
|
HybridWhisperSession::HybridWhisperSession(
|
|
const SessionOptions& options
|
|
)
|
|
: HybridObject(TAG),
|
|
state_(std::make_shared<HybridWhisperSession::State_>(options))
|
|
{ }
|
|
|
|
void HybridWhisperSession::pushAudio(const std::shared_ptr<ArrayBuffer>& audio) {
|
|
std::lock_guard<std::mutex> lock { state_->mutex_ };
|
|
|
|
state_->addAudio(*audio);
|
|
}
|
|
|
|
std::shared_ptr<Promise<std::string>> HybridWhisperSession::convertNext() {
|
|
return Promise<std::string>::async([state = state_] () -> std::string {
|
|
std::lock_guard<std::mutex> lock { state->mutex_ };
|
|
return state->session_.transcribeNextChunk();
|
|
});
|
|
}
|