/*
 * Copyright (C) 2020, KylinSoft Co., Ltd.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */
#ifndef RECORDER_H
#define RECORDER_H

#include <QtMultimedia/QAudioFormat>
#include <QtMultimedia/QAudioInput>

#include <QObject>
#include <QtMultimedia/QMediaRecorder>//录音
#include <QAudioBuffer>//音频缓存
#include <QMediaCaptureSession> //音频探针
#include <QUdpSocket> //UDP套接字
#include <QHostAddress> //主机地址
#include <QUrl> //文件地址
#include <QFile>
#include <QBuffer>

#include <kylin-ai/coreai/speech/recognizer.h>
#include <kylin-ai/coreai/speech/audioconfig.h>
#include <kylin-ai/coreai/speech/error.h>
#include <kylin-ai/coreai/speech/result.h>
#include "msgpane.h"
#include "qaudiodevice.h"


#define TEST 1

class Recorder : public QObject
{
    Q_OBJECT
public:
    explicit Recorder(QObject *parent = nullptr);
    ~Recorder();
    void startRecord();
    void stopRecord();
    void closeSession();

signals:
    void sigSendTmpMsg(const QString str);  //语音识别中的结果
    void sigSendMsg(const QString str);     //语音识别修正后的结果
    void reply(const QString &message, bool is_end, int index, int errorCode, QString model = "");
    void sigCancelSendVoice();  //取消语音输入
    void sigIsStartTimer();     //向前端发送信号，启动30s计时器

private:
    bool initSession();

private:
    SpeechRecognitionSession *session = nullptr;
    AudioConfig *config = nullptr;
    QAudioDevice devInfo;

};

#endif // RECORDER_H
