Files
QSmartAssistant/KWSManager.h
lizhuoran e92cb0b4e5 feat: 完整的语音助手系统实现
主要功能:
-  离线语音识别 (ASR) - Paraformer中文模型
-  在线语音识别 - Streaming Paraformer中英文双语模型
-  语音合成 (TTS) - MeloTTS中英文混合模型
-  语音唤醒 (KWS) - Zipformer关键词检测模型
-  麦克风录音功能 - 支持多种格式和实时转换
-  模型设置界面 - 完整的图形化配置管理

KWS优化亮点:
- 🎯 成功实现关键词检测 (测试成功率10%→预期50%+)
- ⚙️ 可调参数: 阈值、活跃路径、尾随空白、分数权重、线程数
- 🔧 智能参数验证和实时反馈
- 📊 详细的调试信息和成功统计
- 🎛️ 用户友好的设置界面

技术架构:
- 模块化设计: ASRManager, TTSManager, KWSManager
- 实时音频处理: 自动格式转换 (任意格式→16kHz单声道)
- 智能设备检测: 自动选择最佳音频格式
- 完整资源管理: 正确的创建和销毁流程
- 跨平台支持: macOS优化的音频权限处理

界面特性:
- 2×2网格布局: ASR、TTS、录音、KWS四大功能模块
- 分离录音设置: 设备参数 + 输出格式独立配置
- 实时状态显示: 音频电平、处理次数、成功统计
- 详细的用户指导和错误提示
2025-12-23 13:47:00 +08:00

61 lines
1.9 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#ifndef KWSMANAGER_H
#define KWSMANAGER_H
#include <QObject>
#include <QString>
#include <QDebug>
#include "sherpa-onnx/c-api/c-api.h"
class KWSManager : public QObject {
Q_OBJECT
public:
explicit KWSManager(QObject* parent = nullptr);
~KWSManager();
// 初始化KWS模型
bool initialize();
bool initialize(const QString& modelPath, const QString& tokensPath, const QString& keywordsPath);
// 检查是否已初始化
bool isInitialized() const;
// 创建和销毁KWS流
const SherpaOnnxKeywordSpotter* createKeywordSpotter();
void destroyKeywordSpotter(const SherpaOnnxKeywordSpotter* spotter);
// 创建和销毁KWS流
const SherpaOnnxOnlineStream* createKeywordStream(const SherpaOnnxKeywordSpotter* spotter);
void destroyKeywordStream(const SherpaOnnxOnlineStream* stream);
// 音频处理
void acceptWaveform(const SherpaOnnxOnlineStream* stream, const float* samples, int sampleCount);
bool isReady(const SherpaOnnxOnlineStream* stream, const SherpaOnnxKeywordSpotter* spotter);
void decode(const SherpaOnnxOnlineStream* stream, const SherpaOnnxKeywordSpotter* spotter);
// 获取检测结果
QString getResult(const SherpaOnnxOnlineStream* stream, const SherpaOnnxKeywordSpotter* spotter);
// 获取部分识别文本类似ASR的部分结果
QString getPartialText(const SherpaOnnxOnlineStream* stream, const SherpaOnnxKeywordSpotter* spotter);
// 重置流
void reset(const SherpaOnnxOnlineStream* stream, const SherpaOnnxKeywordSpotter* spotter);
private:
void cleanup();
QString getDefaultModelPath() const;
QString getDefaultTokensPath() const;
QString getDefaultKeywordsPath() const;
// KWS配置和模型
SherpaOnnxKeywordSpotterConfig kwsConfig;
bool initialized;
// 模型路径
QString modelPath;
QString tokensPath;
QString keywordsPath;
};
#endif // KWSMANAGER_H