Signed-off-by: lvqiang214 <lvqiang1@huawei.com>
This commit is contained in:
lvqiang214 2024-08-17 14:59:04 +08:00
parent 64a8b2dec2
commit 23fc4a7871
12 changed files with 69 additions and 23 deletions

View File

@ -627,15 +627,13 @@ napi_value EnrollIntellVoiceEngineNapi::EvaluateForResult(napi_env env, napi_cal
}
context->complete_ = [](napi_env env, AsyncContext *asyncContext, napi_value &result) {
INTELL_VOICE_LOG_INFO("enter to evaluate");
auto context = static_cast<EvaluateContext *>(asyncContext);
napi_status status = napi_create_object(env, &result);
if (status != napi_ok || result == nullptr) {
INTELL_VOICE_LOG_ERROR("failed to create js callbackInfo, error: %{public}d", status);
INTELL_VOICE_LOG_ERROR("failed to create object, status: %{public}d", status);
context->result_ = NAPI_INTELLIGENT_VOICE_NO_MEMORY;
return;
}
napi_set_named_property(env, result, "score", SetValue(env, context->info.score));
napi_set_named_property(env, result, "resultCode", SetValue(env, context->info.resultCode));
};

View File

@ -19,9 +19,13 @@
#include "history_info_mgr.h"
#include "intell_voice_log.h"
#include "string_util.h"
#define LOG_TAG "IntellVoiceSensibility"
using namespace std;
using namespace OHOS::IntellVoiceUtils;
namespace OHOS {
namespace IntellVoiceEngine {
static constexpr int32_t MIN_SENSIBILITY_VALUE = 1;
@ -33,7 +37,11 @@ static const std::string WAKEUP_CONF_DEFAULPHRASE = "DefaultPhrase";
std::string IntellVoiceSensibility::GetDspSensibility(const std::string &sensibility, const std::string &dspFeature,
const std::string &configPath)
{
int32_t value = std::stoi(sensibility);
int32_t value = 0;
if (!StringUtil::StringToInt(sensibility, value)) {
INTELL_VOICE_LOG_ERROR("failed to get sensibility");
return "";
}
if ((value < MIN_SENSIBILITY_VALUE) || (value > MAX_SENSIBILITY_VALUE)) {
INTELL_VOICE_LOG_WARN("invalid sensibility:%{public}d", value);
return "";
@ -68,7 +76,7 @@ std::string IntellVoiceSensibility::ParseWakeupConfigDspSensibility(const std::s
return ParseDefaultDspSensibility(wakeupJson, wakeupPhrase, index);
}
return ParseUserDspSensibility(wakeupJson, wakeupPhrase, index);
return ParseUserDspSensibility(wakeupJson, index);
}
std::string IntellVoiceSensibility::ParseDefaultDspSensibility(const Json::Value &wakeupJson,
@ -99,8 +107,7 @@ std::string IntellVoiceSensibility::ParseDefaultDspSensibility(const Json::Value
return "";
}
std::string IntellVoiceSensibility::ParseUserDspSensibility(const Json::Value &wakeupJson,
const std::string &wakeupPhrase, uint32_t index)
std::string IntellVoiceSensibility::ParseUserDspSensibility(const Json::Value &wakeupJson, uint32_t index)
{
if ((!wakeupJson.isMember("SensibilityParams")) ||
(!wakeupJson["SensibilityParams"].isMember("DspSentenceThresholds"))) {
@ -141,7 +148,12 @@ bool IntellVoiceSensibility::IsSupportNodes800(const std::string &dspFeature)
return false;
}
int feature = std::stoi(dspFeature);
int32_t feature = 0;
if (!StringUtil::StringToInt(dspFeature, feature)) {
INTELL_VOICE_LOG_ERROR("failed to get dsp feature");
return false;
}
if ((feature & HAL_FEATURE_KWS_NODES_900) == HAL_FEATURE_KWS_NODES_900) {
return true;
}

View File

@ -29,8 +29,7 @@ public:
private:
static std::string ParseDefaultDspSensibility(const Json::Value &wakeupJson, const std::string &wakeupPhrase,
uint32_t index);
static std::string ParseUserDspSensibility(const Json::Value &wakeupJson, const std::string &wakeupPhrase,
uint32_t index);
static std::string ParseUserDspSensibility(const Json::Value &wakeupJson, uint32_t index);
static std::string ParseWakeupConfigDspSensibility(const std::string &wakeupPhrase, uint32_t index,
const std::string &configPath);
static bool IsDefaltPhrase(const Json::Value &wakeupJson, const std::string &wakeupPhrase);

View File

@ -61,7 +61,7 @@ void EnrollEngine::OnEnrollEvent(int32_t msgId, int32_t result)
} else if (msgId == INTELL_VOICE_ENGINE_MSG_COMMIT_ENROLL_COMPLETE) {
std::lock_guard<std::mutex> lock(mutex_);
enrollResult_ = result;
IntellVoiceServiceManager::SetEnrollResult(INTELL_VOICE_ENROLL, result == 0 ? true : false);
IntellVoiceServiceManager::SetEnrollResult(INTELL_VOICE_ENROLL, enrollResult_ == 0 ? true : false);
}
}
@ -122,7 +122,7 @@ int32_t EnrollEngine::Attach(const IntellVoiceEngineInfo &info)
SetDspFeatures();
isPcmFromExternal_ = info.isPcmFromExternal;
HistoryInfoMgr::GetInstance().SetWakeupPhrase(info.wakeupPhrase);
wakeupPhrase_ = info.wakeupPhrase;
IntellVoiceEngineAdapterInfo adapterInfo = {
.wakeupPhrase = info.wakeupPhrase,
@ -146,6 +146,7 @@ int32_t EnrollEngine::Detach(void)
if (enrollResult_ == 0) {
ProcDspModel(OHOS::HDI::IntelligentVoice::Engine::V1_0::DSP_MODLE);
HistoryInfoMgr::GetInstance().SetWakeupPhrase(wakeupPhrase_);
/* save new version number */
UpdateEngineUtils::SaveWakeupVesion();
INTELL_VOICE_LOG_INFO("enroll save version");

View File

@ -54,6 +54,7 @@ private:
int32_t enrollResult_ = -1;
sptr<OHOS::HDI::IntelligentVoice::Engine::V1_0::IIntellVoiceEngineCallback> callback_ = nullptr;
std::unique_ptr<AudioSource> audioSource_ = nullptr;
std::string wakeupPhrase_;
std::mutex mutex_;
OHOS::AudioStandard::AudioCapturerOptions capturerOptions_;
friend class IntellVoiceUtils::SptrFactory<EngineBase, EnrollEngine>;

View File

@ -115,12 +115,18 @@ bool UpdateEngineUtils::IsVersionUpdate()
return false;
}
if (stoi(versionNumberCur) > stoi(versionNumberSave)) {
INTELL_VOICE_LOG_INFO("version new %{public}d cur %{public}d",
stoi(versionNumberCur), stoi(versionNumberSave));
return true;
int32_t historyVersion = 0;
int32_t curVersion = 0;
if ((!StringUtil::StringToInt(versionNumberSave, historyVersion)) ||
(!StringUtil::StringToInt(versionNumberCur, curVersion))) {
INTELL_VOICE_LOG_ERROR("failed to get version");
return false;
}
if (curVersion > historyVersion) {
INTELL_VOICE_LOG_INFO("version new %{public}d, cur %{public}d", curVersion, historyVersion);
return true;
}
return false;
}
}

View File

@ -75,6 +75,7 @@ void WakeupEngine::SetCallback(sptr<IRemoteObject> object)
if (callback == nullptr) {
INTELL_VOICE_LOG_WARN("clear callback");
}
callback_ = callback;
SetListenerMsg listenerMsg(callback);
StateMsg msg(SET_LISTENER, &listenerMsg, sizeof(SetListenerMsg));
ROLE(WakeupEngineImpl).Handle(msg);
@ -179,6 +180,12 @@ int32_t WakeupEngine::HandleHeadsetOn()
return -1;
}
SetListenerMsg listenerMsg(callback_);
StateMsg msgCb(SET_LISTENER, &listenerMsg, sizeof(SetListenerMsg));
if (headsetImpl_ != nullptr) {
headsetImpl_->Handle(msgCb);
}
StateMsg msg(INIT);
if (headsetImpl_->Handle(msg) != 0) {
INTELL_VOICE_LOG_ERROR("init headset wakeup engine impl failed");

View File

@ -58,6 +58,7 @@ private:
OHOS::IntellVoiceUtils::UniqueProductType<HeadsetWakeupEngineImpl> headsetImpl_ =
OHOS::IntellVoiceUtils::UniqueProductType<HeadsetWakeupEngineImpl>(nullptr, nullptr);
std::mutex headsetMutex_;
sptr<IIntelligentVoiceEngineCallback> callback_ = nullptr;
};
}
}

