mirror of
https://github.com/openharmony/ai_intelligent_voice_framework.git
synced 2026-07-01 20:24:01 -04:00
@@ -56,8 +56,12 @@ Note: If the text contains special characters, please escape them according to t
|
||||
<configuration>
|
||||
<oatconfig>
|
||||
<filefilterlist>
|
||||
<filefilter name="defaultFilter" desc="Files not to check">
|
||||
<filteritem type="filename" name="*.xml" desc="Configuration files"/>
|
||||
</filefilter>
|
||||
<filefilter name="binaryFileTypePolicyFilter" desc="Filters for binary file policies" >
|
||||
<filteritem type="filepath" name="figures/.*" desc="architecture figure binary."/>
|
||||
<filteritem type="filename" name="*.pcm" desc="Sample test files"/>
|
||||
</filefilter>
|
||||
</filefilterlist>
|
||||
</oatconfig>
|
||||
|
||||
@@ -56,6 +56,7 @@ ohos_shared_library("intell_voice_server") {
|
||||
sources = [
|
||||
"intell_voice_engine/server/base/adapter_callback_service.cpp",
|
||||
"intell_voice_engine/server/base/audio_capturer_source_change_callback.cpp",
|
||||
"intell_voice_engine/server/base/audio_debug.cpp",
|
||||
"intell_voice_engine/server/base/audio_source.cpp",
|
||||
"intell_voice_engine/server/base/engine_base.cpp",
|
||||
"intell_voice_engine/server/base/engine_factory.cpp",
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "audio_debug.h"
|
||||
#ifdef AUDIO_DATA_DEBUG
|
||||
#include "intell_voice_log.h"
|
||||
#include "time_util.h"
|
||||
|
||||
#define LOG_TAG "AudioDebug"
|
||||
#endif
|
||||
|
||||
namespace OHOS {
|
||||
namespace IntellVoiceEngine {
|
||||
#ifdef AUDIO_DATA_DEBUG
|
||||
|
||||
static const std::string PCM_DIR = "/data/data/intell_voice/pcm_data/";
|
||||
|
||||
void AudioDebug::CreateAudioDebugFile()
|
||||
{
|
||||
DestroyAudioDebugFile();
|
||||
|
||||
auto path = PCM_DIR + OHOS::IntellVoiceUtils::TimeUtil::GetCurrTime() + ".pcm";
|
||||
fileStream_ = std::make_unique<std::ofstream>(path);
|
||||
if (fileStream_ == nullptr) {
|
||||
INTELL_VOICE_LOG_ERROR("open debug record file failed");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void AudioDebug::WriteData(char *data, uint32_t length)
|
||||
{
|
||||
if (fileStream_ != nullptr) {
|
||||
fileStream_->write(data, length);
|
||||
}
|
||||
}
|
||||
|
||||
void AudioDebug::DestroyAudioDebugFile()
|
||||
{
|
||||
if (fileStream_ != nullptr) {
|
||||
fileStream_->close();
|
||||
fileStream_ = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
void AudioDebug::CreateAudioDebugFile()
|
||||
{
|
||||
}
|
||||
|
||||
void AudioDebug::WriteData(char * /* data */, uint32_t /* length */)
|
||||
{
|
||||
}
|
||||
|
||||
void AudioDebug::DestroyAudioDebugFile()
|
||||
{
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef AUDIO_DEBUG_H
|
||||
#define AUDIO_DEBUG_H
|
||||
|
||||
#include <cstdint>
|
||||
#ifdef AUDIO_DATA_DEBUG
|
||||
#include <memory>
|
||||
#include <fstream>
|
||||
#endif
|
||||
|
||||
namespace OHOS {
|
||||
namespace IntellVoiceEngine {
|
||||
class AudioDebug {
|
||||
public:
|
||||
AudioDebug() = default;
|
||||
~AudioDebug() = default;
|
||||
|
||||
void CreateAudioDebugFile();
|
||||
void WriteData(char *data, uint32_t length);
|
||||
void DestroyAudioDebugFile();
|
||||
|
||||
private:
|
||||
#ifdef AUDIO_DATA_DEBUG
|
||||
std::unique_ptr<std::ofstream> fileStream_ = nullptr;
|
||||
#endif
|
||||
};
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -15,17 +15,16 @@
|
||||
#include "audio_source.h"
|
||||
|
||||
#include "securec.h"
|
||||
#include "time_util.h"
|
||||
#include "intell_voice_log.h"
|
||||
#include "memory_guard.h"
|
||||
|
||||
#define LOG_TAG "AudioSource"
|
||||
|
||||
using namespace OHOS::AudioStandard;
|
||||
using namespace OHOS::IntellVoiceUtils;
|
||||
#define LOG_TAG "AudioSource"
|
||||
|
||||
namespace OHOS {
|
||||
namespace IntellVoiceEngine {
|
||||
static const std::string PCM_DIR = "/data/data/intell_voice/pcm_data/";
|
||||
static const std::string CACHE_PATH = "/data/data/intell_voice/cache/";
|
||||
|
||||
AudioSource::AudioSource(uint32_t minBufferSize, uint32_t bufferCnt,
|
||||
@@ -74,17 +73,11 @@ bool AudioSource::Start()
|
||||
return false;
|
||||
}
|
||||
|
||||
auto path = PCM_DIR + TimeUtil::GetCurrTime() + ".pcm";
|
||||
fileStream_ = std::make_unique<std::ofstream>(path);
|
||||
if (fileStream_ == nullptr) {
|
||||
INTELL_VOICE_LOG_ERROR("open debug record file failed");
|
||||
return false;
|
||||
}
|
||||
CreateAudioDebugFile();
|
||||
|
||||
if (!audioCapturer_->Start()) {
|
||||
INTELL_VOICE_LOG_ERROR("start audio capturer failed");
|
||||
fileStream_->close();
|
||||
fileStream_ = nullptr;
|
||||
DestroyAudioDebugFile();
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -140,9 +133,7 @@ bool AudioSource::Read()
|
||||
return false;
|
||||
}
|
||||
|
||||
if (fileStream_ != nullptr) {
|
||||
fileStream_->write(reinterpret_cast<char *>(buffer_.get()), minBufferSize_);
|
||||
}
|
||||
WriteData(reinterpret_cast<char *>(buffer_.get()), minBufferSize_);
|
||||
|
||||
if (listener_ != nullptr) {
|
||||
listener_->readBufferCb_(buffer_.get(), minBufferSize_);
|
||||
@@ -163,10 +154,7 @@ void AudioSource::Stop()
|
||||
isReading_.store(false);
|
||||
readThread_.join();
|
||||
|
||||
if (fileStream_ != nullptr) {
|
||||
fileStream_->close();
|
||||
fileStream_ = nullptr;
|
||||
}
|
||||
DestroyAudioDebugFile();
|
||||
|
||||
if (audioCapturer_ == nullptr) {
|
||||
INTELL_VOICE_LOG_ERROR("audioCapturer_ is nullptr");
|
||||
|
||||
@@ -19,9 +19,9 @@
|
||||
#include <functional>
|
||||
#include <thread>
|
||||
#include <atomic>
|
||||
#include <fstream>
|
||||
#include "audio_capturer.h"
|
||||
#include "audio_info.h"
|
||||
#include "audio_debug.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace IntellVoiceEngine {
|
||||
@@ -35,7 +35,7 @@ struct AudioSourceListener {
|
||||
OnBufferEndCb bufferEndCb_;
|
||||
};
|
||||
|
||||
class AudioSource {
|
||||
class AudioSource : private AudioDebug {
|
||||
public:
|
||||
AudioSource(uint32_t minBufferSize, uint32_t bufferCnt, std::unique_ptr<AudioSourceListener> listener,
|
||||
const OHOS::AudioStandard::AudioCapturerOptions &capturerOptions);
|
||||
@@ -55,7 +55,6 @@ private:
|
||||
std::thread readThread_;
|
||||
OHOS::AudioStandard::AudioCapturerOptions capturerOptions_;
|
||||
std::shared_ptr<uint8_t> buffer_ = nullptr;
|
||||
std::unique_ptr<std::ofstream> fileStream_ = nullptr;
|
||||
std::unique_ptr<OHOS::AudioStandard::AudioCapturer> audioCapturer_ = nullptr;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -327,6 +327,7 @@ bool WakeupEngine::StartAudioSource()
|
||||
if (!audioSource_->Start()) {
|
||||
INTELL_VOICE_LOG_ERROR("start capturer failed");
|
||||
audioSource_ = nullptr;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
@@ -43,7 +43,7 @@ bool TriggerModel::SetData(const uint8_t *data, uint32_t size)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool TriggerModel::SetData(std::vector<uint8_t>data)
|
||||
bool TriggerModel::SetData(std::vector<uint8_t> &data)
|
||||
{
|
||||
if (data.size() == 0) {
|
||||
INTELL_VOICE_LOG_ERROR("size is invalid");
|
||||
|
||||
@@ -32,7 +32,7 @@ public:
|
||||
virtual ~TriggerModel();
|
||||
|
||||
bool SetData(const uint8_t *data, uint32_t size);
|
||||
bool SetData(std::vector<uint8_t> data);
|
||||
bool SetData(std::vector<uint8_t> &data);
|
||||
void Print();
|
||||
|
||||
int32_t GetUuid() const
|
||||
|
||||
@@ -48,6 +48,8 @@ ohos_unittest("client_unit_test") {
|
||||
"safwk:system_ability_fwk",
|
||||
"samgr:samgr_proxy",
|
||||
]
|
||||
|
||||
resource_config_file = "resource/ohos_test.xml"
|
||||
}
|
||||
|
||||
ohos_unittest("trigger_unit_test") {
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!-- Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
<configuration ver="2.0">
|
||||
<target name="client_unit_test">
|
||||
<depend resource="one.pcm" pushpath="/data/test/resource" findpath="res" presetcmd=""/>
|
||||
<preparer>
|
||||
<option name="push" value="one.pcm -> /data/test/resource" src="res"/>
|
||||
</preparer>
|
||||
</target>
|
||||
</configuration>
|
||||
Binary file not shown.
@@ -55,9 +55,9 @@ void EngineEventCallback::OnEvent(
|
||||
++startCnt_;
|
||||
engine_->Start(startCnt_ == ENROLL_CNT ? true : false);
|
||||
if (startCnt_ == ENROLL_CNT) {
|
||||
EngineEventCallback::ReadFile(TEST_RESOURCE_PATH + "three.pcm");
|
||||
EngineEventCallback::ReadFile(TEST_RESOURCE_PATH + "one.pcm");
|
||||
} else {
|
||||
EngineEventCallback::ReadFile(TEST_RESOURCE_PATH + "two.pcm");
|
||||
EngineEventCallback::ReadFile(TEST_RESOURCE_PATH + "one.pcm");
|
||||
}
|
||||
} else if (startCnt_ == ENROLL_CNT) {
|
||||
engine_->SetParameter("CommitEnrollment=true");
|
||||
|
||||
Reference in New Issue
Block a user