diff --git a/TODO.md b/TODO.md new file mode 100644 index 0000000..e5671da --- /dev/null +++ b/TODO.md @@ -0,0 +1,2 @@ +1. 整理aiui测试代码中的appid,使用测试项目的appid +2. 将应用程序中的aiui的appid修改成配置 \ No newline at end of file diff --git a/dep/iflytopcpp b/dep/iflytopcpp index 75c6919..a25cad2 160000 --- a/dep/iflytopcpp +++ b/dep/iflytopcpp @@ -1 +1 @@ -Subproject commit 75c691900a692c38cfdb9947446ca438efca6ee6 +Subproject commit a25cad2026c70d65867ad54e3f1faced1ebd2988 diff --git a/dep/zlinuxcomponents b/dep/zlinuxcomponents index c771fa7..c1eac4f 160000 --- a/dep/zlinuxcomponents +++ b/dep/zlinuxcomponents @@ -1 +1 @@ -Subproject commit c771fa7af061fd5d672d37a703a536e27f2d6522 +Subproject commit c1eac4f961ff27d8cc4c3f1ddfa985be40750e9d diff --git a/src/main.cpp b/src/main.cpp index 0c3a6d7..ca5e616 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -156,12 +156,16 @@ void Main::buildVoiceProcessService() { const char *appid = "5938b7c7"; // 应用ID,在AIUI开放平台创建并设置 const char *key = "19c1f7becc78eedc7826b485aabe30de"; // 接口密钥,在AIUI开放平台查看 json paramj; - paramj["result_level"] = "plain"; - paramj["auth_id"] = "ac30105366ea460f9ff08ddac0c4f71e"; - paramj["data_type"] = "text"; - paramj["scene"] = "main_box"; - paramj["sample_rate"] = "16000"; - paramj["context"] = R"({"sdk_support":["nlp","tts","vad","iat"]})"; + paramj["result_level"] = "plain"; + paramj["auth_id"] = "ac30105366ea460f9ff08ddac0c4f71e"; //相当于设备ID,设备唯一 + paramj["data_type"] = "audio"; + paramj["aue"] = "raw"; + paramj["vad_info"] = "end"; + paramj["cloud_vad_eos"] = "700"; + paramj["close_delay"] = "200"; + paramj["scene"] = "main_box"; + paramj["sample_rate"] = "16000"; + paramj["context"] = R"({"sdk_support":["nlp","tts","vad","iat"]})"; BUILD_AND_REG_SERRVICE(AiuiService); GET_SERVICE(AiuiService)->initialize(appid, key, paramj.dump()); } diff --git a/src/service/voiceprocess/audio_recoder_service.cpp b/src/service/voiceprocess/audio_recoder_service.cpp index 610af89..2ef125a 100644 --- a/src/service/voiceprocess/audio_recoder_service.cpp +++ b/src/service/voiceprocess/audio_recoder_service.cpp @@ -4,13 +4,51 @@ using namespace std; using namespace iflytop; using namespace core; +#define TEST + AudioRecoderService::AudioRecoderService() {} void AudioRecoderService::initialize(const char *pcmName, unsigned int channels, unsigned int sample_rate, snd_pcm_format_t format) { +#ifdef TEST + logger->info("In Test Mode"); + m_inputFileStream.open("test_in_audio.wav", ios::in | ios::binary); + if (!m_inputFileStream.is_open()) { + logger->error("open file {} failed", "test_in_audio.wav"); + return; + } + m_inputFileStream.seekg(44, ios::beg); +#else m_audioRecoder = make_shared(); m_audioRecoder->initialize(pcmName, channels, sample_rate, format); - m_audioRecoder->onRecordData.connect([this](shared_ptr audioclip) { onRecordData(audioclip); }); +#endif } -void AudioRecoderService::startRecord() { m_audioRecoder->startRecord(); } +void AudioRecoderService::startRecord() { +#ifdef TEST + if (m_thread) { + m_thread->join(); + m_thread = nullptr; + } + m_thread.reset(new Thread("testAudio", [&]() { + ThisThread thisThread; + uint8_t buf[8000]; + while (!thisThread.getExitFlag()) { + m_inputFileStream.read((char *)buf, 8000); + if (m_inputFileStream.gcount() != 8000) { + logger->info("read file end"); + break; + } + + shared_ptr audioclip; + audioclip.reset(new AudioClip(buf, 8000, 5, 16000, AudioFormat::S16_LE)); + logger->info("report audioclip {}", 8000); + onRecordData(audioclip); + thisThread.sleepForMs(60); + } + logger->info("testAudio thread exit"); + })); +#else + m_audioRecoder->startRecord(); +#endif +} \ No newline at end of file diff --git a/src/service/voiceprocess/audio_recoder_service.hpp b/src/service/voiceprocess/audio_recoder_service.hpp index 5498192..1adefc6 100644 --- a/src/service/voiceprocess/audio_recoder_service.hpp +++ b/src/service/voiceprocess/audio_recoder_service.hpp @@ -39,6 +39,10 @@ class AudioRecoderService : public enable_shared_from_this shared_ptr m_audioRecoder; nod::signal audioclip)> onRecordData; + // 输入文件 + ifstream m_inputFileStream; + unique_ptr m_thread; + public: AudioRecoderService();