View File

@ -20,6 +20,7 @@
#include "intell_voice_log.h"
#include "history_info_mgr.h"
#include "intell_voice_util.h"
#include "string_util.h"
#include "intell_voice_service_manager.h"
#include "trigger_manager.h"
#include "engine_host_manager.h"
@ -135,13 +136,19 @@ OHOS::AudioStandard::AudioChannel WakeupEngineImpl::GetWakeupSourceChannel()
return AudioChannel::MONO;
}
auto ret = static_cast<OHOS::AudioStandard::AudioChannel>(std::stoi(channel));
if (ret > AudioChannel::CHANNEL_4) {
INTELL_VOICE_LOG_INFO("invalid channel, ret:%{public}d", ret);
int32_t channelCnt = 0;
if (!StringUtil::StringToInt(channel, channelCnt)) {
INTELL_VOICE_LOG_ERROR("failed to get channel cnt");
return AudioChannel::MONO;
}
INTELL_VOICE_LOG_INFO("channle:%{public}d", static_cast<int32_t>(ret));
return ret;
if ((channelCnt < AudioChannel::MONO) || (channelCnt > AudioChannel::CHANNEL_4)) {
INTELL_VOICE_LOG_INFO("invalid channel cnt:%{public}d", channelCnt);
return AudioChannel::MONO;
}
INTELL_VOICE_LOG_INFO("channel cnt:%{public}d", static_cast<int32_t>(channelCnt));
return static_cast<OHOS::AudioStandard::AudioChannel>(channelCnt);
}
bool WakeupEngineImpl::SetCallbackInner()

