!54 设置灵敏度和功能查询

Merge pull request !54 from lvqiang214/master
This commit is contained in:
openharmony_ci 2024-06-11 06:52:08 +00:00 committed by Gitee
commit 09bb0a0799
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
32 changed files with 332 additions and 118 deletions

View File

@ -38,7 +38,8 @@
"state_registry",
"core_service",
"call_manager",
"huks"
"huks",
"jsoncpp"
],
"third_party": []
},

View File

@ -89,9 +89,6 @@ void EngineEventCallbackNapi::OnEvent(const IntellVoiceEngineCallBackEvent &even
int32_t eventId = -1;
if (event.msgId == HDI::IntelligentVoice::Engine::V1_0::INTELL_VOICE_ENGINE_MSG_RECOGNIZE_COMPLETE) {
eventId = INTELLIGENT_VOICE_EVENT_RECOGNIZE_COMPLETE;
} else if (event.msgId == static_cast<OHOS::HDI::IntelligentVoice::Engine::V1_0::IntellVoiceEngineMessageType>(
OHOS::HDI::IntelligentVoice::Engine::V1_2::INTELL_VOICE_ENGINE_MSG_RECONFIRM_RECOGNITION_COMPLETE)) {
eventId = INTELLIGENT_VOICE_EVENT_RECONFIRM_RECOGNITION_COMPLETE;
} else if (event.msgId == static_cast<OHOS::HDI::IntelligentVoice::Engine::V1_0::IntellVoiceEngineMessageType>(
OHOS::HDI::IntelligentVoice::Engine::V1_2::INTELL_VOICE_ENGINE_MSG_HEADSET_RECOGNIZE_COMPLETE)) {
eventId = INTELLIGENT_VOICE_EVENT_HEADSET_RECOGNIZE_COMPLETE;

View File

@ -69,7 +69,6 @@ static const std::map<std::string, OHOS::IntellVoice::EnrollIntelligentVoiceEven
static const std::map<std::string, OHOS::IntellVoice::WakeupIntelligentVoiceEventType> WAKEUP_EVENT_TYPE_MAP = {
{"INTELLIGENT_VOICE_EVENT_WAKEUP_NONE", INTELLIGENT_VOICE_EVENT_WAKEUP_NONE},
{"INTELLIGENT_VOICE_EVENT_RECOGNIZE_COMPLETE", INTELLIGENT_VOICE_EVENT_RECOGNIZE_COMPLETE},
{"INTELLIGENT_VOICE_EVENT_RECONFIRM_RECOGNITION_COMPLETE", INTELLIGENT_VOICE_EVENT_RECONFIRM_RECOGNITION_COMPLETE},
{"INTELLIGENT_VOICE_EVENT_HEADSET_RECOGNIZE_COMPLETE", INTELLIGENT_VOICE_EVENT_HEADSET_RECOGNIZE_COMPLETE},
};

View File

@ -243,7 +243,12 @@ int32_t IntellVoiceManager::GetFileDataFromAshmem(sptr<Ashmem> ashmem, std::vect
int32_t IntellVoiceManager::SetParameter(const std::string &key, const std::string &value)
{
INTELL_VOICE_LOG_INFO("enter, key:%{public}s, value:%{public}s", key.c_str(), value.c_str());
return 0;
if (g_sProxy == nullptr) {
INTELL_VOICE_LOG_ERROR("IntellVoiceService Proxy is null");
return -1;
}
string keyValueList = key + "=" + value;
return g_sProxy->SetParameter(keyValueList);
}
std::string IntellVoiceManager::GetParameter(const std::string &key)

View File

@ -78,10 +78,8 @@ enum WakeupIntelligentVoiceEventType {
INTELLIGENT_VOICE_EVENT_WAKEUP_NONE = 0,
/* Recognize complete. */
INTELLIGENT_VOICE_EVENT_RECOGNIZE_COMPLETE = 1,
/* Reconfirm Recognition complete. */
INTELLIGENT_VOICE_EVENT_RECONFIRM_RECOGNITION_COMPLETE = 2,
/* Headset Recognize complete. */
INTELLIGENT_VOICE_EVENT_HEADSET_RECOGNIZE_COMPLETE = 3,
INTELLIGENT_VOICE_EVENT_HEADSET_RECOGNIZE_COMPLETE = 2,
};
enum IntelligentVoiceErrorCode {

View File

@ -168,6 +168,7 @@ ohos_shared_library("intell_voice_server") {
"hilog:libhilog",
"huks:libhukssdk",
"ipc:ipc_core",
"jsoncpp:jsoncpp",
"kv_store:distributeddata_inner",
"relational_store:native_rdb",
"safwk:system_ability_fwk",

View File

@ -39,12 +39,14 @@ public:
HDI_INTELL_VOICE_SERVICE_GET_CLONE_FILES_LIST,
HDI_INTELL_VOICE_SERVICE_GET_CLONE_FILE,
HDI_INTELL_VOICE_SERVICE_SEND_CLONE_FILE,
HDI_INTELL_VOICE_SERVICE_CLONE_FOR_RESULT
HDI_INTELL_VOICE_SERVICE_CLONE_FOR_RESULT,
HDI_INTELL_VOICE_SERVICE_SET_PARAMETER
};
virtual int32_t CreateIntellVoiceEngine(IntellVoiceEngineType type, sptr<IIntellVoiceEngine> &inst) = 0;
virtual int32_t ReleaseIntellVoiceEngine(IntellVoiceEngineType type) = 0;
virtual int32_t GetUploadFiles(int numMax, std::vector<UploadHdiFile> &files) = 0;
virtual int32_t SetParameter(const std::string &keyValueList) = 0;
virtual std::string GetParameter(const std::string &key) = 0;
virtual int32_t GetWakeupSourceFilesList(std::vector<std::string>& cloneFiles) = 0;
virtual int32_t GetWakeupSourceFile(const std::string &filePath, std::vector<uint8_t> &buffer) = 0;

View File

@ -112,6 +112,18 @@ std::string IntellVoiceServiceProxy::GetParameter(const std::string &key)
return reply.ReadString();
}
int32_t IntellVoiceServiceProxy::SetParameter(const std::string &keyValueList)
{
MessageParcel data;
MessageParcel reply;
MessageOption option;
data.WriteInterfaceToken(IIntellVoiceService::GetDescriptor());
data.WriteString(keyValueList);
Remote()->SendRequest(HDI_INTELL_VOICE_SERVICE_SET_PARAMETER, data, reply, option);
return reply.ReadInt32();
}
int32_t IntellVoiceServiceProxy::GetWakeupSourceFilesList(std::vector<std::string>& cloneFiles)
{
MessageParcel data;

View File

@ -30,6 +30,7 @@ public:
int32_t CreateIntellVoiceEngine(IntellVoiceEngineType type, sptr<IIntellVoiceEngine> &inst) override;
int32_t ReleaseIntellVoiceEngine(IntellVoiceEngineType type) override;
int32_t GetUploadFiles(int numMax, std::vector<UploadHdiFile> &files) override;
int32_t SetParameter(const std::string &keyValueList) override;
std::string GetParameter(const std::string &key) override;
int32_t GetWakeupSourceFilesList(std::vector<std::string> &cloneFiles) override;
int32_t GetWakeupSourceFile(const std::string &filePath, std::vector<uint8_t> &buffer) override;

View File

@ -33,6 +33,7 @@ namespace IntellVoiceEngine {
static const std::string KEY_GET_WAKEUP_FEATURE = "wakeup_features";
static const std::string LANGUAGE_TEXT = "language=";
static const std::string AREA_TEXT = "area=";
static const std::string SENSIBILITY_TEXT = "sensibility=";
EngineUtil::EngineUtil()
{
@ -134,20 +135,6 @@ bool EngineUtil::SetDspFeatures()
return true;
}
void EngineUtil::SplitStringToKVPair(const std::string &inputStr, std::map<std::string, std::string> &kvpairs)
{
std::vector<std::string> paramsList;
StringUtil::Split(inputStr, ";", paramsList);
for (auto &it : paramsList) {
std::string key;
std::string value;
if (StringUtil::SplitLineToPair(it, key, value)) {
kvpairs[key] = value;
INTELL_VOICE_LOG_INFO("key:%{public}s, value:%{public}s", key.c_str(), value.c_str());
}
}
}
void EngineUtil::WriteBufferFromAshmem(uint8_t *&buffer, uint32_t size, sptr<OHOS::Ashmem> ashmem)
{
if (!ashmem->MapReadOnlyAshmem()) {
@ -211,8 +198,8 @@ void EngineUtil::ProcDspModel(OHOS::HDI::IntelligentVoice::Engine::V1_0::Content
buffer = nullptr;
};
std::shared_ptr<GenericTriggerModel> model = std::make_shared<GenericTriggerModel>(
VOICE_WAKEUP_MODEL_UUID, 1, TriggerModel::TriggerModelType::VOICE_WAKEUP_TYPE);
std::shared_ptr<GenericTriggerModel> model = std::make_shared<GenericTriggerModel>(VOICE_WAKEUP_MODEL_UUID,
TriggerModel::TriggerModelVersion::MODLE_VERSION_2, TriggerModel::TriggerModelType::VOICE_WAKEUP_TYPE);
if (model == nullptr) {
INTELL_VOICE_LOG_ERROR("model is null");
return;
@ -256,5 +243,26 @@ void EngineUtil::SetArea()
adapter_->SetParameter(AREA_TEXT + area);
}
void EngineUtil::SetSensibility()
{
if (adapter_ == nullptr) {
INTELL_VOICE_LOG_ERROR("adapter is nullptr");
return;
}
std::string sensibility = HistoryInfoMgr::GetInstance().GetSensibility();
if (sensibility.empty()) {
INTELL_VOICE_LOG_WARN("sensibility is empty");
return;
}
auto &mgr = IntellVoiceServiceManager::GetInstance();
if (mgr != nullptr) {
mgr->SetDspSensibility(sensibility);
}
adapter_->SetParameter(SENSIBILITY_TEXT + sensibility);
}
}
}

View File

@ -35,7 +35,6 @@ enum EngineEvent {
START_RECOGNIZE,
STOP_RECOGNIZE,
RECOGNIZE_COMPLETE,
RECONFIRM_RECOGNITION_COMPLETE,
START_CAPTURER,
READ,
STOP_CAPTURER,
@ -94,9 +93,9 @@ public:
void ProcDspModel(OHOS::HDI::IntelligentVoice::Engine::V1_0::ContentType type);
void SetLanguage();
void SetArea();
void SetSensibility();
protected:
static void SplitStringToKVPair(const std::string &inputStr, std::map<std::string, std::string> &kvpairs);
std::shared_ptr<IAdapterHostManager> adapter_ = nullptr;
OHOS::HDI::IntelligentVoice::Engine::V1_0::IntellVoiceEngineAdapterDescriptor desc_;

View File

@ -16,7 +16,7 @@
#include <fstream>
#include "securec.h"
#include "intell_voice_log.h"
#include "intell_voice_util.h"
#include "enroll_adapter_listener.h"
#include "time_util.h"
#include "scope_guard.h"
@ -219,7 +219,7 @@ bool EnrollEngine::SetParameterInner(const std::string &keyValueList)
HistoryInfoMgr &historyInfoMgr = HistoryInfoMgr::GetInstance();
std::map<std::string, std::string> kvpairs;
EngineUtil::SplitStringToKVPair(keyValueList, kvpairs);
IntellVoiceUtil::SplitStringToKVPair(keyValueList, kvpairs);
for (auto it : kvpairs) {
if (it.first == std::string("wakeup_bundle_name")) {
INTELL_VOICE_LOG_INFO("set wakeup bundle name:%{public}s", it.second.c_str());
@ -241,6 +241,11 @@ bool EnrollEngine::SetParameterInner(const std::string &keyValueList)
historyInfoMgr.SetArea(it.second);
continue;
}
if (it.first == std::string("Sensibility")) {
INTELL_VOICE_LOG_INFO("set Sensibility:%{public}s", it.second.c_str());
historyInfoMgr.SetSensibility(it.second);
continue;
}
}
return false;

View File

@ -410,6 +410,16 @@ std::string IntellVoiceService::GetParameter(const std::string &key)
return manager->GetParameter(key);
}
int32_t IntellVoiceService::SetParameter(const std::string &keyValueList)
{
const auto &manager = IntellVoiceServiceManager::GetInstance();
if (manager == nullptr) {
INTELL_VOICE_LOG_INFO("manager is nullptr");
return -1;
}
return manager->SetParameter(keyValueList);
}
int32_t IntellVoiceService::GetWakeupSourceFilesList(std::vector<std::string>& cloneFiles)
{
if (!IntellVoiceUtil::VerifySystemPermission(OHOS_PERMISSION_INTELL_VOICE)) {

View File

@ -41,6 +41,7 @@ public:
int32_t GetUploadFiles(int numMax, std::vector<UploadHdiFile> &files) override;
int32_t SetParameter(const std::string &keyValueList) override;
std::string GetParameter(const std::string &key) override;
int32_t GetWakeupSourceFilesList(std::vector<std::string>& cloneFiles) override;
int32_t GetWakeupSourceFile(const std::string &filePath, std::vector<uint8_t> &buffer) override;

View File

@ -33,6 +33,7 @@
#include "clone_update_strategy.h"
#include "silence_update_strategy.h"
#include "update_engine_utils.h"
#include "json/json.h"
#define LOG_TAG "IntellVoiceServiceManager"
@ -45,11 +46,18 @@ namespace IntellVoiceEngine {
static constexpr int32_t MAX_ATTEMPT_CNT = 10;
static constexpr uint32_t MAX_TASK_NUM = 200;
static const std::string SERVICE_MANAGER_THREAD_NAME = "ServMgrThread";
static const std::string SENSIBILITY_TEXT = "sensibility=";
static const std::string WHISPER_MODEL_PATH =
"/sys_prod/variant/region_comm/china/etc/intellvoice/wakeup/dsp/whisper_wakeup_dsp_config";
static const std::string VAD_MODEL_PATH =
"/sys_prod/variant/region_comm/china/etc/intellvoice/wakeup/ap/vad.om";
static const std::string WAKEUP_CONFIG_USER_PATH =
"/sys_prod/variant/region_comm/china/etc/intellvoice/wakeup/ap/wakeup_config_user.json";
static const std::string WAKEUP_CONFIG_PATH =
"/sys_prod/variant/region_comm/china/etc/intellvoice/wakeup/ap/wakeup_config.json";
std::atomic<bool> IntellVoiceServiceManager::enrollResult_[ENGINE_TYPE_BUT] = {false, false, false};
std::atomic<bool> IntellVoiceServiceManager::g_enrollResult[ENGINE_TYPE_BUT] = {false, false, false};
std::vector<int32_t> IntellVoiceServiceManager::g_defaultDspSentenceThresholds = {101, 101, 101};
std::unique_ptr<IntellVoiceServiceManager> IntellVoiceServiceManager::g_intellVoiceServiceMgr =
std::unique_ptr<IntellVoiceServiceManager>(new (std::nothrow) IntellVoiceServiceManager());
@ -349,6 +357,23 @@ void IntellVoiceServiceManager::CreateAndStartServiceObject(int32_t uuid, bool n
StartDetection(uuid);
}
void IntellVoiceServiceManager::SetDspSensibility(const std::string &sensibility)
{
auto triggerMgr = TriggerManager::GetInstance();
if (triggerMgr == nullptr) {
INTELL_VOICE_LOG_ERROR("trigger manager is nullptr");
return;
}
int32_t index = std::stoi(sensibility) - 1;
if ((index < 0) || (index >= static_cast<int32_t>(g_defaultDspSentenceThresholds.size()))) {
INTELL_VOICE_LOG_WARN("invalid index:%{public}d", index);
return;
}
triggerMgr->SetParameter("WAKEUP_SENSIBILITY", std::to_string(g_defaultDspSentenceThresholds[index]));
}
void IntellVoiceServiceManager::ReleaseServiceObject(int32_t uuid)
{
std::lock_guard<std::mutex> lock(detectorMutex_);
@ -520,19 +545,14 @@ void IntellVoiceServiceManager::ProcBreathModel()
return;
}
if (triggerMgr->GetModel(PROXIMAL_WAKEUP_MODEL_UUID) != nullptr) {
INTELL_VOICE_LOG_INFO("proximal model is exist, do nothing");
return;
}
std::shared_ptr<uint8_t> buffer = nullptr;
uint32_t size = 0;
if (!IntellVoiceUtil::ReadFile(WHISPER_MODEL_PATH, buffer, size)) {
return;
}
auto model = std::make_shared<GenericTriggerModel>(PROXIMAL_WAKEUP_MODEL_UUID, 1,
TriggerModel::TriggerModelType::PROXIMAL_WAKEUP_TYPE);
auto model = std::make_shared<GenericTriggerModel>(PROXIMAL_WAKEUP_MODEL_UUID,
TriggerModel::TriggerModelVersion::MODLE_VERSION_2, TriggerModel::TriggerModelType::PROXIMAL_WAKEUP_TYPE);
if (model == nullptr) {
INTELL_VOICE_LOG_ERROR("model is nullptr");
return;
@ -612,11 +632,81 @@ std::string IntellVoiceServiceManager::GetParameter(const std::string &key)
} else if (key == "isNeedReEnroll") {
val = UpdateEngineUtils::IsVersionUpdate() ? "true" : "false";
INTELL_VOICE_LOG_INFO("get nedd reenroll result %{public}s", val.c_str());
} else if (key == "wakeup_capability") {
val = GetWakeupCapability();
INTELL_VOICE_LOG_INFO("get wakeup capability result %{public}s", val.c_str());
}
return val;
}
int32_t IntellVoiceServiceManager::SetParameter(const std::string &keyValueList)
{
INTELL_VOICE_LOG_INFO("enter");
HistoryInfoMgr &historyInfoMgr = HistoryInfoMgr::GetInstance();
std::map<std::string, std::string> kvpairs;
IntellVoiceUtil::SplitStringToKVPair(keyValueList, kvpairs);
for (auto it : kvpairs) {
if (it.first == std::string("Sensibility")) {
INTELL_VOICE_LOG_INFO("set Sensibility:%{public}s", it.second.c_str());
std::string sensibility = it.second;
historyInfoMgr.SetSensibility(sensibility);
SetDspSensibility(sensibility);
TaskExecutor::AddSyncTask([this, sensibility]() -> int32_t {
auto engine = GetEngine(INTELL_VOICE_WAKEUP, engines_);
if (engine != nullptr) {
engine->SetParameter(SENSIBILITY_TEXT + sensibility);
}
return 0;
});
break;
}
}
return 0;
}
std::string IntellVoiceServiceManager::GetWakeupCapability()
{
INTELL_VOICE_LOG_INFO("enter");
Json::Value root;
if (IntellVoiceUtil::IsFileExist(VAD_MODEL_PATH)) {
root["SupportWhisperWakeup"] = true;
} else {
root["SupportWhisperWakeup"] = false;
}
if (IntellVoiceUtil::IsFileExist(WAKEUP_CONFIG_USER_PATH)) {
root["SupportUserDefinedWakeupPhrase"] = true;
} else {
root["SupportUserDefinedWakeupPhrase"] = false;
}
auto isSupportShortWordFunc = []() -> bool {
std::ifstream jsonStrm(WAKEUP_CONFIG_PATH);
if (!jsonStrm.is_open()) {
INTELL_VOICE_LOG_ERROR("open file faile!");
return false;
}
Json::Value wakeupJson;
Json::CharReaderBuilder reader;
reader["collectComments"] = false;
std::string errs;
if (!parseFromStream(reader, jsonStrm, &wakeupJson, &errs)) {
INTELL_VOICE_LOG_ERROR("parseFromStream json faile!");
return false;
}
Json::Value features = wakeupJson["Features"];
for (uint32_t i = 0; i < features.size(); i++) {
if (features[i].asString() == "short_phrase") {
return true;
}
}
return false;
};
root["SupportShortWord"] = isSupportShortWordFunc();
return root.toStyledString();
}
int32_t IntellVoiceServiceManager::GetWakeupSourceFilesList(std::vector<std::string>& cloneFiles)
{
return EngineHostManager::GetInstance().GetWakeupSourceFilesList(cloneFiles);

View File

@ -51,7 +51,7 @@ public:
return;
}
enrollResult_[type].store(result);
g_enrollResult[type].store(result);
}
static bool GetEnrollResult(IntellVoiceEngineType type)
{
@ -59,7 +59,7 @@ public:
return false;
}
return enrollResult_[type].load();
return g_enrollResult[type].load();
}
sptr<IIntellVoiceEngine> HandleCreateEngine(IntellVoiceEngineType type);
@ -89,10 +89,13 @@ public:
using TaskExecutor::AddSyncTask;
using TaskExecutor::StopThread;
int32_t SetParameter(const std::string &keyValueList);
std::string GetParameter(const std::string &key);
std::string GetWakeupCapability();
int32_t GetWakeupSourceFilesList(std::vector<std::string>& cloneFiles);
int32_t GetWakeupSourceFile(const std::string &filePath, std::vector<uint8_t> &buffer);
int32_t SendWakeupFile(const std::string &filePath, const std::vector<uint8_t> &buffer);
void SetDspSensibility(const std::string &sensibility);
private:
IntellVoiceServiceManager();
@ -145,7 +148,8 @@ private:
private:
static std::unique_ptr<IntellVoiceServiceManager> g_intellVoiceServiceMgr;
static std::atomic<bool> enrollResult_[ENGINE_TYPE_BUT];
static std::atomic<bool> g_enrollResult[ENGINE_TYPE_BUT];
static std::vector<int32_t> g_defaultDspSentenceThresholds;
std::mutex deathMutex_;
std::mutex detectorMutex_;
std::mutex switchMutex_;

View File

@ -38,6 +38,8 @@ IntellVoiceServiceStub::IntellVoiceServiceStub()
MessageParcel &reply) -> int32_t { return this->SendCloneFileInner(data, reply); };
processServiceFuncMap_[HDI_INTELL_VOICE_SERVICE_CLONE_FOR_RESULT] = [this](MessageParcel &data,
MessageParcel &reply) -> int32_t { return this->CloneForResultInner(data, reply); };
processServiceFuncMap_[HDI_INTELL_VOICE_SERVICE_SET_PARAMETER] = [this](MessageParcel &data,
MessageParcel &reply) -> int32_t { return this->SetParameterInner(data, reply); };
}
IntellVoiceServiceStub::~IntellVoiceServiceStub()
@ -112,6 +114,13 @@ int32_t IntellVoiceServiceStub::GetParameterInner(MessageParcel &data, MessagePa
return 0;
}
int32_t IntellVoiceServiceStub::SetParameterInner(MessageParcel &data, MessageParcel &reply)
{
int32_t ret = SetParameter(data.ReadString());
reply.WriteInt32(ret);
return ret;
}
int32_t IntellVoiceServiceStub::GetCloneFileListInner(MessageParcel &data, MessageParcel &reply)
{
int32_t ret = 0;

View File

@ -36,6 +36,7 @@ private:
std::map<uint32_t, std::function<int32_t(MessageParcel &data, MessageParcel &reply)>> processServiceFuncMap_;
int32_t CreateEngineInner(MessageParcel &data, MessageParcel &reply);
int32_t ReleaseEngineInner(MessageParcel &data, MessageParcel &reply);
int32_t SetParameterInner(MessageParcel &data, MessageParcel &reply);
int32_t GetParameterInner(MessageParcel &data, MessageParcel &reply);
int32_t GetReportedFilesInner(MessageParcel &data, MessageParcel &reply);
int32_t GetCloneFileListInner(MessageParcel &data, MessageParcel &reply);

View File

@ -29,6 +29,7 @@ const std::string KEY_WAKEUP_ENGINE_ABILITY_NAME = "WakeupEngineAbilityName";
const std::string KEY_WAKEUP_VESRION = "WakeupVersion";
const std::string KEY_LANGUAGE = "Language";
const std::string KEY_AREA = "Area";
const std::string KEY_SENSIBILITY = "Sensibility";
const std::string KEY_WAKEUP_PHRASE = "WakeupPhrase";
const std::string KEY_WAKEUP_DSP_FEATURE = "WakeupDspFeature";
@ -98,6 +99,16 @@ std::string HistoryInfoMgr::GetArea()
return GetValue(KEY_AREA);
}
void HistoryInfoMgr::SetSensibility(const std::string &sensibility)
{
SetValue(KEY_SENSIBILITY, sensibility);
}
std::string HistoryInfoMgr::GetSensibility()
{
return GetValue(KEY_SENSIBILITY);
}
void HistoryInfoMgr::SetWakeupPhrase(const std::string &wakeupPhrase)
{
SetValue(KEY_WAKEUP_PHRASE, wakeupPhrase);

View File

@ -43,6 +43,8 @@ public:
std::string GetLanguage();
void SetArea(const std::string &area);
std::string GetArea();
void SetSensibility(const std::string &sensibility);
std::string GetSensibility();
void SetWakeupPhrase(const std::string &wakeupPhrase);
std::string GetWakeupPhrase();
void SetWakeupDspFeature(const std::string &wakeupDspFeature);

View File

@ -50,7 +50,7 @@ bool HeadsetWakeupEngineImpl::Init()
}
adapterListener_ = std::make_shared<WakeupAdapterListener>(
std::bind(&HeadsetWakeupEngineImpl::OnWakeupEvent, this, std::placeholders::_1, std::placeholders::_2));
std::bind(&HeadsetWakeupEngineImpl::OnWakeupEvent, this, std::placeholders::_1));
if (adapterListener_ == nullptr) {
INTELL_VOICE_LOG_ERROR("adapterListener_ is nullptr");
return false;
@ -148,13 +148,16 @@ int32_t HeadsetWakeupEngineImpl::AttachInner(const IntellVoiceEngineInfo &info)
return adapter_->Attach(adapterInfo);
}
void HeadsetWakeupEngineImpl::OnWakeupEvent(int32_t msgId, int32_t result)
void HeadsetWakeupEngineImpl::OnWakeupEvent(
const OHOS::HDI::IntelligentVoice::Engine::V1_0::IntellVoiceEngineCallBackEvent &event)
{
INTELL_VOICE_LOG_INFO("enter, msgId:%{public}d, result:%{public}d", msgId, result);
if (msgId == INTELL_VOICE_ENGINE_MSG_INIT_DONE) {
std::thread(&HeadsetWakeupEngineImpl::OnInitDone, this, result).detach();
} else if (msgId == HDI::IntelligentVoice::Engine::V1_2::INTELL_VOICE_ENGINE_MSG_HEADSET_RECOGNIZE_COMPLETE) {
std::thread(&HeadsetWakeupEngineImpl::OnWakeupRecognition, this, result).detach();
INTELL_VOICE_LOG_INFO("enter, msgId:%{public}d, result:%{public}d", event.msgId, event.result);
if (event.msgId == INTELL_VOICE_ENGINE_MSG_INIT_DONE) {
std::thread(&HeadsetWakeupEngineImpl::OnInitDone, this, event.result).detach();
} else if (
event.msgId == static_cast<OHOS::HDI::IntelligentVoice::Engine::V1_0::IntellVoiceEngineMessageType>(
OHOS::HDI::IntelligentVoice::Engine::V1_2::INTELL_VOICE_ENGINE_MSG_HEADSET_RECOGNIZE_COMPLETE)) {
std::thread(&HeadsetWakeupEngineImpl::OnWakeupRecognition, this, event.result, event.info).detach();
} else {
}
}
@ -166,10 +169,16 @@ void HeadsetWakeupEngineImpl::OnInitDone(int32_t result)
Handle(msg);
}
void HeadsetWakeupEngineImpl::OnWakeupRecognition(int32_t result)
void HeadsetWakeupEngineImpl::OnWakeupRecognition(int32_t result, const std::string &info)
{
INTELL_VOICE_LOG_INFO("enter, result:%{public}d", result);
StateMsg msg(RECOGNIZE_COMPLETE, &result, sizeof(int32_t));
OHOS::HDI::IntelligentVoice::Engine::V1_0::IntellVoiceEngineCallBackEvent event;
event.msgId = static_cast<OHOS::HDI::IntelligentVoice::Engine::V1_0::IntellVoiceEngineMessageType>(
HDI::IntelligentVoice::Engine::V1_2::INTELL_VOICE_ENGINE_MSG_HEADSET_RECOGNIZE_COMPLETE);
event.result = static_cast<OHOS::HDI::IntelligentVoice::Engine::V1_0::IntellVoiceEngineErrors>(result);
event.info = info;
StateMsg msg(RECOGNIZE_COMPLETE, reinterpret_cast<void *>(&event),
sizeof(OHOS::HDI::IntelligentVoice::Engine::V1_0::IntellVoiceEngineCallBackEvent));
Handle(msg);
}
@ -303,12 +312,16 @@ int32_t HeadsetWakeupEngineImpl::HandleStop(const StateMsg & /* msg */, State &n
int32_t HeadsetWakeupEngineImpl::HandleRecognizeComplete(const StateMsg &msg, State &nextState)
{
EngineUtil::Stop();
int32_t *result = reinterpret_cast<int32_t *>(msg.inMsg);
if (result == nullptr) {
INTELL_VOICE_LOG_ERROR("result is nullptr");
OHOS::HDI::IntelligentVoice::Engine::V1_0::IntellVoiceEngineCallBackEvent *event =
reinterpret_cast<OHOS::HDI::IntelligentVoice::Engine::V1_0::IntellVoiceEngineCallBackEvent *>(msg.inMsg);
if (event == nullptr) {
INTELL_VOICE_LOG_ERROR("event is nullptr");
return -1;
}
if (*result != 0) {
adapterListener_->Notify(*event);
if (event->result != 0) {
INTELL_VOICE_LOG_INFO("wakeup failed");
StopAudioSource();
NotifyVerifyResult(false);

View File

@ -56,9 +56,9 @@ private:
private:
bool SetCallbackInner();
int32_t AttachInner(const IntellVoiceEngineInfo &info);
void OnWakeupEvent(int32_t msgId, int32_t result);
void OnWakeupEvent(const OHOS::HDI::IntelligentVoice::Engine::V1_0::IntellVoiceEngineCallBackEvent &event);
void OnInitDone(int32_t result);
void OnWakeupRecognition(int32_t result);
void OnWakeupRecognition(int32_t result, const std::string &info);
bool StartAudioSource();
void StopAudioSource();
void ReadThread();

View File

@ -52,25 +52,24 @@ void WakeupAdapterListener::SetCallback(const sptr<IIntelligentVoiceEngineCallba
void WakeupAdapterListener::OnIntellVoiceHdiEvent(const IntellVoiceEngineCallBackEvent &event)
{
INTELL_VOICE_LOG_INFO("OnIntellVoiceHdiEvent");
wakeupEventCb_(event.msgId, event.result);
INTELL_VOICE_LOG_INFO("enter");
wakeupEventCb_(event);
}
{
std::lock_guard<std::mutex> lock(mutex_);
if (cb_ == nullptr) {
INTELL_VOICE_LOG_WARN("cb_ is nullptr");
BackupCallBackEvent(event);
return;
}
void WakeupAdapterListener::Notify(const IntellVoiceEngineCallBackEvent &event)
{
std::lock_guard<std::mutex> lock(mutex_);
if (cb_ == nullptr) {
INTELL_VOICE_LOG_WARN("cb_ is nullptr");
BackupCallBackEvent(event);
return;
}
historyEvent_ = nullptr;
if ((event.msgId == OHOS::HDI::IntelligentVoice::Engine::V1_0::INTELL_VOICE_ENGINE_MSG_RECOGNIZE_COMPLETE) ||
(event.msgId == static_cast<OHOS::HDI::IntelligentVoice::Engine::V1_0::IntellVoiceEngineMessageType>(
INTELL_VOICE_ENGINE_MSG_RECONFIRM_RECOGNITION_COMPLETE)) || (
event.msgId == static_cast<OHOS::HDI::IntelligentVoice::Engine::V1_0::IntellVoiceEngineMessageType>(
INTELL_VOICE_ENGINE_MSG_HEADSET_RECOGNIZE_COMPLETE))) {
cb_->OnIntellVoiceEngineEvent(event);
}
historyEvent_ = nullptr;
if ((event.msgId == OHOS::HDI::IntelligentVoice::Engine::V1_0::INTELL_VOICE_ENGINE_MSG_RECOGNIZE_COMPLETE) ||
(event.msgId == static_cast<OHOS::HDI::IntelligentVoice::Engine::V1_0::IntellVoiceEngineMessageType>(
INTELL_VOICE_ENGINE_MSG_HEADSET_RECOGNIZE_COMPLETE))) {
cb_->OnIntellVoiceEngineEvent(event);
}
}

View File

@ -23,7 +23,8 @@
namespace OHOS {
namespace IntellVoiceEngine {
using OnWakeupEventCb = std::function<void(int32_t, int32_t)>;
using OnWakeupEventCb = std::function<void(
const OHOS::HDI::IntelligentVoice::Engine::V1_0::IntellVoiceEngineCallBackEvent &)>;
class WakeupAdapterListener : public IntellVoiceAdapterListener {
public:
@ -33,6 +34,7 @@ public:
void SetCallback(const sptr<IIntelligentVoiceEngineCallback> &cb);
void OnIntellVoiceHdiEvent(
const OHOS::HDI::IntelligentVoice::Engine::V1_0::IntellVoiceEngineCallBackEvent &event) override;
void Notify(const OHOS::HDI::IntelligentVoice::Engine::V1_0::IntellVoiceEngineCallBackEvent &event);
private:
void BackupCallBackEvent(const OHOS::HDI::IntelligentVoice::Engine::V1_0::IntellVoiceEngineCallBackEvent &event);

View File

@ -53,7 +53,7 @@ WakeupEngineImpl::WakeupEngineImpl() : ModuleStates(State(IDLE), "WakeupEngineIm
capturerOptions_.capturerInfo.sourceType = SourceType::SOURCE_TYPE_WAKEUP;
capturerOptions_.capturerInfo.capturerFlags = 0;
adapterListener_ = std::make_shared<WakeupAdapterListener>(
std::bind(&WakeupEngineImpl::OnWakeupEvent, this, std::placeholders::_1, std::placeholders::_2));
std::bind(&WakeupEngineImpl::OnWakeupEvent, this, std::placeholders::_1));
if (adapterListener_ == nullptr) {
INTELL_VOICE_LOG_ERROR("adapterListener_ is nullptr");
}
@ -94,16 +94,14 @@ bool WakeupEngineImpl::InitStates()
std::bind(&WakeupEngineImpl::HandleStopCapturer, this, std::placeholders::_1, std::placeholders::_2),
RECOGNIZE_COMPLETE_TIMEOUT_US)
.ACT(GET_WAKEUP_PCM, HandleGetWakeupPcm)
.ACT(START_CAPTURER, HandleStartCapturer)
.ACT(RECONFIRM_RECOGNITION_COMPLETE, HandleReconfirmRecognitionComplete);
.ACT(START_CAPTURER, HandleStartCapturer);
ForState(READ_CAPTURER)
.WaitUntil(READ_CAPTURER_TIMEOUT,
std::bind(&WakeupEngineImpl::HandleStopCapturer, this, std::placeholders::_1, std::placeholders::_2),
READ_CAPTURER_TIMEOUT_US)
.ACT(READ, HandleRead)
.ACT(STOP_CAPTURER, HandleStopCapturer)
.ACT(RECONFIRM_RECOGNITION_COMPLETE, HandleReconfirmRecognitionComplete);
.ACT(STOP_CAPTURER, HandleStopCapturer);
FromState(INITIALIZING, READ_CAPTURER)
.ACT(RELEASE_ADAPTER, HandleRelease)
@ -154,7 +152,7 @@ bool WakeupEngineImpl::SetCallbackInner()
}
if (adapterListener_ == nullptr) {
INTELL_VOICE_LOG_ERROR("adapterListener_ is nullptr");
INTELL_VOICE_LOG_ERROR("adapter listener is nullptr");
return false;
}
@ -316,16 +314,15 @@ void WakeupEngineImpl::StopAudioSource()
WakeupSourceProcess::Release();
}
void WakeupEngineImpl::OnWakeupEvent(int32_t msgId, int32_t result)
void WakeupEngineImpl::OnWakeupEvent(
const OHOS::HDI::IntelligentVoice::Engine::V1_0::IntellVoiceEngineCallBackEvent &event)
{
if (msgId == INTELL_VOICE_ENGINE_MSG_INIT_DONE) {
std::thread(&WakeupEngineImpl::OnInitDone, this, result).detach();
} else if (msgId == INTELL_VOICE_ENGINE_MSG_RECOGNIZE_COMPLETE) {
std::thread(&WakeupEngineImpl::OnWakeupRecognition, this, result).detach();
} else if (msgId == static_cast<OHOS::HDI::IntelligentVoice::Engine::V1_0::IntellVoiceEngineMessageType>(
HDI::IntelligentVoice::Engine::V1_2::INTELL_VOICE_ENGINE_MSG_RECONFIRM_RECOGNITION_COMPLETE)) {
std::thread(&WakeupEngineImpl::OnWakeupKws3Recognition, this, result).detach();
if (event.msgId == INTELL_VOICE_ENGINE_MSG_INIT_DONE) {
std::thread(&WakeupEngineImpl::OnInitDone, this, event.result).detach();
} else if (event.msgId == INTELL_VOICE_ENGINE_MSG_RECOGNIZE_COMPLETE) {
std::thread(&WakeupEngineImpl::OnWakeupRecognition, this, event.result, event.info).detach();
} else {
INTELL_VOICE_LOG_WARN("invalid msg id:%{public}d", event.msgId);
}
}
@ -336,17 +333,15 @@ void WakeupEngineImpl::OnInitDone(int32_t result)
Handle(msg);
}
void WakeupEngineImpl::OnWakeupRecognition(int32_t result)
void WakeupEngineImpl::OnWakeupRecognition(int32_t result, const std::string &info)
{
INTELL_VOICE_LOG_INFO("on wakeup recognition, result:%{public}d", result);
StateMsg msg(RECOGNIZE_COMPLETE, &result, sizeof(int32_t));
Handle(msg);
}
void WakeupEngineImpl::OnWakeupKws3Recognition(int32_t result)
{
INTELL_VOICE_LOG_INFO("on wakeup kws3 recognition, result:%{public}d", result);
StateMsg msg(RECONFIRM_RECOGNITION_COMPLETE, &result, sizeof(int32_t));
OHOS::HDI::IntelligentVoice::Engine::V1_0::IntellVoiceEngineCallBackEvent event;
event.msgId = INTELL_VOICE_ENGINE_MSG_RECOGNIZE_COMPLETE;
event.result = static_cast<OHOS::HDI::IntelligentVoice::Engine::V1_0::IntellVoiceEngineErrors>(result);
event.info = info;
StateMsg msg(RECOGNIZE_COMPLETE, reinterpret_cast<void *>(&event),
sizeof(OHOS::HDI::IntelligentVoice::Engine::V1_0::IntellVoiceEngineCallBackEvent));
Handle(msg);
}
@ -389,6 +384,7 @@ int32_t WakeupEngineImpl::HandleInit(const StateMsg & /* msg */, State &nextStat
UpdateDspModel();
EngineUtil::SetLanguage();
EngineUtil::SetArea();
EngineUtil::SetSensibility();
SetDspFeatures();
IntellVoiceEngineInfo info = {
@ -441,7 +437,13 @@ int32_t WakeupEngineImpl::HandleStart(const StateMsg &msg, State &nextState)
return -1;
}
channelId_ = ((*msgBody == PROXIMAL_WAKEUP_MODEL_UUID) ? CHANNEL_ID_1 : CHANNEL_ID_0);
if (*msgBody == PROXIMAL_WAKEUP_MODEL_UUID) {
channelId_ = CHANNEL_ID_1;
EngineUtil::SetParameter("WakeupType=3");
} else {
channelId_ = CHANNEL_ID_0;
EngineUtil::SetParameter("WakeupType=0");
}
INTELL_VOICE_LOG_INFO("enter, channel id is %{public}d", channelId_);
EngineUtil::SetParameter("VprTrdType=0;WakeupScene=0");
@ -489,24 +491,24 @@ int32_t WakeupEngineImpl::HandleStop(const StateMsg & /* msg */, State &nextStat
int32_t WakeupEngineImpl::HandleRecognizeComplete(const StateMsg &msg, State &nextState)
{
int32_t *result = reinterpret_cast<int32_t *>(msg.inMsg);
if (result == nullptr) {
OHOS::HDI::IntelligentVoice::Engine::V1_0::IntellVoiceEngineCallBackEvent *event =
reinterpret_cast<OHOS::HDI::IntelligentVoice::Engine::V1_0::IntellVoiceEngineCallBackEvent *>(msg.inMsg);
if (event == nullptr) {
INTELL_VOICE_LOG_ERROR("result is nullptr");
return -1;
}
if (*result != 0) {
if (adapterListener_ != nullptr) {
adapterListener_->Notify(*event);
}
if (event->result != 0) {
INTELL_VOICE_LOG_ERROR("wakeup failed");
StopAudioSource();
EngineUtil::Stop();
nextState = State(INITIALIZED);
} else {
nextState = State(RECOGNIZED);
}
return 0;
}
int32_t WakeupEngineImpl::HandleReconfirmRecognitionComplete(const StateMsg &msg, State &nextState)
{
EngineUtil::Stop();
return 0;
}

View File

@ -59,10 +59,10 @@ private:
void SetParamOnAudioStop();
bool CreateWakeupSourceStopCallback();
void DestroyWakeupSourceStopCallback();
void OnWakeupEvent(int32_t msgId, int32_t result);
void OnWakeupEvent(const OHOS::HDI::IntelligentVoice::Engine::V1_0::IntellVoiceEngineCallBackEvent &event);
void OnInitDone(int32_t result);
void OnWakeupRecognition(int32_t result);
void OnWakeupKws3Recognition(int32_t result);
void OnWakeupRecognition(int32_t result, const std::string &info);
void OnWakeupKws3Recognition(int32_t result, const std::string &info);
void UpdateDspModel();
OHOS::AudioStandard::AudioChannel GetWakeupSourceChannel();

View File

@ -30,6 +30,11 @@ public:
PROXIMAL_WAKEUP_TYPE = 2,
};
enum TriggerModelVersion {
MODLE_VERSION_1 = 1,
MODLE_VERSION_2 = 2,
};
TriggerModel(int32_t uuid, int32_t version, TriggerModelType type);
virtual ~TriggerModel();

View File

@ -17,10 +17,11 @@
#include <string>
#include "intell_voice_log.h"
#include "rdb_errno.h"
#include "rdb_helper.h"
#include "rdb_open_callback.h"
#include "intell_voice_log.h"
#include "intell_voice_service_manager.h"
#define LOG_TAG "TriggerDbHelper"
@ -229,9 +230,14 @@ std::shared_ptr<GenericTriggerModel> TriggerDbHelper::GetGenericTriggerModel(con
}
int32_t type;
if (!GetModelType(set, type)) {
INTELL_VOICE_LOG_ERROR("failed to get model type");
return nullptr;
if (modelVersion >= static_cast<int32_t>(TriggerModel::TriggerModelVersion::MODLE_VERSION_2)) {
if (!GetModelType(set, type)) {
INTELL_VOICE_LOG_ERROR("failed to get model type");
return nullptr;
}
} else {
type = (modelUuid == OHOS::IntellVoiceEngine::VOICE_WAKEUP_MODEL_UUID ?
TriggerModel::TriggerModelType::VOICE_WAKEUP_TYPE : TriggerModel::TriggerModelType::PROXIMAL_WAKEUP_TYPE);
}
std::shared_ptr<GenericTriggerModel> model = std::make_shared<GenericTriggerModel>(modelUuid, modelVersion,

View File

@ -92,7 +92,8 @@ void TriggerManagerTest::ReadFile(const std::string &path)
HWTEST_F(TriggerManagerTest, start_recognition_001, TestSize.Level1)
{
int32_t uuid = 11;
auto model = std::make_shared<GenericTriggerModel>(uuid, 100, TriggerModel::TriggerModelType::VOICE_WAKEUP_TYPE);
auto model = std::make_shared<GenericTriggerModel>(uuid, TriggerModel::TriggerModelVersion::MODLE_VERSION_2,
TriggerModel::TriggerModelType::VOICE_WAKEUP_TYPE);
model->SetData(modelData);
triggerManager->UpdateModel(model);

View File

@ -58,7 +58,8 @@ HWTEST_F(TriggerTest, trigger_db_helper_001, TestSize.Level1)
{
// insert model
int32_t uuid = 11;
auto model = std::make_shared<GenericTriggerModel>(uuid, 100, TriggerModel::TriggerModelType::VOICE_WAKEUP_TYPE);
auto model = std::make_shared<GenericTriggerModel>(uuid, TriggerModel::TriggerModelVersion::MODLE_VERSION_2,
TriggerModel::TriggerModelType::VOICE_WAKEUP_TYPE);
uint8_t data[4] = {0, 1, 2, 3};
model->SetData(data, sizeof(data));
std::vector<uint8_t> expect(data, data + (sizeof(data) / sizeof(uint8_t)));

View File

@ -13,6 +13,7 @@
* limitations under the License.
*/
#include "intell_voice_util.h"
#include <sys/stat.h>
#include <memory>
#include <malloc.h>
#include <fcntl.h>
@ -20,7 +21,7 @@
#include <unistd.h>
#include <cinttypes>
#include <fstream>
#include "string_util.h"
#include "accesstoken_kit.h"
#include "tokenid_kit.h"
#include "ipc_skeleton.h"
@ -88,6 +89,31 @@ bool IntellVoiceUtil::ReadFile(const std::string &filePath, std::shared_ptr<uint
return true;
}
void IntellVoiceUtil::SplitStringToKVPair(const std::string &inputStr, std::map<std::string, std::string> &kvpairs)
{
std::vector<std::string> paramsList;
StringUtil::Split(inputStr, ";", paramsList);
for (auto &it : paramsList) {
std::string key;
std::string value;
if (StringUtil::SplitLineToPair(it, key, value)) {
kvpairs[key] = value;
INTELL_VOICE_LOG_INFO("key:%{public}s, value:%{public}s", key.c_str(), value.c_str());
}
}
}
bool IntellVoiceUtil::IsFileExist(const std::string &filePath)
{
struct stat sb;
if (stat(filePath.c_str(), &sb) != 0) {
INTELL_VOICE_LOG_ERROR("get file status failed");
return false;
}
return true;
}
bool IntellVoiceUtil::VerifyClientPermission(const std::string &permissionName)
{
Security::AccessToken::AccessTokenID clientTokenId = IPCSkeleton::GetCallingTokenID();

View File

@ -18,6 +18,7 @@
#include <string>
#include <vector>
#include <memory>
#include <map>
namespace OHOS {
namespace IntellVoiceUtils {
@ -28,6 +29,8 @@ public:
std::vector<std::vector<uint8_t>> &audioData);
static bool VerifySystemPermission(const std::string &permissionName);
static bool ReadFile(const std::string &filePath, std::shared_ptr<uint8_t> &buffer, uint32_t &size);
static void SplitStringToKVPair(const std::string &inputStr, std::map<std::string, std::string> &kvpairs);
static bool IsFileExist(const std::string &filePath);
private:
static bool VerifyClientPermission(const std::string &permissionName);