add static sdk support

Signed-off-by: yuzhicheng <yuzhicheng1@huawei.com>
This commit is contained in:
yuzhicheng
2025-11-22 15:34:06 +08:00
committed by haoqingqi
parent a42be6ef07
commit 8fffb8b358
28 changed files with 2335 additions and 164 deletions
+3 -1
View File
@@ -66,7 +66,9 @@
"//foundation/ai/intelligent_voice_framework/frameworks/js:intelligentvoice_js",
"//foundation/ai/intelligent_voice_framework/frameworks/native:intellvoice_native",
"//foundation/ai/intelligent_voice_framework/sa_profile:intell_voice_service_sa_profile",
"//foundation/ai/intelligent_voice_framework/utils:intell_voice_utils"
"//foundation/ai/intelligent_voice_framework/utils:intell_voice_utils",
"//foundation/ai/intelligent_voice_framework/frameworks/taihe:intelligent_voice_framework_taihe",
"//foundation/ai/intelligent_voice_framework/frameworks/taihe:intelligent_voice_framework_taihe_gen_only"
],
"inner_kits": [
{
@@ -190,7 +190,9 @@ napi_value IntellVoiceManagerNapi::Export(napi_env env, napi_value exports)
napi_property_descriptor properties[] = {
DECLARE_NAPI_FUNCTION("getCapabilityInfo", GetCapabilityInfo),
DECLARE_NAPI_FUNCTION("on", On),
DECLARE_NAPI_FUNCTION("onServiceChange", OnServiceChange),
DECLARE_NAPI_FUNCTION("off", Off),
DECLARE_NAPI_FUNCTION("offServiceChange", OffServiceChange),
};
napi_property_descriptor staticProperties[] = {
@@ -287,6 +289,34 @@ napi_value IntellVoiceManagerNapi::On(napi_env env, napi_callback_info info)
return RegisterCallback(env, jsThis, args);
}
napi_value IntellVoiceManagerNapi::OnServiceChange(napi_env env, napi_callback_info info)
{
INTELL_VOICE_LOG_INFO("enter");
napi_value undefinedResult = nullptr;
napi_get_undefined(env, &undefinedResult);
const size_t expectArgCount = ARGC_ONE;
size_t argCount = ARGC_ONE;
napi_value args[expectArgCount] = { nullptr };
napi_value jsThis = nullptr;
napi_status status = napi_get_cb_info(env, info, &argCount, args, &jsThis, nullptr);
if (status != napi_ok || argCount != expectArgCount) {
INTELL_VOICE_LOG_ERROR("failed to get parameters");
return undefinedResult;
}
napi_valuetype handler = napi_undefined;
if (napi_typeof(env, args[ARG_INDEX_0], &handler) != napi_ok || handler != napi_function) {
INTELL_VOICE_LOG_ERROR("callback handler type mismatch");
return undefinedResult;
}
napi_value args1[ARGC_TWO] = { nullptr, args[ARG_INDEX_0] };
return RegisterCallback(env, jsThis, args1);
}
napi_value IntellVoiceManagerNapi::RegisterCallback(napi_env env, napi_value jsThis, napi_value *args)
{
INTELL_VOICE_LOG_INFO("enter");
@@ -353,6 +383,26 @@ napi_value IntellVoiceManagerNapi::Off(napi_env env, napi_callback_info info)
return DeregisterCallback(env, jsThis);
}
napi_value IntellVoiceManagerNapi::OffServiceChange(napi_env env, napi_callback_info info)
{
INTELL_VOICE_LOG_INFO("enter");
napi_value undefinedResult = nullptr;
napi_get_undefined(env, &undefinedResult);
const size_t expectArgCount = ARGC_ONE;
size_t argCount = ARGC_ONE;
napi_value args[expectArgCount] = {0};
napi_value jsThis = nullptr;
napi_status status = napi_get_cb_info(env, info, &argCount, args, &jsThis, nullptr);
if (status != napi_ok || argCount > ARGC_ONE) {
INTELL_VOICE_LOG_ERROR("failed to get parameters");
return undefinedResult;
}
return DeregisterCallback(env, jsThis);
}
napi_value IntellVoiceManagerNapi::DeregisterCallback(napi_env env, napi_value jsThis)
{
INTELL_VOICE_LOG_INFO("enter");
@@ -42,7 +42,9 @@ private:
static napi_value GetCapabilityInfo(napi_env env, napi_callback_info info);
static napi_value On(napi_env env, napi_callback_info info);
static napi_value OnServiceChange(napi_env env, napi_callback_info info);
static napi_value Off(napi_env env, napi_callback_info info);
static napi_value OffServiceChange(napi_env env, napi_callback_info info);
static napi_value GetIntelligentVoiceManager(napi_env env, napi_callback_info info);
static napi_value GetIntelligentVoiceManagerWrapper(napi_env env);
@@ -70,7 +70,9 @@ napi_value WakeupIntellVoiceEngineNapi::Export(napi_env env, napi_value exports)
DECLARE_NAPI_FUNCTION("getParameter", GetParameter),
DECLARE_NAPI_FUNCTION("release", Release),
DECLARE_NAPI_FUNCTION("on", On),
DECLARE_NAPI_FUNCTION("onWakeupIntelligentVoiceEvent", OnWakeupIntelligentVoiceEvent),
DECLARE_NAPI_FUNCTION("off", Off),
DECLARE_NAPI_FUNCTION("offWakeupIntelligentVoiceEvent", OffWakeupIntelligentVoiceEvent),
DECLARE_NAPI_FUNCTION("startCapturer", StartCapturer),
DECLARE_NAPI_FUNCTION("read", Read),
DECLARE_NAPI_FUNCTION("stopCapturer", StopCapturer),
@@ -486,6 +488,35 @@ napi_value WakeupIntellVoiceEngineNapi::On(napi_env env, napi_callback_info info
return RegisterCallback(env, jsThis, args);
}
napi_value WakeupIntellVoiceEngineNapi::OnWakeupIntelligentVoiceEvent(napi_env env, napi_callback_info info)
{
INTELL_VOICE_LOG_INFO("enter");
napi_value undefinedResult = nullptr;
napi_get_undefined(env, &undefinedResult);
size_t argCount = ARGC_ONE;
napi_value args[ARGC_ONE] = { nullptr };
napi_value jsThis = nullptr;
napi_status status = napi_get_cb_info(env, info, &argCount, args, &jsThis, nullptr);
if (status != napi_ok || argCount != ARGC_ONE) {
INTELL_VOICE_LOG_ERROR("failed to get parameters");
IntellVoiceCommonNapi::ThrowError(env, NAPI_INTELLIGENT_VOICE_INVALID_PARAM);
return undefinedResult;
}
napi_valuetype handler = napi_undefined;
if (napi_typeof(env, args[ARG_INDEX_0], &handler) != napi_ok || handler != napi_function) {
INTELL_VOICE_LOG_ERROR("callback handler type mismatch");
IntellVoiceCommonNapi::ThrowError(env, NAPI_INTELLIGENT_VOICE_INVALID_PARAM);
return undefinedResult;
}
napi_value args1[ARGC_TWO] = { nullptr, args[ARG_INDEX_0] };
return RegisterCallback(env, jsThis, args1);
}
napi_value WakeupIntellVoiceEngineNapi::RegisterCallback(napi_env env, napi_value jsThis, napi_value *args)
{
INTELL_VOICE_LOG_INFO("enter");
@@ -563,6 +594,35 @@ napi_value WakeupIntellVoiceEngineNapi::Off(napi_env env, napi_callback_info inf
return UnregisterCallback(env, jsThis, callbackName, args[ARG_INDEX_1]);
}
napi_value WakeupIntellVoiceEngineNapi::OffWakeupIntelligentVoiceEvent(napi_env env, napi_callback_info info)
{
INTELL_VOICE_LOG_INFO("enter");
napi_value undefinedResult = nullptr;
napi_get_undefined(env, &undefinedResult);
const size_t maxArgCount = ARGC_ONE;
size_t argCount = ARGC_ONE;
napi_value args[ARGC_ONE] = { nullptr };
napi_value jsThis = nullptr;
napi_status status = napi_get_cb_info(env, info, &argCount, args, &jsThis, nullptr);
if (status != napi_ok || argCount > maxArgCount) {
INTELL_VOICE_LOG_ERROR("failed to get parameters");
return undefinedResult;
}
if (argCount == ARGC_ONE) {
napi_valuetype secondArgType = napi_undefined;
if (napi_typeof(env, args[ARG_INDEX_0], &secondArgType) != napi_ok || secondArgType != napi_function) {
INTELL_VOICE_LOG_ERROR("failed to get callback function instance");
return undefinedResult;
}
}
return UnregisterCallback(env, jsThis, INTELL_VOICE_EVENT_CALLBACK_NAME, args[ARG_INDEX_0]);
}
napi_value WakeupIntellVoiceEngineNapi::UnregisterCallback(napi_env env, napi_value jsThis,
const std::string &callbackName, napi_value callback)
{
@@ -44,7 +44,9 @@ private:
static napi_value GetParameter(napi_env env, napi_callback_info info);
static napi_value Release(napi_env env, napi_callback_info info);
static napi_value On(napi_env env, napi_callback_info info);
static napi_value OnWakeupIntelligentVoiceEvent(napi_env env, napi_callback_info info);
static napi_value Off(napi_env env, napi_callback_info info);
static napi_value OffWakeupIntelligentVoiceEvent(napi_env env, napi_callback_info info);
static napi_value StartCapturer(napi_env env, napi_callback_info info);
static napi_value Read(napi_env env, napi_callback_info info);
static napi_value StopCapturer(napi_env env, napi_callback_info info);
+120
View File
@@ -0,0 +1,120 @@
# Copyright (C) 2025 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.
import("//build/config/components/ets_frontend/ets2abc_config.gni")
import("//build/ohos.gni")
import("//build/ohos/taihe_idl/taihe.gni")
subsystem_name = "ai"
part_name = "intelligent_voice_framework"
taihe_generated_file_path = "$taihe_file_path/out/$subsystem_name/$part_name"
copy_taihe_idl("copy_intellVoice_taihe") {
sources = [
"idl/ohos.ai.intelligentVoice.context.taihe",
"idl/ohos.ai.intelligentVoice.taihe",
]
}
ohos_taihe("run_taihe") {
taihe_generated_file_path = "$taihe_generated_file_path"
deps = [ ":copy_intellVoice_taihe" ]
outputs = [
"$taihe_generated_file_path/src/ohos.ai.intelligentVoice.ani.cpp",
"$taihe_generated_file_path/src/ohos.ai.intelligentVoice.abi.c",
]
}
taihe_shared_library("intellVoice_taihe") {
taihe_generated_file_path = "$taihe_generated_file_path"
subsystem_name = "$subsystem_name"
part_name = "$part_name"
include_dirs = [
"inc",
"../../interfaces/inner_api/native",
"../../services/intell_voice_service/inc",
"../../services/intell_voice_engine/proxy",
"../../utils",
]
sources = get_target_outputs(":run_taihe")
sources += [
"src/ani_constructor.cpp",
"src/intell_voice_manager_taihe.cpp",
"src/wakeup_manager_taihe.cpp",
"src/enroll_intell_voice_engine_taihe.cpp",
"src/wakeup_intell_voice_engine_taihe.cpp",
"src/intellvoice_taihe_utils.cpp",
"src/intell_voice_manager_callback_taihe.cpp",
"src/enroll_intell_voice_engine_callback_taihe.cpp",
"src/wakeup_intell_voice_engine_callback_taihe.cpp",
"src/intell_voice_update_callback_taihe.cpp",
]
cflags = [
"-Wno-error=unused-parameter",
"-DHILOG_ENABLE",
"-DENABLE_DEBUG",
]
deps = [
":run_taihe",
"../../frameworks/native:intellvoice_native",
"../../services:intell_voice_proxy",
]
external_deps = [
"ability_base:want",
"access_token:libaccesstoken_sdk",
"access_token:libtokenid_sdk",
"c_utils:utils",
"drivers_interface_intelligent_voice:intell_voice_engine_idl_headers_1.0",
"drivers_interface_intelligent_voice:intell_voice_engine_idl_headers_1.1",
"drivers_interface_intelligent_voice:intell_voice_engine_idl_headers_1.2",
"hilog:libhilog",
"ipc:ipc_core",
"napi:ace_napi",
"safwk:system_ability_fwk",
"samgr:samgr_proxy",
]
}
generate_static_abc("intelligent_voice_framework_taihe_abc") {
base_url = "$taihe_generated_file_path"
files = [ "$taihe_generated_file_path/@ohos.ai.intelligentVoice.ets" ]
is_boot_abc = "True"
device_dst_file = "/system/framework/intelligent_voice_framework_taihe_abc.abc"
dependencies = [ ":run_taihe" ]
}
ohos_prebuilt_etc("intelligent_voice_framework_etc") {
source = "$target_out_dir/intelligent_voice_framework_taihe_abc.abc"
module_install_dir = "framework"
part_name = "$part_name"
subsystem_name = "$subsystem_name"
deps = [
":intelligent_voice_framework_taihe_abc"
]
}
group("intelligent_voice_framework_taihe") {
deps = [
":intellVoice_taihe",
":intelligent_voice_framework_etc",
]
}
group("intelligent_voice_framework_taihe_gen_only") {
deps = [ ":run_taihe" ]
}
@@ -0,0 +1,20 @@
/*
* Copyright (C) 2025 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.
*/
@!namespace("@ohos.ai.intelligentVoice")
@!sts_inject("""
import { AsyncCallback, Callback } from '@ohos.base';
""")
@@ -0,0 +1,286 @@
/*
* Copyright (C) 2025 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.
*/
@!namespace("@ohos.ai.intelligentVoice", "intelligentVoice")
@!sts_inject("""
static { loadLibrary("intellVoice_taihe.z"); }
""")
@overload("getIntelligentVoiceManager")
function GetIntelligentVoiceManager(): IntelligentVoiceManager;
interface IntelligentVoiceManager {
getCapabilityInfo(): Array<IntelligentVoiceEngineType>;
@on_off("serviceChange")
onServiceChange(callback: (data: ServiceChangeType) => void): void;
@on_off("serviceChange")
offServiceChange(callback: Optional<(data: ServiceChangeType) => void>): void;
}
interface WakeupManager {
@gen_promise("setParameter")
SetParameterSync(key: String, value: String): void;
@gen_promise("getParameter")
GetParameterSync(key: String): String;
@gen_promise("getUploadFiles")
GetUploadFilesSync(maxCount: i32): Array<UploadFile>;
@gen_promise("getWakeupSourceFiles")
GetWakeupSourceFilesSync(): Array<WakeupSourceFile>;
@gen_promise("enrollWithWakeupFilesForResult")
EnrollWithWakeupFilesForResultSync(wakeupFiles: Array<WakeupSourceFile>, wakeupInfo: String): EnrollResult;
@gen_promise("clearUserData")
ClearUserDataSync(): void;
}
enum UploadFileType: i32 {
ENROLL_FILE = 0,
WAKEUP_FILE = 1,
}
struct UploadFile {
type: UploadFileType;
filesDescription: String;
filesContent: Array<@arraybuffer Array<u8>>;
}
struct WakeupSourceFile {
filePath: String;
fileContent: @arraybuffer Array<u8>;
}
enum ServiceChangeType: i32 {
SERVICE_UNAVAILABLE = 0,
}
enum IntelligentVoiceEngineType: i32 {
ENROLL_ENGINE_TYPE = 0,
WAKEUP_ENGINE_TYPE = 1,
UPDATE_ENGINE_TYPE = 2,
}
struct EnrollIntelligentVoiceEngineDescriptor {
wakeupPhrase: String;
}
struct WakeupIntelligentVoiceEngineDescriptor {
needReconfirm: bool;
wakeupPhrase: String;
}
enum EvaluationResultCode: i32 {
UNKNOWN = 0,
PASS = 1,
WORD_EMPTY = 2,
CHINESE_ONLY = 3,
INVALID_LENGTH = 4,
UNUSUAL_WORD = 5,
CONSECUTIVE_SAME_WORD = 6,
TOO_FEW_PHONEMES = 7,
TOO_MANY_PHONEMES = 8,
COMMON_INSTRUCTION = 9,
COMMON_SPOKEN_LANGUAGE = 10,
SENSITIVE_WORD = 11,
NO_INITIAL_CONSONANT = 12,
REPEATED_PHONEME = 13,
}
struct EvaluationResult {
score: i32;
resultCode: EvaluationResultCode;
}
@overload("getWakeupManager")
function GetWakeupManager(): WakeupManager;
@gen_async("createEnrollIntelligentVoiceEngine")
@gen_promise("createEnrollIntelligentVoiceEngine")
function CreateEnrollIntelligentVoiceEngineSync(descriptor: EnrollIntelligentVoiceEngineDescriptor): EnrollIntelligentVoiceEngine;
@gen_async("createWakeupIntelligentVoiceEngine")
@gen_promise("createWakeupIntelligentVoiceEngine")
function CreateWakeupIntelligentVoiceEngineSync(descriptor: WakeupIntelligentVoiceEngineDescriptor): WakeupIntelligentVoiceEngine;
struct EnrollEngineConfig {
language: String;
region: String;
}
enum SensibilityType: i32 {
LOW_SENSIBILITY = 0,
MIDDLE_SENSIBILITY = 1,
HIGH_SENSIBILITY = 2,
}
struct WakeupHapInfo {
bundleName: String;
abilityName: String;
}
enum WakeupIntelligentVoiceEventType: i32 {
INTELLIGENT_VOICE_EVENT_WAKEUP_NONE = 0,
INTELLIGENT_VOICE_EVENT_RECOGNIZE_COMPLETE = 1,
INTELLIGENT_VOICE_EVENT_HEADSET_RECOGNIZE_COMPLETE = 2,
}
enum IntelligentVoiceErrorCode: i32 {
INTELLIGENT_VOICE_NO_MEMORY = 22700101,
INTELLIGENT_VOICE_INVALID_PARAM = 22700102,
INTELLIGENT_VOICE_INIT_FAILED = 22700103,
INTELLIGENT_VOICE_COMMIT_ENROLL_FAILED = 22700104,
INTELLIGENT_VOICE_START_CAPTURER_FAILED = 22700105,
INTELLIGENT_VOICE_READ_FAILED = 22700106,
INTELLIGENT_VOICE_SYSTEM_ERROR = 22700107,
}
enum EnrollResult: i32 {
SUCCESS = 0,
VPR_TRAIN_FAILED = -1,
WAKEUP_PHRASE_NOT_MATCH = -2,
TOO_NOISY = -3,
TOO_LOUD = -4,
INTERVAL_LARGE = -5,
DIFFERENT_PERSON = -6,
UNKNOWN_ERROR = -100,
}
enum CapturerChannel: i32 {
CAPTURER_CHANNEL_1 = 0x1 << 0,
CAPTURER_CHANNEL_2 = 0x1 << 1,
CAPTURER_CHANNEL_3 = 0x1 << 2,
CAPTURER_CHANNEL_4 = 0x1 << 3,
}
struct EnrollCallbackInfo {
result: EnrollResult;
context: String;
}
struct WakeupIntelligentVoiceEngineCallbackInfo {
eventId: WakeupIntelligentVoiceEventType;
isSuccess: bool;
context: String;
}
interface EnrollIntelligentVoiceEngine {
@gen_async("getSupportedRegions")
@gen_promise("getSupportedRegions")
GetSupportedRegionsSync(): Array<String>;
@gen_async("init")
@gen_promise("init")
InitSync(config: EnrollEngineConfig): void;
@gen_async("enrollForResult")
@gen_promise("enrollForResult")
EnrollForResultSync(isLast: bool): EnrollCallbackInfo;
@gen_async("stop")
@gen_promise("stop")
StopSync(): void;
@gen_async("commit")
@gen_promise("commit")
CommitSync(): void;
@gen_async("setWakeupHapInfo")
@gen_promise("setWakeupHapInfo")
SetWakeupHapInfoSync(info: WakeupHapInfo): void;
@gen_async("setSensibility")
@gen_promise("setSensibility")
SetSensibilitySync(sensibility: SensibilityType): void;
@gen_async("setParameter")
@gen_promise("setParameter")
SetParameterSync(key: String, value: String): void;
@gen_async("getParameter")
@gen_promise("getParameter")
GetParameterSync(key: String): void;
@gen_promise("evaluateForResult")
EvaluateForResultSync(word: String): EvaluationResult;
@gen_async("release")
@gen_promise("release")
ReleaseSync(): void;
}
interface WakeupIntelligentVoiceEngine {
@gen_async("getSupportedRegions")
@gen_promise("getSupportedRegions")
GetSupportedRegionsSync(): Array<String>;
@gen_async("setWakeupHapInfo")
@gen_promise("setWakeupHapInfo")
SetWakeupHapInfoSync(info: WakeupHapInfo): void;
@gen_async("setSensibility")
@gen_promise("setSensibility")
SetSensibilitySync(sensibility: SensibilityType): void;
@gen_async("setParameter")
@gen_promise("setParameter")
SetParameterSync(key: String, value: String): void;
@gen_async("getParameter")
@gen_promise("getParameter")
GetParameterSync(key: String): void;
@gen_promise("getPcm")
GetPcmSync(): @arraybuffer Array<u8>;
@gen_promise("startCapturer")
StartCapturerSync(channels: i32): void;
@gen_promise("read")
ReadSync(): @arraybuffer Array<u8>;
@gen_promise("stopCapturer")
StopCapturerSync(): void;
@gen_async("release")
@gen_promise("release")
ReleaseSync(): void;
@on_off("wakeupIntelligentVoiceEvent")
onWakeupIntelligentVoiceEvent(callback: (data: WakeupIntelligentVoiceEngineCallbackInfo) => void): void;
@on_off("wakeupIntelligentVoiceEvent")
offWakeupIntelligentVoiceEvent(callback: Optional<(data: WakeupIntelligentVoiceEngineCallbackInfo) => void>): void;
}
@@ -0,0 +1,45 @@
/*
* Copyright (c) 2025 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 ENROLL_INTELL_VOICE_ENGINE_CALLBACK_TAIHE_H
#define ENROLL_INTELL_VOICE_ENGINE_CALLBACK_TAIHE_H
#include <queue>
#include <map>
#include <uv.h>
#include "i_intell_voice_engine_callback.h"
namespace OHOS {
namespace IntellVoiceTaihe {
using OHOS::IntellVoiceEngine::IIntellVoiceEngineEventCallback;
using OHOS::IntellVoiceEngine::IntellVoiceEngineCallBackEvent;
struct EnrollCallbackInfo {
int32_t eventId;
int32_t result;
std::string context;
};
class EnrollIntellVoiceEngineCallbackTaihe : public IIntellVoiceEngineEventCallback {
public:
explicit EnrollIntellVoiceEngineCallbackTaihe();
virtual ~EnrollIntellVoiceEngineCallbackTaihe();
void OnEvent(const IntellVoiceEngineCallBackEvent &event) override;
};
} // namespace IntellVoiceTaihe
} // namespace OHOS
#endif
@@ -0,0 +1,69 @@
/*
* Copyright (c) 2025 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 ENROLL_INTELL_VOICE_ENGINE_TAIHE_H
#define ENROLL_INTELL_VOICE_ENGINE_TAIHE_H
#include "intell_voice_manager.h"
#include "enroll_intell_voice_engine.h"
#include "enroll_intell_voice_engine_callback_taihe.h"
#include "ohos.ai.intelligentVoice.proj.hpp"
#include "ohos.ai.intelligentVoice.impl.hpp"
#include "taihe/runtime.hpp"
#include "stdexcept"
namespace OHOS {
namespace IntellVoiceTaihe {
using ohos::ai::intelligentVoice::EnrollIntelligentVoiceEngine;
using ohos::ai::intelligentVoice::EnrollIntelligentVoiceEngineDescriptor;
class EnrollIntelligentVoiceEngineImpl {
public:
explicit EnrollIntelligentVoiceEngineImpl(EnrollIntelligentVoiceEngineDescriptor const &descriptor);
~EnrollIntelligentVoiceEngineImpl();
::taihe::array<::taihe::string> GetSupportedRegionsSync();
void InitSync(::ohos::ai::intelligentVoice::EnrollEngineConfig const &config);
::ohos::ai::intelligentVoice::EnrollCallbackInfo EnrollForResultSync(bool isLast);
void StopSync();
void CommitSync();
void SetWakeupHapInfoSync(::ohos::ai::intelligentVoice::WakeupHapInfo const &info);
void SetSensibilitySync(::ohos::ai::intelligentVoice::SensibilityType sensibility);
void SetParameterSync(::taihe::string_view key, ::taihe::string_view value);
void GetParameterSync(::taihe::string_view key);
::ohos::ai::intelligentVoice::EvaluationResult EvaluateForResultSync(::taihe::string_view word);
void ReleaseSync();
private:
std::shared_ptr<IntellVoice::EnrollIntellVoiceEngine> engine_ = nullptr;
IntellVoice::EnrollIntelligentVoiceEngineDescriptor descriptor_;
std::shared_ptr<EnrollIntellVoiceEngineCallbackTaihe> callback_ = nullptr;
};
} // namespace IntellVoiceTaihe
} // namespace OHOS
#endif
@@ -0,0 +1,43 @@
/*
* Copyright (c) 2025 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 INTELL_VOICE_MANAGER_CALLBACK_TAIHE_H
#define INTELL_VOICE_MANAGER_CALLBACK_TAIHE_H
#include "iremote_object.h"
#include "ohos.ai.intelligentVoice.proj.hpp"
#include "ohos.ai.intelligentVoice.impl.hpp"
#include "taihe/runtime.hpp"
#include "stdexcept"
namespace OHOS {
namespace IntellVoiceTaihe {
using namespace taihe;
using ohos::ai::intelligentVoice::ServiceChangeType;
class IntellVoiceManagerCallbackTaihe : public IRemoteObject::DeathRecipient {
public:
explicit IntellVoiceManagerCallbackTaihe(std::shared_ptr<callback_view<void(ServiceChangeType)>> callback);
~IntellVoiceManagerCallbackTaihe() override {};
void OnRemoteDied(const wptr<IRemoteObject> &remote) override;
private:
std::mutex mutex_;
std::shared_ptr<callback_view<void(ServiceChangeType)>> callback_ = nullptr;
};
} // namespace IntellVoiceTaihe
} // namespace OHOS
#endif
@@ -0,0 +1,54 @@
/*
* Copyright (c) 2025 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 INTELL_VOICE_MANAGER_TAIHE_H
#define INTELL_VOICE_MANAGER_TAIHE_H
#include "intell_voice_info.h"
#include "intell_voice_manager.h"
#include "intell_voice_manager_callback_taihe.h"
#include "ohos.ai.intelligentVoice.proj.hpp"
#include "ohos.ai.intelligentVoice.impl.hpp"
#include "taihe/runtime.hpp"
#include "stdexcept"
namespace OHOS {
namespace IntellVoiceTaihe {
using namespace taihe;
using OHOS::IntellVoice::IntellVoiceManager;
using ohos::ai::intelligentVoice::IntelligentVoiceManager;
using ohos::ai::intelligentVoice::ServiceChangeType;
using ohos::ai::intelligentVoice::IntelligentVoiceEngineType;
class IntelligentVoiceManagerImpl {
public:
explicit IntelligentVoiceManagerImpl();
~IntelligentVoiceManagerImpl();
taihe::array<IntelligentVoiceEngineType> getCapabilityInfo();
void onServiceChange(callback_view<void(ServiceChangeType)> callback);
void offServiceChange(optional_view<callback<void(ServiceChangeType)>> callback);
private:
std::mutex mutex_;
IntellVoiceManager *manager_ = nullptr;
sptr<IntellVoiceManagerCallbackTaihe> serviceChangeCb_ = nullptr;
};
} // namespace IntellVoiceTaihe
} // namespace OHOS
#endif
@@ -0,0 +1,38 @@
/*
* Copyright (c) 2025 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 INTELL_VOICEUPDATE_CALLBACK_TAIHE_H
#define INTELL_VOICEUPDATE_CALLBACK_TAIHE_H
#include <queue>
#include <map>
#include <uv.h>
#include "i_intell_voice_update_callback.h"
#include "intell_voice_info.h"
namespace OHOS {
namespace IntellVoiceTaihe {
using namespace OHOS::IntellVoice;
class IntellVoiceUpdateCallbackTaihe : public IIntellVoiceUpdateCallback {
public:
explicit IntellVoiceUpdateCallbackTaihe();
virtual ~IntellVoiceUpdateCallbackTaihe();
void OnUpdateComplete(const int result) override;
};
} // namespace IntellVoiceTaihe
} // namespace OHOS
#endif
@@ -0,0 +1,47 @@
/*
* Copyright (C) 2025 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 INTELLVOICE_TAIHE_UTILS_H
#define INTELLVOICE_TAIHE_UTILS_H
#include "intell_voice_manager.h"
#include "ohos.ai.intelligentVoice.proj.hpp"
#include "ohos.ai.intelligentVoice.impl.hpp"
#include "taihe/runtime.hpp"
#include "stdexcept"
namespace OHOS {
namespace IntellVoiceTaihe {
using namespace taihe;
using ohos::ai::intelligentVoice::EnrollResult;
using ohos::ai::intelligentVoice::EvaluationResultCode;
using ohos::ai::intelligentVoice::UploadFileType;
using ohos::ai::intelligentVoice::WakeupSourceFile;
class IntellVoiceTaiheUtils {
public:
static taihe::array<::ohos::ai::intelligentVoice::UploadFile> ToTaiheArrayUploadFile(
std::vector<IntellVoice::UploadFilesInfo> &uploadFiles);
static taihe::array<::ohos::ai::intelligentVoice::WakeupSourceFile> ToTaiheArrayWakeupSourceFile(
std::vector<IntellVoice::WakeupSourceFile> &cloneFile);
template <typename EnumType, typename ValueType>
static bool GetEnumKeyByValue(ValueType value, typename EnumType::key_t &key);
};
} // namespace IntellVoiceTaihe
} // namespace OHOS
#endif
@@ -0,0 +1,59 @@
/*
* Copyright (c) 2025 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 WAKEUP_INTELL_VOICE_ENGINE_CALLBACK_TAIHE_H
#define WAKEUP_INTELL_VOICE_ENGINE_CALLBACK_TAIHE_H
#include <queue>
#include <map>
#include <uv.h>
#include "i_intell_voice_engine_callback.h"
#include "ohos.ai.intelligentVoice.proj.hpp"
#include "ohos.ai.intelligentVoice.impl.hpp"
#include "taihe/runtime.hpp"
#include "stdexcept"
namespace OHOS {
namespace IntellVoiceTaihe {
using OHOS::IntellVoiceEngine::IIntellVoiceEngineEventCallback;
using OHOS::IntellVoiceEngine::IntellVoiceEngineCallBackEvent;
struct EnrollCallbackInfo {
int32_t eventId;
int32_t result;
std::string context;
};
class WakeupIntellVoiceEngineCallbackTaihe : public IIntellVoiceEngineEventCallback {
public:
explicit WakeupIntellVoiceEngineCallbackTaihe(std::shared_ptr<
::taihe::callback_view<void(::ohos::ai::intelligentVoice::WakeupIntelligentVoiceEngineCallbackInfo const &)>
> callback);
virtual ~WakeupIntellVoiceEngineCallbackTaihe();
void ClearCallbackRef();
void OnEvent(const IntellVoiceEngineCallBackEvent &event) override;
private:
std::mutex mutex_;
std::shared_ptr<::taihe::callback_view<
void(::ohos::ai::intelligentVoice::WakeupIntelligentVoiceEngineCallbackInfo const &)>> callback_;
};
} // namespace IntellVoiceTaihe
} // namespace OHOS
#endif
@@ -0,0 +1,73 @@
/*
* Copyright (c) 2025 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 WAKEUP_INTELL_VOICE_ENGINE_TAIHE_H
#define WAKEUP_INTELL_VOICE_ENGINE_TAIHE_H
#include "intell_voice_manager.h"
#include "wakeup_intell_voice_engine.h"
#include "wakeup_intell_voice_engine_callback_taihe.h"
#include "ohos.ai.intelligentVoice.proj.hpp"
#include "ohos.ai.intelligentVoice.impl.hpp"
#include "taihe/runtime.hpp"
#include "stdexcept"
namespace OHOS {
namespace IntellVoiceTaihe {
using ohos::ai::intelligentVoice::WakeupIntelligentVoiceEngine;
using ohos::ai::intelligentVoice::WakeupIntelligentVoiceEngineDescriptor;
class WakeupIntelligentVoiceEngineImpl {
public:
explicit WakeupIntelligentVoiceEngineImpl(WakeupIntelligentVoiceEngineDescriptor const &descriptor);
~WakeupIntelligentVoiceEngineImpl();
::taihe::array<::taihe::string> GetSupportedRegionsSync();
void SetWakeupHapInfoSync(::ohos::ai::intelligentVoice::WakeupHapInfo const &info);
void SetSensibilitySync(::ohos::ai::intelligentVoice::SensibilityType sensibility);
void SetParameterSync(::taihe::string_view key, ::taihe::string_view value);
void GetParameterSync(::taihe::string_view key);
::taihe::array<uint8_t> GetPcmSync();
void StartCapturerSync(int32_t channels);
::taihe::array<uint8_t> ReadSync();
void StopCapturerSync();
void ReleaseSync();
void onWakeupIntelligentVoiceEvent(
::taihe::callback_view<void(::ohos::ai::intelligentVoice::WakeupIntelligentVoiceEngineCallbackInfo const &)>
callback);
void offWakeupIntelligentVoiceEvent(::taihe::optional_view<
::taihe::callback<void(::ohos::ai::intelligentVoice::WakeupIntelligentVoiceEngineCallbackInfo const &)>>
callback);
private:
std::shared_ptr<IntellVoice::WakeupIntellVoiceEngine> engine_ = nullptr;
std::shared_ptr<WakeupIntellVoiceEngineCallbackTaihe> callback_ = nullptr;
IntellVoice::WakeupIntelligentVoiceEngineDescriptor descriptor_;
};
} // namespace IntellVoiceTaihe
} // namespace OHOS
#endif
@@ -0,0 +1,55 @@
/*
* Copyright (c) 2025 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 WAKEUP_MANAGER_TAIHE_H
#define WAKEUP_MANAGER_TAIHE_H
#include "intell_voice_manager.h"
#include "intell_voice_update_callback_taihe.h"
#include "ohos.ai.intelligentVoice.proj.hpp"
#include "ohos.ai.intelligentVoice.impl.hpp"
#include "taihe/runtime.hpp"
#include "stdexcept"
namespace OHOS {
namespace IntellVoiceTaihe {
using ohos::ai::intelligentVoice::WakeupManager;
class WakeupManagerImpl {
public:
WakeupManagerImpl();
void SetParameterSync(::taihe::string_view key, ::taihe::string_view value);
::taihe::string GetParameterSync(::taihe::string_view key);
::taihe::array<::ohos::ai::intelligentVoice::UploadFile> GetUploadFilesSync(int32_t maxCount);
::taihe::array<::ohos::ai::intelligentVoice::WakeupSourceFile> GetWakeupSourceFilesSync();
::ohos::ai::intelligentVoice::EnrollResult EnrollWithWakeupFilesForResultSync(
::taihe::array_view<::ohos::ai::intelligentVoice::WakeupSourceFile> wakeupFiles,
::taihe::string_view wakeupInfo);
void ClearUserDataSync();
private:
std::shared_ptr<IntellVoiceUpdateCallbackTaihe> callback_ = nullptr;
};
} // namespace IntellVoiceTaihe
} // namespace OHOS
#endif
+31
View File
@@ -0,0 +1,31 @@
/*
* Copyright (c) 2025 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 "taihe/runtime.hpp"
#include "ohos.ai.intelligentVoice.context.ani.hpp"
#include "ohos.ai.intelligentVoice.ani.hpp"
ANI_EXPORT ani_status ANI_Constructor(ani_vm *vm, uint32_t *result)
{
ani_env *env;
if (ANI_OK != vm->GetEnv(ANI_VERSION_1, &env)) {
return ANI_ERROR;
}
if (ANI_OK != ohos::ai::intelligentVoice::ANIRegister(env)) {
std::cerr << "Error from ohos::ai::intelligentVoice::ANIRegister" << std::endl;
return ANI_ERROR;
}
*result = ANI_VERSION_1;
return ANI_OK;
}
@@ -0,0 +1,41 @@
/*
* Copyright (c) 2025 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 "enroll_intell_voice_engine_callback_taihe.h"
#include "intell_voice_log.h"
#define LOG_TAG "EnrollEngineCallbackTaihe"
using namespace std;
using namespace OHOS::IntellVoiceEngine;
using namespace OHOS::HDI::IntelligentVoice::Engine::V1_0;
namespace OHOS {
namespace IntellVoiceTaihe {
EnrollIntellVoiceEngineCallbackTaihe::EnrollIntellVoiceEngineCallbackTaihe()
{
}
EnrollIntellVoiceEngineCallbackTaihe::~EnrollIntellVoiceEngineCallbackTaihe()
{
}
void EnrollIntellVoiceEngineCallbackTaihe::OnEvent(const IntellVoiceEngineCallBackEvent &event)
{
INTELL_VOICE_LOG_INFO("OnEvent: msgId: %{public}d, errCode: %{public}d", event.msgId, event.result);
}
} // namespace IntellVoiceNapi
} // namespace OHOS
@@ -0,0 +1,196 @@
/*
* Copyright (c) 2025 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 "enroll_intell_voice_engine_taihe.h"
#include "intellvoice_taihe_utils.h"
#include "iservice_registry.h"
#include "system_ability_definition.h"
#include "intell_voice_log.h"
#include "i_intell_voice_engine_callback.h"
#define LOG_TAG "EnrollEngineTaihe"
using namespace std;
using namespace taihe;
using namespace OHOS::IntellVoice;
using namespace OHOS::IntellVoiceTaihe;
namespace OHOS {
namespace IntellVoiceTaihe {
EnrollIntelligentVoiceEngineImpl::EnrollIntelligentVoiceEngineImpl(
EnrollIntelligentVoiceEngineDescriptor const &descriptor)
{
descriptor_.wakeupPhrase = descriptor.wakeupPhrase;
engine_ = std::make_shared<EnrollIntellVoiceEngine>(descriptor_);
if (engine_ == nullptr) {
INTELL_VOICE_LOG_ERROR("create enroll engine failed");
return;
}
callback_ = std::make_shared<EnrollIntellVoiceEngineCallbackTaihe>();
if (callback_ == nullptr) {
INTELL_VOICE_LOG_ERROR("create intell voice engine callback taihe failed");
return;
}
if (engine_->SetCallback(callback_) != 0) {
INTELL_VOICE_LOG_ERROR("set callback failed");
return;
}
}
EnrollIntelligentVoiceEngineImpl::~EnrollIntelligentVoiceEngineImpl()
{
engine_ = nullptr;
}
::taihe::array<::taihe::string> EnrollIntelligentVoiceEngineImpl::GetSupportedRegionsSync()
{
return {"CN"};
}
void EnrollIntelligentVoiceEngineImpl::InitSync(::ohos::ai::intelligentVoice::EnrollEngineConfig const &config)
{
if (engine_ == nullptr) {
INTELL_VOICE_LOG_ERROR("engine is nullptr");
return;
}
EngineConfig engineConfig{
.language = std::string(config.language),
.region = std::string(config.region),
};
engine_->Init(engineConfig);
}
::ohos::ai::intelligentVoice::EnrollCallbackInfo EnrollIntelligentVoiceEngineImpl::EnrollForResultSync(bool isLast)
{
::ohos::ai::intelligentVoice::EnrollResult::key_t resultCodeKey;
int retCode = UNKNOWN;
IntellVoiceTaiheUtils::GetEnumKeyByValue<::ohos::ai::intelligentVoice::EnrollResult>(retCode, resultCodeKey);
if (engine_ == nullptr) {
INTELL_VOICE_LOG_ERROR("engine is nullptr");
return {ohos::ai::intelligentVoice::EnrollResult(resultCodeKey), ""};
}
engine_->Start(isLast);
return {ohos::ai::intelligentVoice::EnrollResult(resultCodeKey), ""};
}
void EnrollIntelligentVoiceEngineImpl::StopSync()
{
if (engine_ == nullptr) {
INTELL_VOICE_LOG_ERROR("engine is nullptr");
return;
}
engine_->Stop();
}
void EnrollIntelligentVoiceEngineImpl::CommitSync()
{
if (engine_ == nullptr) {
INTELL_VOICE_LOG_ERROR("engine is nullptr");
return;
}
engine_->Commit();
}
void EnrollIntelligentVoiceEngineImpl::SetWakeupHapInfoSync(::ohos::ai::intelligentVoice::WakeupHapInfo const &info)
{
if (engine_ == nullptr) {
INTELL_VOICE_LOG_ERROR("engine is nullptr");
return;
}
WakeupHapInfo hapInfo{
.bundleName = std::string(info.bundleName),
.abilityName = std::string(info.abilityName),
};
engine_->SetWakeupHapInfo(hapInfo);
}
void EnrollIntelligentVoiceEngineImpl::SetSensibilitySync(::ohos::ai::intelligentVoice::SensibilityType sensibility)
{
if (engine_ == nullptr) {
INTELL_VOICE_LOG_ERROR("engine is nullptr");
return;
}
engine_->SetSensibility(sensibility);
}
void EnrollIntelligentVoiceEngineImpl::SetParameterSync(::taihe::string_view key, ::taihe::string_view value)
{
if (engine_ == nullptr) {
INTELL_VOICE_LOG_ERROR("engine is nullptr");
return;
}
engine_->SetParameter(std::string(key), std::string(value));
}
void EnrollIntelligentVoiceEngineImpl::GetParameterSync(::taihe::string_view key)
{
if (engine_ == nullptr) {
INTELL_VOICE_LOG_ERROR("engine is nullptr");
return;
}
engine_->GetParameter(std::string(key));
}
::ohos::ai::intelligentVoice::EvaluationResult EnrollIntelligentVoiceEngineImpl::EvaluateForResultSync(
::taihe::string_view word)
{
::ohos::ai::intelligentVoice::EvaluationResultCode::key_t resultCodeKey;
int retCode = UNKNOWN;
IntellVoiceTaiheUtils::GetEnumKeyByValue<::ohos::ai::intelligentVoice::EvaluationResultCode>(
retCode, resultCodeKey);
if (engine_ == nullptr) {
INTELL_VOICE_LOG_ERROR("engine is nullptr");
return {0, ohos::ai::intelligentVoice::EvaluationResultCode(resultCodeKey)};
}
EvaluationResult result;
engine_->Evaluate(std::string(word), result);
IntellVoiceTaiheUtils::GetEnumKeyByValue<::ohos::ai::intelligentVoice::EvaluationResultCode>(
result.resultCode, resultCodeKey);
::ohos::ai::intelligentVoice::EvaluationResult ret{
.score = result.score,
.resultCode = ohos::ai::intelligentVoice::EvaluationResultCode(resultCodeKey),
};
return ret;
}
void EnrollIntelligentVoiceEngineImpl::ReleaseSync()
{
if (engine_ == nullptr) {
INTELL_VOICE_LOG_ERROR("engine is nullptr");
return;
}
engine_->Release();
}
EnrollIntelligentVoiceEngine CreateEnrollIntelligentVoiceEngineSync(
EnrollIntelligentVoiceEngineDescriptor const &descriptor)
{
// The parameters in the make_holder function should be of the same type
// as the parameters in the constructor of the actual implementation class.
return taihe::make_holder<EnrollIntelligentVoiceEngineImpl, EnrollIntelligentVoiceEngine>(descriptor);
}
} // namespace IntellVoiceTaihe
} // namespace OHOS
TH_EXPORT_CPP_API_CreateEnrollIntelligentVoiceEngineSync(
OHOS::IntellVoiceTaihe::CreateEnrollIntelligentVoiceEngineSync);
@@ -0,0 +1,46 @@
/*
* Copyright (C) 2025 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 "intell_voice_manager_callback_taihe.h"
#include "intell_voice_log.h"
#define LOG_TAG "IntellVoiceManagerCallbackTaihe"
using namespace std;
using namespace taihe;
using namespace OHOS::IntellVoiceTaihe;
namespace OHOS {
namespace IntellVoiceTaihe {
IntellVoiceManagerCallbackTaihe::IntellVoiceManagerCallbackTaihe(
std::shared_ptr<callback_view<void(ServiceChangeType)>> callback): callback_(callback)
{
INTELL_VOICE_LOG_INFO("enter");
}
void IntellVoiceManagerCallbackTaihe::OnRemoteDied(const wptr<IRemoteObject> &remote)
{
std::unique_lock<std::mutex> lock(mutex_);
INTELL_VOICE_LOG_INFO("receive sa death callback");
(void)remote;
if (callback_ != nullptr) {
(*callback_)(ServiceChangeType(ServiceChangeType::key_t::SERVICE_UNAVAILABLE));
}
}
} // namespace IntellVoiceTaihe
} // namespace OHOS
@@ -0,0 +1,83 @@
/*
* Copyright (c) 2025 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 "intell_voice_manager_taihe.h"
#include "intell_voice_log.h"
#include "intell_voice_info.h"
#include "accesstoken_kit.h"
#include "tokenid_kit.h"
#include "ipc_skeleton.h"
#define LOG_TAG "IntellVoiceManagerTaihe"
using namespace std;
using namespace taihe;
using namespace OHOS::IntellVoice;
using namespace OHOS::IntellVoiceTaihe;
namespace OHOS {
namespace IntellVoiceTaihe {
IntelligentVoiceManagerImpl::IntelligentVoiceManagerImpl()
{
manager_ = IntellVoiceManager::GetInstance();
if (manager_ == nullptr) {
INTELL_VOICE_LOG_ERROR("create native manager failed");
}
}
IntelligentVoiceManagerImpl::~IntelligentVoiceManagerImpl()
{
manager_ = nullptr;
}
::taihe::array<IntelligentVoiceEngineType> IntelligentVoiceManagerImpl::getCapabilityInfo()
{
INTELL_VOICE_LOG_INFO("enter");
ohos::ai::intelligentVoice::IntelligentVoiceEngineType enroll(
ohos::ai::intelligentVoice::IntelligentVoiceEngineType::key_t::ENROLL_ENGINE_TYPE);
ohos::ai::intelligentVoice::IntelligentVoiceEngineType wakeup(
ohos::ai::intelligentVoice::IntelligentVoiceEngineType::key_t::WAKEUP_ENGINE_TYPE);
return {enroll, wakeup};
}
void IntelligentVoiceManagerImpl::onServiceChange(callback_view<void(ServiceChangeType)> callback)
{
if (manager_ != nullptr) {
if (serviceChangeCb_ != nullptr) {
manager_->DeregisterServiceDeathRecipient(serviceChangeCb_);
}
serviceChangeCb_ = new (std::nothrow) IntellVoiceManagerCallbackTaihe(
std::make_shared<callback_view<void(ServiceChangeType)>>(callback));
manager_->RegisterServiceDeathRecipient(serviceChangeCb_);
}
}
void IntelligentVoiceManagerImpl::offServiceChange(optional_view<callback<void(ServiceChangeType)>> callback)
{
(void)callback;
if (manager_ != nullptr && serviceChangeCb_ != nullptr) {
manager_->DeregisterServiceDeathRecipient(serviceChangeCb_);
}
}
IntelligentVoiceManager GetIntelligentVoiceManager()
{
INTELL_VOICE_LOG_INFO("enter");
return make_holder<IntelligentVoiceManagerImpl, IntelligentVoiceManager>();
}
} // namespace IntellVoiceTaihe
} // namespace OHOS
TH_EXPORT_CPP_API_GetIntelligentVoiceManager(GetIntelligentVoiceManager);
@@ -0,0 +1,39 @@
/*
* Copyright (c) 2025 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 "intell_voice_update_callback_taihe.h"
#include "intell_voice_log.h"
#define LOG_TAG "UpdateCallbackTaihe"
using namespace std;
using namespace OHOS::HDI::IntelligentVoice::Engine::V1_0;
namespace OHOS {
namespace IntellVoiceTaihe {
IntellVoiceUpdateCallbackTaihe::IntellVoiceUpdateCallbackTaihe()
{
}
IntellVoiceUpdateCallbackTaihe::~IntellVoiceUpdateCallbackTaihe()
{
}
void IntellVoiceUpdateCallbackTaihe::OnUpdateComplete(const int result)
{
INTELL_VOICE_LOG_INFO("OnUpdateComplete: result: %{public}d", result);
}
} // namespace IntellVoiceNapi
} // namespace OHOS
@@ -0,0 +1,101 @@
/*
* Copyright (C) 2025 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 "intellvoice_taihe_utils.h"
#include "intell_voice_log.h"
#define LOG_TAG "WakeupManagerTaihe"
using namespace std;
using namespace taihe;
using namespace OHOS::IntellVoice;
using namespace OHOS::IntellVoiceTaihe;
namespace OHOS {
namespace IntellVoiceTaihe {
taihe::array<::ohos::ai::intelligentVoice::UploadFile> IntellVoiceTaiheUtils::ToTaiheArrayUploadFile(
std::vector<UploadFilesInfo> &uploadFiles)
{
std::vector<::ohos::ai::intelligentVoice::UploadFile> arrayUploadFile;
if (uploadFiles.empty()) {
INTELL_VOICE_LOG_ERROR("no upload files");
return taihe::array<::ohos::ai::intelligentVoice::UploadFile>(arrayUploadFile);
}
INTELL_VOICE_LOG_INFO("upload files size:%{public}u", static_cast<uint32_t>(uploadFiles.size()));
for (auto uploadFile : uploadFiles) {
std::vector<taihe::array<uint8_t>> arrVec;
for (auto content : uploadFile.filesContent) {
arrVec.push_back(taihe::array<uint8_t>(content));
}
::ohos::ai::intelligentVoice::UploadFileType::key_t resultCodeKey;
GetEnumKeyByValue<::ohos::ai::intelligentVoice::UploadFileType>(uploadFile.type, resultCodeKey);
::ohos::ai::intelligentVoice::UploadFile filesInfo{
.type = ohos::ai::intelligentVoice::UploadFileType(resultCodeKey),
.filesDescription = uploadFile.filesDescription,
.filesContent = taihe::array<taihe::array<uint8_t>>(arrVec),
};
arrayUploadFile.push_back(filesInfo);
}
std::vector<UploadFilesInfo>().swap(uploadFiles);
return taihe::array<::ohos::ai::intelligentVoice::UploadFile>(arrayUploadFile);
}
taihe::array<::ohos::ai::intelligentVoice::WakeupSourceFile> IntellVoiceTaiheUtils::ToTaiheArrayWakeupSourceFile(
std::vector<IntellVoice::WakeupSourceFile> &cloneFile)
{
std::vector<::ohos::ai::intelligentVoice::WakeupSourceFile> wakeupSourceFile;
if (cloneFile.empty()) {
INTELL_VOICE_LOG_ERROR("no upload files");
return taihe::array<::ohos::ai::intelligentVoice::WakeupSourceFile>(wakeupSourceFile);
}
INTELL_VOICE_LOG_INFO("cloneFile size:%{public}u", static_cast<uint32_t>(cloneFile.size()));
for (auto file : cloneFile) {
::ohos::ai::intelligentVoice::WakeupSourceFile filesInfo{
.filePath = file.filePath,
.fileContent = taihe::array<uint8_t>(file.fileContent),
};
wakeupSourceFile.push_back(filesInfo);
}
std::vector<IntellVoice::WakeupSourceFile>().swap(cloneFile);
return taihe::array<::ohos::ai::intelligentVoice::WakeupSourceFile>(wakeupSourceFile);
}
template <typename EnumType, typename ValueType>
bool IntellVoiceTaiheUtils::GetEnumKeyByValue(ValueType value, typename EnumType::key_t &key)
{
for (size_t index = 0; index < std::size(EnumType::table); ++index) {
if (EnumType::table[index] == value) {
key = static_cast<typename EnumType::key_t>(index);
return true;
}
}
return false;
}
template bool IntellVoiceTaiheUtils::GetEnumKeyByValue<EvaluationResultCode, int32_t>(
int32_t value, typename EvaluationResultCode::key_t &key);
template bool IntellVoiceTaiheUtils::GetEnumKeyByValue<EnrollResult, int32_t>(
int32_t value, typename EnrollResult::key_t &key);
template bool IntellVoiceTaiheUtils::GetEnumKeyByValue<UploadFileType, int32_t>(
int32_t value, typename UploadFileType::key_t &key);
} // namespace IntellVoiceTaihe
} // namespace OHOS
@@ -0,0 +1,73 @@
/*
* Copyright (c) 2025 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 "wakeup_intell_voice_engine_callback_taihe.h"
#include "intell_voice_log.h"
#include "intell_voice_info.h"
#include "v1_2/intell_voice_engine_types.h"
#define LOG_TAG "WakeupEngineCallbackTaihe"
using namespace std;
using namespace taihe;
using namespace ohos::ai::intelligentVoice;
using namespace OHOS::IntellVoiceEngine;
using namespace OHOS::HDI::IntelligentVoice::Engine::V1_0;
namespace OHOS {
namespace IntellVoiceTaihe {
WakeupIntellVoiceEngineCallbackTaihe::WakeupIntellVoiceEngineCallbackTaihe(
std::shared_ptr<::taihe::callback_view<
void(::ohos::ai::intelligentVoice::WakeupIntelligentVoiceEngineCallbackInfo const &)>> callback)
: callback_(callback)
{
}
WakeupIntellVoiceEngineCallbackTaihe::~WakeupIntellVoiceEngineCallbackTaihe()
{
}
void WakeupIntellVoiceEngineCallbackTaihe::ClearCallbackRef()
{
callback_ = nullptr;
}
void WakeupIntellVoiceEngineCallbackTaihe::OnEvent(const IntellVoiceEngineCallBackEvent &event)
{
std::lock_guard<std::mutex> lock(mutex_);
INTELL_VOICE_LOG_INFO("enter");
WakeupIntelligentVoiceEventType::key_t eventId
= WakeupIntelligentVoiceEventType::key_t::INTELLIGENT_VOICE_EVENT_WAKEUP_NONE;
if (event.msgId == OHOS::HDI::IntelligentVoice::Engine::V1_0::INTELL_VOICE_ENGINE_MSG_RECOGNIZE_COMPLETE) {
eventId = WakeupIntelligentVoiceEventType::key_t::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_HEADSET_RECOGNIZE_COMPLETE)) {
eventId = WakeupIntelligentVoiceEventType::key_t::INTELLIGENT_VOICE_EVENT_HEADSET_RECOGNIZE_COMPLETE;
} else {
INTELL_VOICE_LOG_ERROR("error msgId:%{public}d", event.msgId);
return;
}
WakeupIntelligentVoiceEventType eventType(eventId);
WakeupIntelligentVoiceEngineCallbackInfo cbInfo = {eventType, event.result == 0 ? true : false, event.info};
INTELL_VOICE_LOG_INFO("OnEvent EngineCallBackInfo: eventId: %{public}d, isSuccess: %{public}u",
cbInfo.eventId.get_key(), cbInfo.isSuccess);
if (callback_ != nullptr) {
(*callback_)(cbInfo);
}
}
} // namespace IntellVoiceTaihe
} // namespace OHOS
@@ -0,0 +1,178 @@
/*
* Copyright (c) 2025 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 "wakeup_intell_voice_engine_taihe.h"
#include "want.h"
#include "iservice_registry.h"
#include "system_ability_definition.h"
#include "intell_voice_log.h"
#include "i_intell_voice_engine_callback.h"
#define LOG_TAG "WakeupIntellVoiceEngineNapi"
using namespace std;
using namespace taihe;
using namespace OHOS::IntellVoice;
using namespace OHOS::IntellVoiceTaihe;
namespace OHOS {
namespace IntellVoiceTaihe {
WakeupIntelligentVoiceEngineImpl::WakeupIntelligentVoiceEngineImpl(
WakeupIntelligentVoiceEngineDescriptor const &descriptor)
{
descriptor_.wakeupPhrase = descriptor.wakeupPhrase;
engine_ = std::make_shared<WakeupIntellVoiceEngine>(descriptor_);
if (engine_ == nullptr) {
INTELL_VOICE_LOG_ERROR("create wakeup engine failed");
return;
}
}
WakeupIntelligentVoiceEngineImpl::~WakeupIntelligentVoiceEngineImpl()
{
engine_ = nullptr;
}
::taihe::array<::taihe::string> WakeupIntelligentVoiceEngineImpl::GetSupportedRegionsSync()
{
return { "CN" };
}
void WakeupIntelligentVoiceEngineImpl::SetWakeupHapInfoSync(::ohos::ai::intelligentVoice::WakeupHapInfo const &info)
{
if (engine_ == nullptr) {
INTELL_VOICE_LOG_ERROR("engine is nullptr");
return;
}
WakeupHapInfo hapInfo{
.bundleName = std::string(info.bundleName),
.abilityName = std::string(info.abilityName),
};
engine_->SetWakeupHapInfo(hapInfo);
}
void WakeupIntelligentVoiceEngineImpl::SetSensibilitySync(::ohos::ai::intelligentVoice::SensibilityType sensibility)
{
if (engine_ == nullptr) {
INTELL_VOICE_LOG_ERROR("engine is nullptr");
return;
}
engine_->SetSensibility(sensibility);
}
void WakeupIntelligentVoiceEngineImpl::SetParameterSync(::taihe::string_view key, ::taihe::string_view value)
{
if (engine_ == nullptr) {
INTELL_VOICE_LOG_ERROR("engine is nullptr");
return;
}
engine_->SetParameter(std::string(key), std::string(value));
}
void WakeupIntelligentVoiceEngineImpl::GetParameterSync(::taihe::string_view key)
{
if (engine_ == nullptr) {
INTELL_VOICE_LOG_ERROR("engine is nullptr");
return;
}
engine_->GetParameter(std::string(key));
}
::taihe::array<uint8_t> WakeupIntelligentVoiceEngineImpl::GetPcmSync()
{
std::vector<uint8_t> data;
if (engine_ == nullptr) {
INTELL_VOICE_LOG_ERROR("engine is nullptr");
return ::taihe::array<uint8_t>(data);
}
engine_->GetWakeupPcm(data);
return ::taihe::array<uint8_t>(data);
}
void WakeupIntelligentVoiceEngineImpl::StartCapturerSync(int32_t channels)
{
if (engine_ == nullptr) {
INTELL_VOICE_LOG_ERROR("engine is nullptr");
return;
}
engine_->StartCapturer(channels);
}
::taihe::array<uint8_t> WakeupIntelligentVoiceEngineImpl::ReadSync()
{
std::vector<uint8_t> data;
if (engine_ == nullptr) {
INTELL_VOICE_LOG_ERROR("engine is nullptr");
return ::taihe::array<uint8_t>(data);
}
engine_->Read(data);
return ::taihe::array<uint8_t>(data);
}
void WakeupIntelligentVoiceEngineImpl::StopCapturerSync()
{
if (engine_ == nullptr) {
INTELL_VOICE_LOG_ERROR("engine is nullptr");
return;
}
engine_->StopCapturer();
}
void WakeupIntelligentVoiceEngineImpl::ReleaseSync()
{
if (engine_ == nullptr) {
INTELL_VOICE_LOG_ERROR("engine is nullptr");
return;
}
engine_->Release();
}
void WakeupIntelligentVoiceEngineImpl::onWakeupIntelligentVoiceEvent(
callback_view<void(::ohos::ai::intelligentVoice::WakeupIntelligentVoiceEngineCallbackInfo const &)>
callback)
{
auto callbackRef = std::make_shared<callback_view<
void(::ohos::ai::intelligentVoice::WakeupIntelligentVoiceEngineCallbackInfo const &)>>(callback);
callback_ = std::make_shared<WakeupIntellVoiceEngineCallbackTaihe>(callbackRef);
if (engine_ == nullptr) {
INTELL_VOICE_LOG_ERROR("engine is nullptr");
return;
}
engine_->SetCallback(callback_);
}
void WakeupIntelligentVoiceEngineImpl::offWakeupIntelligentVoiceEvent(::taihe::optional_view<
::taihe::callback<void(::ohos::ai::intelligentVoice::WakeupIntelligentVoiceEngineCallbackInfo const &)>>
callback)
{
(void)callback;
callback_->ClearCallbackRef();
}
WakeupIntelligentVoiceEngine CreateWakeupIntelligentVoiceEngineSync(
WakeupIntelligentVoiceEngineDescriptor const &descriptor)
{
// The parameters in the make_holder function should be of the same type
// as the parameters in the constructor of the actual implementation class.
return taihe::make_holder<WakeupIntelligentVoiceEngineImpl, WakeupIntelligentVoiceEngine>(descriptor);
}
} // namespace IntellVoiceTaihe
} // namespace OHOS
TH_EXPORT_CPP_API_CreateWakeupIntelligentVoiceEngineSync(
OHOS::IntellVoiceTaihe::CreateWakeupIntelligentVoiceEngineSync);
@@ -0,0 +1,127 @@
/*
* Copyright (c) 2025 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 "wakeup_manager_taihe.h"
#include "intellvoice_taihe_utils.h"
#include "intell_voice_log.h"
#define LOG_TAG "WakeupManagerTaihe"
using namespace std;
using namespace taihe;
using namespace OHOS::IntellVoice;
using namespace OHOS::IntellVoiceTaihe;
namespace OHOS {
namespace IntellVoiceTaihe {
WakeupManagerImpl::WakeupManagerImpl()
{}
void WakeupManagerImpl::SetParameterSync(::taihe::string_view key, ::taihe::string_view value)
{
auto manager = IntellVoiceManager::GetInstance();
if (manager == nullptr) {
INTELL_VOICE_LOG_ERROR("manager is nullptr");
return;
}
manager->SetParameter(std::string(key), std::string(value));
}
::taihe::string WakeupManagerImpl::GetParameterSync(::taihe::string_view key)
{
auto manager = IntellVoiceManager::GetInstance();
if (manager == nullptr) {
INTELL_VOICE_LOG_ERROR("manager is nullptr");
return "";
}
return manager->GetParameter(std::string(key));
}
taihe::array<::ohos::ai::intelligentVoice::UploadFile> WakeupManagerImpl::GetUploadFilesSync(int32_t maxCount)
{
std::vector<UploadFilesInfo> uploadFiles;
auto manager = IntellVoiceManager::GetInstance();
if (manager == nullptr) {
INTELL_VOICE_LOG_ERROR("manager is nullptr");
return IntellVoiceTaiheUtils::ToTaiheArrayUploadFile(uploadFiles);
}
manager->GetUploadFiles(maxCount, uploadFiles);
return IntellVoiceTaiheUtils::ToTaiheArrayUploadFile(uploadFiles);
}
taihe::array<::ohos::ai::intelligentVoice::WakeupSourceFile> WakeupManagerImpl::GetWakeupSourceFilesSync()
{
std::vector<IntellVoice::WakeupSourceFile> cloneFile;
auto manager = IntellVoiceManager::GetInstance();
if (manager == nullptr) {
INTELL_VOICE_LOG_ERROR("manager is nullptr");
return IntellVoiceTaiheUtils::ToTaiheArrayWakeupSourceFile(cloneFile);
}
manager->GetWakeupSourceFiles(cloneFile);
return IntellVoiceTaiheUtils::ToTaiheArrayWakeupSourceFile(cloneFile);
}
::ohos::ai::intelligentVoice::EnrollResult WakeupManagerImpl::EnrollWithWakeupFilesForResultSync(
::taihe::array_view<::ohos::ai::intelligentVoice::WakeupSourceFile> wakeupFiles, ::taihe::string_view wakeupInfo)
{
::ohos::ai::intelligentVoice::EnrollResult::key_t resultCodeKey;
int retCode = UNKNOWN;
IntellVoiceTaiheUtils::GetEnumKeyByValue<::ohos::ai::intelligentVoice::EnrollResult>(retCode, resultCodeKey);
auto manager = IntellVoiceManager::GetInstance();
if (manager == nullptr) {
INTELL_VOICE_LOG_ERROR("manager is nullptr");
return ohos::ai::intelligentVoice::EnrollResult(resultCodeKey);
}
callback_ = std::make_shared<IntellVoiceUpdateCallbackTaihe>();
if (callback_ == nullptr) {
INTELL_VOICE_LOG_ERROR("create intell voice update callback taihe failed");
return ohos::ai::intelligentVoice::EnrollResult(resultCodeKey);
}
std::vector<IntellVoice::WakeupSourceFile> cloneFiles;
for (int i = 0; i < wakeupFiles.size(); i++) {
std::vector<uint8_t> dataVec;
for (int j = 0; j < wakeupFiles[i].fileContent.size(); j++) {
dataVec.push_back(wakeupFiles[i].fileContent[j]);
}
IntellVoice::WakeupSourceFile cloneFile {
.filePath = std::string(wakeupFiles[i].filePath),
.fileContent = dataVec,
};
cloneFiles.push_back(cloneFile);
}
int ret = manager->EnrollWithWakeupFilesForResult(cloneFiles, std::string(wakeupInfo), callback_);
IntellVoiceTaiheUtils::GetEnumKeyByValue<::ohos::ai::intelligentVoice::EnrollResult>(ret, resultCodeKey);
return ohos::ai::intelligentVoice::EnrollResult(resultCodeKey);
}
void WakeupManagerImpl::ClearUserDataSync()
{
auto manager = IntellVoiceManager::GetInstance();
if (manager == nullptr) {
INTELL_VOICE_LOG_ERROR("manager is nullptr");
return;
}
manager->ClearUserData();
}
WakeupManager GetWakeupManager()
{
return taihe::make_holder<WakeupManagerImpl, WakeupManager>();
}
} // namespace IntellVoiceTaihe
} // namespace OHOS
TH_EXPORT_CPP_API_GetWakeupManager(OHOS::IntellVoiceTaihe::GetWakeupManager);
File diff suppressed because it is too large Load Diff