|
|
#include <curl/curl.h>
#include <iostream>
#include <string>
#include "zlinuxcomponents/aiui_ws/aiui_service.hpp"
#include "zlinuxcomponents/alsaplayer/AudioPlayerAlsaImpl.hpp"
#include "zlinuxcomponents/alsaplayer/smart_soundbox_player.hpp"
#include "zlinuxcomponents/zmainhelper.hpp"
//
#include "configs/zconfig.hpp"
#include "iflytopcpp/core/spdlogfactory/logger.hpp"
#include "iflytopcpp/core/thread/thread.hpp"
#include "version.hpp"
#include "zlinuxcomponents/rootfs_auto_update/rootfs_auto_update.hpp"
#include "zservice_container/zservice_container.hpp"
#include "zwebservice/zwebservice.hpp"
//
#include "service/device_io_service.hpp"
#include "service/device_io_service_mock.hpp"
#include "service/light_control_service.hpp"
#include "service/main_control_service.hpp"
#include "service/report_service.hpp"
#include "service/voiceprocess/audio_logging_service.hpp"
#include "service/voiceprocess/audio_recoder_service.hpp"
#include "service/voiceprocess/beforeasr_voiceprocesser.hpp"
#include "service/voiceprocess/beforewakeup_voiceprocesser.hpp"
#include "service/voiceprocess/wakeup_processer.hpp"
//
using namespace iflytop; using namespace core; using namespace std; using namespace clipp; class Main { ENABLE_LOGGER(Main);
private: unique_ptr<Thread> thread;
private: int main(int argc, char *argv[]);
public: Main(/* args */) {} ~Main() {} void run(int argc, char *argv[]) { thread.reset(new Thread("main", [&]() { exit(main(argc, argv)); })); while (true) sleep(1000); } void appSetup(int argc, char *argv[]); void updateRootfs(); void buildDeviceIOService(); void buildVoiceProcessService(); void onSIGINT(); };
Main *g_main; void onsignal(int signo) { g_main->onSIGINT(); } int main(int argc, char *argv[]) { Main main; g_main = &main; ::signal(SIGINT, onsignal); main.run(argc, argv); }
/***********************************************************************************************************************
* =======================================================Main======================================================== * ***********************************************************************************************************************/ void Main::onSIGINT() { exit(0); }
void Main::appSetup(int argc, char *argv[]) { string g_host_server_ip; string g_device_id; #if 0
auto cli = ( //
(required("-device_id") & value("device_id", g_device_id)).doc("device_id") //
); if (!parse(argc, argv, cli)) { cout << make_man_page(cli, argv[0]); exit(-1); } #endif
logger->info("system setup start."); spdlog::flush_on(spdlog::level::debug);
logger->info("#"); logger->info("# company:{}", "ifytop"); logger->info("# version:{}", VERSION); logger->info("#");
// BUILD_AND_REG_SERRVICE(Config);
logger->info("build {}.....", "Config"); BUILD_AND_REG_SERRVICE(ZConfig); GET_SERVICE(ZConfig)->initialize(); if (!g_device_id.empty()) GET_SERVICE(ZConfig)->set_deviceId(g_device_id); }
void Main::updateRootfs() { /**
* @brief 比较rootfs目录中的文件和系统中对应路径的文件是否一致,如果不一致则替换 * * 例如 * ./rootfs/etc/asound.conf 和 /etc/asound.conf 不一致,则替换 * */ auto rootfsAutoUpdate = make_shared<RootfsAutoUpdate>(); rootfsAutoUpdate->compareAndReplace(); logger->info("rootfs changed:{}", rootfsAutoUpdate->isChanged() ? "yes" : "no"); if (rootfsAutoUpdate->isChanged()) { logger->info("reboot system."); logger->warn("not auto reboot, please reboot manually."); // system("reboot");
} }
void Main::buildDeviceIOService() { /**
* @brief DeviceIOService初始化 */ auto config = GET_SERVICE(ZConfig);
#if 1
BUILD_AND_REG_SERRVICE(DeviceIOService); #else
BUILD_AND_REG_MOCK_SERRVICE(DeviceIOService, DeviceIOServiceMock); #endif
GET_SERVICE(DeviceIOService)->initialize(config->get_device_io_uart_path(), config->get_device_io_uart_baundrate()); }
void Main::buildVoiceProcessService() { /**
* @brief 音频处理相关组建初始化 */
auto config = GET_SERVICE(ZConfig);
// AudioLoggingService
BUILD_AND_REG_SERRVICE(AudioLoggingService); GET_SERVICE(AudioLoggingService)->initialize(config->get_voice_logger_enable());
// 音频采集
BUILD_AND_REG_SERRVICE(AudioRecoderService); GET_SERVICE(AudioRecoderService) ->initialize(config->get_recoder_device_name().c_str(), //
config->get_recoder_ch_number(), //
config->get_recoder_sample_rate(), //
SND_PCM_FORMAT_S16_LE, //
config->get_recoder_period_time_ms());
// BfWakeupVProcesser
BUILD_AND_REG_SERRVICE(BfWakeupVProcesser); GET_SERVICE(BfWakeupVProcesser)->initialize();
// BeforeAsrVoiceProcesser
BUILD_AND_REG_SERRVICE(BfAsrVProcesser); GET_SERVICE(BfAsrVProcesser)->initialize();
// WakeupProcesser
BUILD_AND_REG_SERRVICE(WakeupProcesser); GET_SERVICE(WakeupProcesser) ->initialize(config->get_wakeup_lib_module(), //
config->get_wakeup_module_path(), //
config->get_wakeup_chunk_length());
// AsrProcesser
const char *appid = config->get_aiui_appid().c_str(); const char *appkey = config->get_aiui_appkey().c_str(); json paramj; paramj["result_level"] = "plain"; paramj["auth_id"] = config->get_aiui_auth_id(); paramj["data_type"] = "audio"; paramj["aue"] = "raw"; paramj["vad_info"] = "end"; paramj["cloud_vad_eos"] = "700"; paramj["close_delay"] = "200"; paramj["scene"] = config->get_aiui_scene(); paramj["sample_rate"] = "16000"; paramj["context"] = R"({"sdk_support":["nlp","tts","vad","iat"]})"; BUILD_AND_REG_SERRVICE(AiuiService);
logger->info("appid {}", appid); logger->info("param {}", paramj.dump(0));
GET_SERVICE(AiuiService)->initialize(appid, appkey, paramj.dump()); }
int Main::main(int argc, char *argv[]) { appSetup(argc, argv); updateRootfs(); buildDeviceIOService(); buildVoiceProcessService(); // while (true) sleep(1000);
// 播放器-SmartSoundBoxPlayer
BUILD_AND_REG_SERRVICE(SmartSoundBoxPlayer); GET_SERVICE(SmartSoundBoxPlayer)->initialize(100, 30); /**
* @brief 其他服务 */ BUILD_AND_REG_SERRVICE(ZWebService); GET_SERVICE(ZWebService)->initialize();
BUILD_AND_REG_SERRVICE(LightControlService); GET_SERVICE(LightControlService)->initialize(); GET_SERVICE(LightControlService)->start();
BUILD_AND_REG_SERRVICE(ReportService); GET_SERVICE(ReportService)->initialize(); GET_SERVICE(ReportService)->start();
BUILD_AND_REG_SERRVICE(MainControlService); GET_SERVICE(MainControlService)->initialize();
logger->info("system setup end."); while (true) sleep(1000); }
|