You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

227 lines
7.1 KiB

2 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
3 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
2 years ago
2 years ago
2 years ago
3 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
3 years ago
3 years ago
3 years ago
  1. #include <curl/curl.h>
  2. #include <iostream>
  3. #include <string>
  4. #include "zlinuxcomponents/aiui_ws/aiui_service.hpp"
  5. #include "zlinuxcomponents/alsaplayer/AudioPlayerAlsaImpl.hpp"
  6. #include "zlinuxcomponents/alsaplayer/smart_soundbox_player.hpp"
  7. #include "zlinuxcomponents/zmainhelper.hpp"
  8. //
  9. #include "configs/gconfig.hpp"
  10. #include "iflytopcpp/core/spdlogfactory/logger.hpp"
  11. #include "iflytopcpp/core/thread/thread.hpp"
  12. #include "version.hpp"
  13. #include "zlinuxcomponents/rootfs_auto_update/rootfs_auto_update.hpp"
  14. #include "zservice_container/zservice_container.hpp"
  15. #include "zwebservice/zwebservice.hpp"
  16. //
  17. #include "iflytopvoicecpp/soundbox4mic_voice_pre_process.hpp"
  18. #include "service/device_io_service.hpp"
  19. #include "service/device_io_service_mock.hpp"
  20. #include "service/light_control_service.hpp"
  21. #include "service/main_control_service.hpp"
  22. #include "service/report_service.hpp"
  23. #include "service/voiceprocess/audio_logging_service.hpp"
  24. #include "service/voiceprocess/audio_recoder_service.hpp"
  25. #include "service/voiceprocess/beforeasr_voiceprocesser.hpp"
  26. #include "service/voiceprocess/beforewakeup_voiceprocesser.hpp"
  27. #include "service/voiceprocess/common_voiceprocesser.hpp"
  28. #include "service/voiceprocess/wakeup_processer.hpp"
  29. //
  30. using namespace iflytop;
  31. using namespace core;
  32. using namespace std;
  33. using namespace clipp;
  34. class Main {
  35. ENABLE_LOGGER(Main);
  36. private:
  37. unique_ptr<Thread> thread;
  38. private:
  39. int main(int argc, char *argv[]);
  40. public:
  41. Main(/* args */) {}
  42. ~Main() {}
  43. void run(int argc, char *argv[]) {
  44. thread.reset(new Thread("main", [&]() { exit(main(argc, argv)); }));
  45. while (true) sleep(1000);
  46. }
  47. void appSetup(int argc, char *argv[]);
  48. void updateRootfs();
  49. void buildDeviceIOService();
  50. void buildVoiceProcessService();
  51. void onSIGINT();
  52. };
  53. Main *g_main;
  54. void onsignal(int signo) { g_main->onSIGINT(); }
  55. int main(int argc, char *argv[]) {
  56. Main main;
  57. g_main = &main;
  58. ::signal(SIGINT, onsignal);
  59. main.run(argc, argv);
  60. }
  61. /***********************************************************************************************************************
  62. * =======================================================Main======================================================== *
  63. ***********************************************************************************************************************/
  64. void Main::onSIGINT() { exit(0); }
  65. void Main::appSetup(int argc, char *argv[]) {
  66. string g_host_server_ip;
  67. string g_device_id;
  68. #if 0
  69. auto cli = ( //
  70. (required("-device_id") & value("device_id", g_device_id)).doc("device_id") //
  71. );
  72. if (!parse(argc, argv, cli)) {
  73. cout << make_man_page(cli, argv[0]);
  74. exit(-1);
  75. }
  76. #endif
  77. logger->info("system setup start.");
  78. spdlog::flush_on(spdlog::level::debug);
  79. logger->info("#");
  80. logger->info("# company:{}", "ifytop");
  81. logger->info("# version:{}", VERSION);
  82. logger->info("#");
  83. // BUILD_AND_REG_SERRVICE(Config);
  84. logger->info("build {}.....", "Config");
  85. BUILD_AND_REG_SERRVICE(GConfig);
  86. GET_SERVICE(GConfig)->initialize();
  87. if (!g_device_id.empty()) GET_SERVICE(GConfig)->set_deviceId(g_device_id);
  88. }
  89. void Main::updateRootfs() {
  90. /**
  91. * @brief rootfs目录中的文件和系统中对应路径的文件是否一致
  92. *
  93. *
  94. * ./rootfs/etc/asound.conf /etc/asound.conf
  95. *
  96. */
  97. auto rootfsAutoUpdate = make_shared<RootfsAutoUpdate>();
  98. rootfsAutoUpdate->compareAndReplace();
  99. logger->info("rootfs changed:{}", rootfsAutoUpdate->isChanged() ? "yes" : "no");
  100. if (rootfsAutoUpdate->isChanged()) {
  101. logger->info("reboot system.");
  102. logger->warn("not auto reboot, please reboot manually.");
  103. // system("reboot");
  104. }
  105. }
  106. void Main::buildDeviceIOService() {
  107. /**
  108. * @brief DeviceIOService初始化
  109. */
  110. auto config = GET_SERVICE(GConfig);
  111. #if 1
  112. BUILD_AND_REG_SERRVICE(DeviceIOService);
  113. #else
  114. BUILD_AND_REG_MOCK_SERRVICE(DeviceIOService, DeviceIOServiceMock);
  115. #endif
  116. GET_SERVICE(DeviceIOService)->initialize(config->get_device_io_uart_path(), config->get_device_io_uart_baundrate());
  117. }
  118. void Main::buildVoiceProcessService() {
  119. /**
  120. * @brief
  121. */
  122. auto config = GET_SERVICE(GConfig);
  123. BUILD_AND_REG_SERRVICE(Soundbox4micVoicePreProcess);
  124. GET_SERVICE(Soundbox4micVoicePreProcess)->initialize();
  125. // AudioLoggingService
  126. BUILD_AND_REG_SERRVICE(AudioLoggingService);
  127. GET_SERVICE(AudioLoggingService)->initialize(config->get_voice_logger_enable());
  128. // 音频采集
  129. BUILD_AND_REG_SERRVICE(AudioRecoderService);
  130. GET_SERVICE(AudioRecoderService)
  131. ->initialize(config->get_recoder_device_name().c_str(), //
  132. config->get_recoder_ch_number(), //
  133. config->get_recoder_sample_rate(), //
  134. SND_PCM_FORMAT_S16_LE, //
  135. config->get_recoder_period_time_ms());
  136. // BfWakeupVProcesser
  137. BUILD_AND_REG_SERRVICE(BfWakeupVProcesser);
  138. GET_SERVICE(BfWakeupVProcesser)->initialize();
  139. // BeforeAsrVoiceProcesser
  140. BUILD_AND_REG_SERRVICE(BfAsrVProcesser);
  141. GET_SERVICE(BfAsrVProcesser)->initialize();
  142. BUILD_AND_REG_SERRVICE(CommonVoiceProcesser);
  143. GET_SERVICE(CommonVoiceProcesser)->initialize(5 /*总通道数*/, 4 /*参考通道通道INDEX*/);
  144. // WakeupProcesser
  145. BUILD_AND_REG_SERRVICE(WakeupProcesser);
  146. GET_SERVICE(WakeupProcesser)
  147. ->initialize(config->get_wakeup_lib_module(), //
  148. config->get_wakeup_module_path(), //
  149. config->get_wakeup_chunk_length());
  150. // AsrProcesser
  151. const char *appid = config->get_aiui_appid().c_str();
  152. const char *appkey = config->get_aiui_appkey().c_str();
  153. json paramj;
  154. paramj["result_level"] = "plain";
  155. paramj["auth_id"] = config->get_aiui_auth_id();
  156. paramj["data_type"] = "audio";
  157. paramj["aue"] = "raw";
  158. paramj["vad_info"] = "end";
  159. paramj["cloud_vad_eos"] = "700";
  160. paramj["close_delay"] = "200";
  161. paramj["scene"] = config->get_aiui_scene();
  162. paramj["sample_rate"] = "16000";
  163. paramj["context"] = R"({"sdk_support":["nlp","tts","vad","iat"]})";
  164. BUILD_AND_REG_SERRVICE(AiuiService);
  165. logger->info("appid {}", appid);
  166. logger->info("param {}", paramj.dump(0));
  167. GET_SERVICE(AiuiService)->initialize(appid, appkey, paramj.dump());
  168. }
  169. int Main::main(int argc, char *argv[]) {
  170. appSetup(argc, argv);
  171. updateRootfs();
  172. buildDeviceIOService();
  173. buildVoiceProcessService();
  174. // while (true) sleep(1000);
  175. // 播放器-SmartSoundBoxPlayer
  176. BUILD_AND_REG_SERRVICE(SmartSoundBoxPlayer);
  177. GET_SERVICE(SmartSoundBoxPlayer)->initialize(100, 30);
  178. /**
  179. * @brief
  180. */
  181. BUILD_AND_REG_SERRVICE(ZWebService);
  182. GET_SERVICE(ZWebService)->initialize();
  183. BUILD_AND_REG_SERRVICE(LightControlService);
  184. GET_SERVICE(LightControlService)->initialize();
  185. GET_SERVICE(LightControlService)->start();
  186. BUILD_AND_REG_SERRVICE(ReportService);
  187. GET_SERVICE(ReportService)->initialize();
  188. GET_SERVICE(ReportService)->start();
  189. BUILD_AND_REG_SERRVICE(MainControlService);
  190. GET_SERVICE(MainControlService)->initialize();
  191. logger->info("system setup end.");
  192. while (true) sleep(1000);
  193. }