View File

@ -12,12 +12,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "string_util.h"
#include <fstream>
#include <iterator>
#include <ctime>
#include <sys/time.h>
#include <climits>
#include "intell_voice_log.h"
#undef LOG_TAG
@ -138,6 +139,18 @@ bool StringUtil::SplitLineToPair(const std::string &line, std::string &first, st
}
return true;
}
bool StringUtil::StringToInt(const std::string &str, int32_t &val)
{
char *endStr = nullptr;
long int conVal = std::strtol(str.c_str(), &endStr, 10); // decimal
if (conVal == LONG_MAX || conVal == LONG_MIN || endStr == nullptr || endStr == str.c_str() || *endStr != '\0') {
return false;
}
val = static_cast<int32_t>(conVal);
return true;
}
}
}

View File

@ -42,6 +42,7 @@ public:
static void TrimSpecialChars(std::string &str);
static uint32_t CalSubStrNum(const std::string &str, const std::string &subStr);
static bool SplitLineToPair(const std::string &line, std::string &first, std::string &second);
static bool StringToInt(const std::string &str, int32_t &val);
private:
DISALLOW_COPY_AND_MOVE(StringUtil);

View File

@ -183,7 +183,7 @@ int TimerMgr::ResetTimer(int timerId, int type, int64_t delayUs, int cookie, ITi
void TimerMgr::KillTimer(int &timerId)
{
std::unique_lock<ffrt::mutex> lock(timeMutex_);
INTELL_VOICE_LOG_INFO("kill timer %d", timerId);
INTELL_VOICE_LOG_INFO("kill timer %{public}d", timerId);
for (auto it = itemQueue_.begin(); it != itemQueue_.end(); it++) {
shared_ptr<TimerItem> curItem = *it;
if (curItem->timerId == timerId) {