fix: 修复 SenseVoiceEngine Windows 编译错误
- Impl 的 QMutex 移出 HAVE_ONNXRUNTIME 条件编译块 - loadModelSync/loadModelAsync 中的 ONNX 成员访问添加 #ifdef 保护 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
a56f273c45
commit
09677e3620
@ -184,9 +184,9 @@ struct SenseVoiceEngine::Impl {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
QMutex mutex;
|
||||
#endif
|
||||
};
|
||||
|
||||
SenseVoiceEngine::SenseVoiceEngine(QObject* parent)
|
||||
@ -206,14 +206,17 @@ bool SenseVoiceEngine::loadModelSync(const QString& modelPath,
|
||||
if (loaded_) {
|
||||
LOG_WARNING(kTag, "模型已加载,先卸载再加载");
|
||||
// 内联清理,避免调用 unloadModel() 导致 mutex 递归死锁
|
||||
#ifdef HAVE_ONNXRUNTIME
|
||||
impl_->session.reset();
|
||||
impl_->sessionOptions.reset();
|
||||
impl_->env.reset();
|
||||
impl_->features.reset();
|
||||
impl_->tokenizer = SenseVoiceTokenizer();
|
||||
#endif
|
||||
loaded_ = false;
|
||||
}
|
||||
|
||||
#ifdef HAVE_ONNXRUNTIME
|
||||
QString errorMsg;
|
||||
bool success = impl_->loadInWorker(modelPath, tokensPath, device, numThreads, errorMsg);
|
||||
loaded_ = success;
|
||||
@ -225,6 +228,11 @@ bool SenseVoiceEngine::loadModelSync(const QString& modelPath,
|
||||
emit error(errorMsg);
|
||||
}
|
||||
return success;
|
||||
#else
|
||||
(void)modelPath; (void)tokensPath; (void)device; (void)numThreads;
|
||||
LOG_ERROR(kTag, "ONNX Runtime 未编译启用");
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
void SenseVoiceEngine::loadModelAsync(const QString& modelPath,
|
||||
@ -235,14 +243,17 @@ void SenseVoiceEngine::loadModelAsync(const QString& modelPath,
|
||||
if (loaded_) {
|
||||
LOG_WARNING(kTag, "模型已加载,先卸载再加载");
|
||||
// 内联清理,避免调用 unloadModel() 导致 mutex 递归死锁
|
||||
#ifdef HAVE_ONNXRUNTIME
|
||||
impl_->session.reset();
|
||||
impl_->sessionOptions.reset();
|
||||
impl_->env.reset();
|
||||
impl_->features.reset();
|
||||
impl_->tokenizer = SenseVoiceTokenizer();
|
||||
#endif
|
||||
loaded_ = false;
|
||||
}
|
||||
|
||||
#ifdef HAVE_ONNXRUNTIME
|
||||
LOG_INFO(kTag, QString("异步加载 SenseVoice 模型: %1").arg(modelPath));
|
||||
|
||||
QFuture<void> future = QtConcurrent::run([this, modelPath, tokensPath, device, numThreads]() {
|
||||
@ -259,6 +270,10 @@ void SenseVoiceEngine::loadModelAsync(const QString& modelPath,
|
||||
}
|
||||
}, Qt::QueuedConnection);
|
||||
});
|
||||
#else
|
||||
(void)modelPath; (void)tokensPath; (void)device; (void)numThreads;
|
||||
LOG_ERROR(kTag, "ONNX Runtime 未编译启用");
|
||||
#endif
|
||||
}
|
||||
|
||||
void SenseVoiceEngine::unloadModel() {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user