98 lines
3.0 KiB
C++
98 lines
3.0 KiB
C++
#ifndef TJD_UI_APP_LEFUN_AI_MODEL_H
|
|
#define TJD_UI_APP_LEFUN_AI_MODEL_H
|
|
|
|
#include "TjdUiAppLefunAiPresenter.h"
|
|
#include "audio_capturer.h"
|
|
#include "media_thread_adapt.h"
|
|
#include "cmsis_os2.h"
|
|
#include "image_info.h"
|
|
#include "player.h"
|
|
#include <list>
|
|
#include <string>
|
|
#include <fstream>
|
|
#include <iostream>
|
|
#include "ble_api.h"
|
|
|
|
#define MAX_HISTORY 10
|
|
#define LEFUN_AI_STORY_FILE_PATH "/system/lefun_ai_record.json"
|
|
|
|
namespace TJD {
|
|
|
|
typedef struct {
|
|
std::string question;
|
|
std::string answer;
|
|
} QARecord_t;
|
|
|
|
typedef struct {
|
|
QARecord_t records[MAX_HISTORY];
|
|
int total_records; // 当前记录数
|
|
} History;
|
|
|
|
void lefun_ai_data_callback(struct data_flow *data);
|
|
class TjdUiAppLefunAiModel
|
|
{
|
|
public:
|
|
TjdUiAppLefunAiModel() {};
|
|
~TjdUiAppLefunAiModel() {};
|
|
static TjdUiAppLefunAiModel &GetInstance(void)
|
|
{
|
|
static TjdUiAppLefunAiModel instance;
|
|
return instance;
|
|
};
|
|
|
|
int file_exists();
|
|
void AudioInit(void);
|
|
int RecordStart();
|
|
void RecordStop();
|
|
void AudioCaptureProcess(void);
|
|
void RecordDestroy(void);
|
|
void addRecord(History* history, std::string question, std::string answer);
|
|
void displayHistory(const History* history);
|
|
void saveToJson(const History* history, const char* filename);
|
|
void loadFromJson(History* history);
|
|
void createInitialJson(const char* filename);
|
|
uint8_t get_total_records_from_json();
|
|
void RequestIntoLefunAi();
|
|
void LefunAiRequestExitLefunAi();
|
|
void LefunAiRequestIntoAudioTransmit();
|
|
void LefunAiRequestStartAudioTransmit();
|
|
void LefunAiRequestEndAudioTransmit();
|
|
void TransmitAudioData(uint8_t *data, uint16_t len);
|
|
bool GetAiAudioTransFlag();
|
|
void RegisterLefunAiDataCallback(lefun_ai_data_callback_t callback);
|
|
void RegisterLefunAiDataEndCallback(lefun_ai_data_callback_t callback);
|
|
void UnregisterLefunAiDataEndCallback();
|
|
void UnregisterLefunAiDataCallback();
|
|
void ResendAudioData(); // 发送缓存数据的函数
|
|
void DeleDataFlow(void);
|
|
void CloseAutoScreenOff(void) ;
|
|
void OpenAutoScreenOff(void) ;
|
|
friend void lefun_ai_data_callback(struct data_flow *data);
|
|
friend void lefun_ai_data_end_callback(struct data_flow *data);
|
|
private:
|
|
|
|
uint32_t lastTime_ = 0;
|
|
int32_t ret;
|
|
std::vector<uint8_t*> audioCache_; // 用于缓存音频数据
|
|
std::atomic<bool> needStop_{false};
|
|
std::atomic<bool> needPause_{false};
|
|
uint8_t *lefunAiRecordBuffer_{nullptr};
|
|
std::mutex pauseMutex_;
|
|
size_t framesize_{0};
|
|
std::string url_{""};
|
|
std::ofstream pfd_;
|
|
AudioSession sessionId_;
|
|
Audio::AudioInterrupt interrupt_;
|
|
bool recordIsRuning_{false};
|
|
bool audioInitStatus_{false};
|
|
bool isActivateAudioInterrupt_{false};
|
|
MediaThreadIdHandle threadIdHandle_;
|
|
std::condition_variable pauseCondVar_;
|
|
std::shared_ptr<OHOS::Audio::AudioCapturer> lefunAiCapturer_{nullptr};
|
|
std::shared_ptr<OHOS::Media::Player> playerCtr_{nullptr};
|
|
std::shared_ptr<OHOS::Media::PlayerCallback> playerCallback_{nullptr};
|
|
};
|
|
|
|
} // namespace TJD
|
|
|
|
#endif |