#ifndef ASRMANAGER_H
#define ASRMANAGER_H

#include <QString>
#include <QObject>
#include <string>
#include "sherpa-onnx/c-api/c-api.h"

class ASRManager : public QObject {
    Q_OBJECT

public:
    explicit ASRManager(QObject* parent = nullptr);
    ~ASRManager();

    bool initialize();
    QString recognizeWavFile(const QString& filePath);
    bool isInitialized() const { return asrRecognizer != nullptr; }

    // 在线识别相关
    bool initializeOnlineRecognizer();
    bool isOnlineInitialized() const { return onlineAsrRecognizer != nullptr; }
    const SherpaOnnxOnlineStream* createOnlineStream();
    void destroyOnlineStream(const SherpaOnnxOnlineStream* stream);
    
    // 在线识别处理
    void acceptWaveform(const SherpaOnnxOnlineStream* stream, const float* samples, int32_t sampleCount);
    bool isStreamReady(const SherpaOnnxOnlineStream* stream);
    void decodeStream(const SherpaOnnxOnlineStream* stream);
    QString getStreamResult(const SherpaOnnxOnlineStream* stream);
    void inputFinished(const SherpaOnnxOnlineStream* stream);
    bool isEndpoint(const SherpaOnnxOnlineStream* stream);

private:
    void cleanup();

    // 离线ASR相关
    SherpaOnnxOfflineRecognizer* asrRecognizer = nullptr;
    SherpaOnnxOfflineRecognizerConfig asrConfig;
    std::string asrModelPathStd;
    std::string asrTokensPathStd;

    // 在线ASR相关
    SherpaOnnxOnlineRecognizer* onlineAsrRecognizer = nullptr;
    SherpaOnnxOnlineRecognizerConfig onlineAsrConfig;
    std::string onlineEncoderPathStd;
    std::string onlineDecoderPathStd;
    std::string onlineTokensPathStd;
};

#endif // ASRMANAGER_H