#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