14 changed files with 325 additions and 40 deletions
-
2CMakeLists.txt
-
2dep/iflytopcpp
-
42env/rootfs/etc/asound.conf
-
BINenv/wakeupvoice/zaina.mp3
-
1sh/packet.sh
-
87src/main.cpp
-
43src/service/voiceprocess/audio_logging_service.cpp
-
97src/service/voiceprocess/audio_logging_service.hpp
-
12src/service/voiceprocess/audio_recoder_service.cpp
-
46src/service/voiceprocess/audio_recoder_service.hpp
-
18src/service/voiceprocess/voiceprocess_service.cpp
-
9src/service/voiceprocess/voiceprocess_service.hpp
-
4src/service/voiceprocess/wakeup_processer.cpp
-
2src/service/voiceprocess/wakeup_processer.hpp
@ -1 +1 @@ |
|||
Subproject commit 59531ea26be163327f7cbc6bc31b9845521afff5 |
|||
Subproject commit e4c17891a53fda64a1beafa88ecc9f62119082c2 |
@ -0,0 +1,43 @@ |
|||
#include "audio_logging_service.hpp"
|
|||
|
|||
#include "iflytopcpp/core/components/time_util.hpp"
|
|||
|
|||
using namespace iflytop; |
|||
using namespace core; |
|||
void AudioLoggingService::initialize() { |
|||
m_originalVoice = make_shared<AudioQueue>(); |
|||
m_beforeWakeupVoice = make_shared<AudioQueue>(); |
|||
m_beforeAsrVoice = make_shared<AudioQueue>(); |
|||
|
|||
m_realtime_log_thread.reset(new Thread("m_realtime_log_thread", [this]() { |
|||
ThisThread thisThread; |
|||
while (!thisThread.getExitFlag()) { |
|||
thisThread.sleepForMs(33); |
|||
} |
|||
})); |
|||
} |
|||
|
|||
void AudioLoggingService::loggerVoice(VoiceType voiceType, shared_ptr<AudioClip> audioClip) { |
|||
zsteady_tp now = zsteady_clock().now(); |
|||
|
|||
shared_ptr<AudioQueue> aq; |
|||
if (voiceType == kOriginalVoice) { |
|||
aq = m_originalVoice; |
|||
} else if (voiceType == kBeforeWakeupVoice) { |
|||
aq = m_beforeWakeupVoice; |
|||
} else if (voiceType == kBeforeAsrVoice) { |
|||
aq = m_beforeAsrVoice; |
|||
} else { |
|||
return; |
|||
} |
|||
|
|||
aq->m_30sque.push_back(audioClip); |
|||
aq->m_rtque.push_back(audioClip); |
|||
if (wakeup) aq->m_wakque.push_back(audioClip); |
|||
|
|||
aq->m_30sque.remove_if( |
|||
[&](shared_ptr<AudioClip> audioClip) { return zsteady_clock().dToMs(now - audioClip->getTp()) > (30 * 1000); }); |
|||
} |
|||
|
|||
void AudioLoggingService::triggerWakeupEvent() {} |
|||
void AudioLoggingService::triggerEndWakeupEvent() {} |
@ -0,0 +1,97 @@ |
|||
//
|
|||
// Created by zwsd
|
|||
//
|
|||
|
|||
#pragma once
|
|||
#include <fstream>
|
|||
#include <iostream>
|
|||
#include <list>
|
|||
#include <map>
|
|||
#include <memory>
|
|||
#include <set>
|
|||
#include <sstream>
|
|||
#include <string>
|
|||
#include <vector>
|
|||
|
|||
#include "iflytopcpp/core/spdlogfactory/logger.hpp"
|
|||
#include "iflytopcpp/core/thread/thread.hpp"
|
|||
#include "zlinuxcomponents/audio/audio_clip.hpp"
|
|||
#include "iflytopcpp/core/components/time_util.hpp"
|
|||
|
|||
/**
|
|||
* @brief |
|||
* |
|||
* service: AudioLoggingService |
|||
* |
|||
* 1. 存储每次唤醒后的音频,及其唤醒前20s的音频 |
|||
* 2. 每隔1分钟录一帧,共录15分钟 |
|||
* 3. 存储不同阶段的语音 |
|||
* |
|||
*/ |
|||
|
|||
namespace iflytop { |
|||
using namespace std; |
|||
using namespace core; |
|||
class AudioLoggingService : public enable_shared_from_this<AudioLoggingService> { |
|||
ENABLE_LOGGER(AudioLoggingService); |
|||
|
|||
public: |
|||
enum VoiceType { |
|||
kOriginalVoice, |
|||
kBeforeWakeupVoice, |
|||
kBeforeAsrVoice, |
|||
}; |
|||
|
|||
/**
|
|||
* @brief |
|||
* 存储一下文件: |
|||
* |
|||
* 每次唤醒存储一次语音,为了录全语音,会将唤醒前30s的语音也录制进来 |
|||
* logVoice/bywakeup/ |
|||
* 20230308183030_origi.wav |
|||
* 20230308183030_bfwak.wav |
|||
* 20230308183030_bfasr.wav |
|||
* |
|||
* 每隔1分钟录一次,一次录一分钟的语音,总共录15分钟,滚动覆盖. |
|||
* logVoice/bytime/ |
|||
* 20230308183030_origi.wav |
|||
* 20230308183030_bfwak.wav |
|||
* 20230308183030_bfasr.wav |
|||
* |
|||
*/ |
|||
class AudioQueue { |
|||
public: |
|||
// 缓存30s语音的队列
|
|||
list<shared_ptr<AudioClip>> m_30sque; |
|||
// 唤醒存储队列
|
|||
list<shared_ptr<AudioClip>> m_wakque; |
|||
// 实时存储队列
|
|||
list<shared_ptr<AudioClip>> m_rtque; |
|||
}; |
|||
|
|||
shared_ptr<AudioQueue> m_originalVoice; |
|||
shared_ptr<AudioQueue> m_beforeWakeupVoice; |
|||
shared_ptr<AudioQueue> m_beforeAsrVoice; |
|||
|
|||
unique_ptr<Thread> m_realtime_log_thread; |
|||
bool wakeup = false; |
|||
|
|||
class OnceLog { |
|||
public: |
|||
zsteady_tp m_startTime; |
|||
|
|||
}; |
|||
|
|||
shared_ptr<OnceLog> m_realTimeOnceLog; |
|||
|
|||
public: |
|||
AudioLoggingService(){}; |
|||
|
|||
void loggerVoice(VoiceType voiceType, shared_ptr<AudioClip> audioClip); |
|||
|
|||
void triggerWakeupEvent(); |
|||
void triggerEndWakeupEvent(); |
|||
|
|||
void initialize(); |
|||
}; |
|||
} // namespace iflytop
|
@ -0,0 +1,12 @@ |
|||
#include "audio_recoder_service.hpp"
|
|||
|
|||
using namespace std; |
|||
using namespace iflytop; |
|||
using namespace core; |
|||
|
|||
AudioRecoderService::AudioRecoderService() {} |
|||
void AudioRecoderService::initialize(const char *pcmName, unsigned int channels, unsigned int sample_rate, |
|||
snd_pcm_format_t format) { |
|||
m_audioRecoder = make_shared<AudioRecoder>(); |
|||
m_audioRecoder->initialize(pcmName, channels, sample_rate, format); |
|||
} |
@ -0,0 +1,46 @@ |
|||
//
|
|||
// Created by zwsd
|
|||
//
|
|||
|
|||
#pragma once
|
|||
#include <fstream>
|
|||
#include <iostream>
|
|||
#include <list>
|
|||
#include <map>
|
|||
#include <memory>
|
|||
#include <set>
|
|||
#include <sstream>
|
|||
#include <string>
|
|||
#include <vector>
|
|||
|
|||
#include "iflytopcpp/core/spdlogfactory/logger.hpp"
|
|||
#include "iflytopcpp/core/thread/thread.hpp"
|
|||
#include "zlinuxcomponents/audio/audio_recoder.hpp"
|
|||
|
|||
/**
|
|||
* @brief |
|||
* |
|||
* service: AudioRecoderService |
|||
* |
|||
* 监听事件: |
|||
* 依赖状态: |
|||
* 依赖服务: |
|||
* 作用: |
|||
* |
|||
*/ |
|||
|
|||
namespace iflytop { |
|||
using namespace std; |
|||
using namespace core; |
|||
class AudioRecoderService : public enable_shared_from_this<AudioRecoderService> { |
|||
ENABLE_LOGGER(AudioRecoderService); |
|||
|
|||
public: |
|||
shared_ptr<AudioRecoder> m_audioRecoder; |
|||
|
|||
public: |
|||
AudioRecoderService(); |
|||
|
|||
void initialize(const char *pcmName, unsigned int channels, unsigned int sample_rate, snd_pcm_format_t format); |
|||
}; |
|||
} // namespace iflytop
|
@ -1,9 +1,25 @@ |
|||
#include "voiceprocess_service.hpp"
|
|||
|
|||
#include "iflytopcpp/core/spdlogfactory/logger.hpp"
|
|||
#include "zservice_container/zservice_container.hpp"
|
|||
|
|||
using namespace iflytop; |
|||
using namespace std; |
|||
using namespace core; |
|||
|
|||
void VoiceProcessService::initialize() {} |
|||
void VoiceProcessService::initialize() { |
|||
//
|
|||
GET_TO_SERVICE(m_beforeWakeupVoiceProcesser); |
|||
GET_TO_SERVICE(m_beforeasrVoiceProcesser); |
|||
GET_TO_SERVICE(m_wakeupProcesser); |
|||
GET_TO_SERVICE(m_audioRecoderService); |
|||
|
|||
m_audioRecoderService->m_audioRecoder->onRecordData.connect( |
|||
[this](shared_ptr<AudioClip> audioClip) { m_beforeWakeupVoiceProcesser->writeVoice(audioClip); }); |
|||
|
|||
m_beforeWakeupVoiceProcesser->onAfterProcessVoice.connect( |
|||
[this](shared_ptr<AudioClip> audioClip) { m_beforeasrVoiceProcesser->writeVoice(audioClip); }); |
|||
|
|||
// m_wakeupProcesser->onWakeupSignal.connect(
|
|||
// [this](float wakeup_score) { logger->info("wakeup_score:{}", wakeup_score); });
|
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue