From 8fffb8b358289609f89bc8a0628842fd1ffe2e44 Mon Sep 17 00:00:00 2001 From: yuzhicheng Date: Sat, 22 Nov 2025 15:34:06 +0800 Subject: [PATCH] add static sdk support Signed-off-by: yuzhicheng --- bundle.json | 4 +- .../js/napi/intell_voice_manager_napi.cpp | 50 ++ .../js/napi/intell_voice_manager_napi.h | 2 + .../napi/wakeup_intell_voice_engine_napi.cpp | 60 ++ .../js/napi/wakeup_intell_voice_engine_napi.h | 2 + frameworks/taihe/BUILD.gn | 120 ++++ .../ohos.ai.intelligentVoice.context.taihe | 20 + .../taihe/idl/ohos.ai.intelligentVoice.taihe | 286 +++++++++ ...nroll_intell_voice_engine_callback_taihe.h | 45 ++ .../inc/enroll_intell_voice_engine_taihe.h | 69 +++ .../inc/intell_voice_manager_callback_taihe.h | 43 ++ .../taihe/inc/intell_voice_manager_taihe.h | 54 ++ .../inc/intell_voice_update_callback_taihe.h | 38 ++ .../taihe/inc/intellvoice_taihe_utils.h | 47 ++ ...akeup_intell_voice_engine_callback_taihe.h | 59 ++ .../inc/wakeup_intell_voice_engine_taihe.h | 73 +++ frameworks/taihe/inc/wakeup_manager_taihe.h | 55 ++ frameworks/taihe/src/ani_constructor.cpp | 31 + ...oll_intell_voice_engine_callback_taihe.cpp | 41 ++ .../src/enroll_intell_voice_engine_taihe.cpp | 196 ++++++ .../intell_voice_manager_callback_taihe.cpp | 46 ++ .../taihe/src/intell_voice_manager_taihe.cpp | 83 +++ .../intell_voice_update_callback_taihe.cpp | 39 ++ .../taihe/src/intellvoice_taihe_utils.cpp | 101 ++++ ...eup_intell_voice_engine_callback_taihe.cpp | 73 +++ .../src/wakeup_intell_voice_engine_taihe.cpp | 178 ++++++ frameworks/taihe/src/wakeup_manager_taihe.cpp | 127 ++++ .../kits/js/@ohos.ai.intelligentVoice.d.ts | 557 +++++++++++++----- 28 files changed, 2335 insertions(+), 164 deletions(-) create mode 100644 frameworks/taihe/BUILD.gn create mode 100644 frameworks/taihe/idl/ohos.ai.intelligentVoice.context.taihe create mode 100644 frameworks/taihe/idl/ohos.ai.intelligentVoice.taihe create mode 100644 frameworks/taihe/inc/enroll_intell_voice_engine_callback_taihe.h create mode 100644 frameworks/taihe/inc/enroll_intell_voice_engine_taihe.h create mode 100644 frameworks/taihe/inc/intell_voice_manager_callback_taihe.h create mode 100644 frameworks/taihe/inc/intell_voice_manager_taihe.h create mode 100644 frameworks/taihe/inc/intell_voice_update_callback_taihe.h create mode 100644 frameworks/taihe/inc/intellvoice_taihe_utils.h create mode 100644 frameworks/taihe/inc/wakeup_intell_voice_engine_callback_taihe.h create mode 100644 frameworks/taihe/inc/wakeup_intell_voice_engine_taihe.h create mode 100644 frameworks/taihe/inc/wakeup_manager_taihe.h create mode 100644 frameworks/taihe/src/ani_constructor.cpp create mode 100644 frameworks/taihe/src/enroll_intell_voice_engine_callback_taihe.cpp create mode 100644 frameworks/taihe/src/enroll_intell_voice_engine_taihe.cpp create mode 100644 frameworks/taihe/src/intell_voice_manager_callback_taihe.cpp create mode 100644 frameworks/taihe/src/intell_voice_manager_taihe.cpp create mode 100644 frameworks/taihe/src/intell_voice_update_callback_taihe.cpp create mode 100644 frameworks/taihe/src/intellvoice_taihe_utils.cpp create mode 100644 frameworks/taihe/src/wakeup_intell_voice_engine_callback_taihe.cpp create mode 100644 frameworks/taihe/src/wakeup_intell_voice_engine_taihe.cpp create mode 100644 frameworks/taihe/src/wakeup_manager_taihe.cpp diff --git a/bundle.json b/bundle.json index 3e6101d..7a05f86 100755 --- a/bundle.json +++ b/bundle.json @@ -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": [ { diff --git a/frameworks/js/napi/intell_voice_manager_napi.cpp b/frameworks/js/napi/intell_voice_manager_napi.cpp index 0a952e0..9ea9728 100755 --- a/frameworks/js/napi/intell_voice_manager_napi.cpp +++ b/frameworks/js/napi/intell_voice_manager_napi.cpp @@ -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"); diff --git a/frameworks/js/napi/intell_voice_manager_napi.h b/frameworks/js/napi/intell_voice_manager_napi.h index 5503a1f..2b9ea6a 100755 --- a/frameworks/js/napi/intell_voice_manager_napi.h +++ b/frameworks/js/napi/intell_voice_manager_napi.h @@ -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); diff --git a/frameworks/js/napi/wakeup_intell_voice_engine_napi.cpp b/frameworks/js/napi/wakeup_intell_voice_engine_napi.cpp index 281ce75..a68932a 100755 --- a/frameworks/js/napi/wakeup_intell_voice_engine_napi.cpp +++ b/frameworks/js/napi/wakeup_intell_voice_engine_napi.cpp @@ -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) { diff --git a/frameworks/js/napi/wakeup_intell_voice_engine_napi.h b/frameworks/js/napi/wakeup_intell_voice_engine_napi.h index 163d6da..6522d28 100755 --- a/frameworks/js/napi/wakeup_intell_voice_engine_napi.h +++ b/frameworks/js/napi/wakeup_intell_voice_engine_napi.h @@ -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); diff --git a/frameworks/taihe/BUILD.gn b/frameworks/taihe/BUILD.gn new file mode 100644 index 0000000..7f07a31 --- /dev/null +++ b/frameworks/taihe/BUILD.gn @@ -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" ] +} \ No newline at end of file diff --git a/frameworks/taihe/idl/ohos.ai.intelligentVoice.context.taihe b/frameworks/taihe/idl/ohos.ai.intelligentVoice.context.taihe new file mode 100644 index 0000000..2a2ddc0 --- /dev/null +++ b/frameworks/taihe/idl/ohos.ai.intelligentVoice.context.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'; +""") diff --git a/frameworks/taihe/idl/ohos.ai.intelligentVoice.taihe b/frameworks/taihe/idl/ohos.ai.intelligentVoice.taihe new file mode 100644 index 0000000..e8084cc --- /dev/null +++ b/frameworks/taihe/idl/ohos.ai.intelligentVoice.taihe @@ -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; + + @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; + + @gen_promise("getWakeupSourceFiles") + GetWakeupSourceFilesSync(): Array; + + @gen_promise("enrollWithWakeupFilesForResult") + EnrollWithWakeupFilesForResultSync(wakeupFiles: Array, 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>; +} + +struct WakeupSourceFile { + filePath: String; + fileContent: @arraybuffer Array; +} + +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; + + @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; + + @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; + + @gen_promise("startCapturer") + StartCapturerSync(channels: i32): void; + + @gen_promise("read") + ReadSync(): @arraybuffer Array; + + @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; +} + + + + + + + + + + + + + diff --git a/frameworks/taihe/inc/enroll_intell_voice_engine_callback_taihe.h b/frameworks/taihe/inc/enroll_intell_voice_engine_callback_taihe.h new file mode 100644 index 0000000..909a45b --- /dev/null +++ b/frameworks/taihe/inc/enroll_intell_voice_engine_callback_taihe.h @@ -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 +#include +#include +#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 diff --git a/frameworks/taihe/inc/enroll_intell_voice_engine_taihe.h b/frameworks/taihe/inc/enroll_intell_voice_engine_taihe.h new file mode 100644 index 0000000..da8d566 --- /dev/null +++ b/frameworks/taihe/inc/enroll_intell_voice_engine_taihe.h @@ -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 engine_ = nullptr; + IntellVoice::EnrollIntelligentVoiceEngineDescriptor descriptor_; + std::shared_ptr callback_ = nullptr; +}; + +} // namespace IntellVoiceTaihe +} // namespace OHOS + +#endif diff --git a/frameworks/taihe/inc/intell_voice_manager_callback_taihe.h b/frameworks/taihe/inc/intell_voice_manager_callback_taihe.h new file mode 100644 index 0000000..78ff1e6 --- /dev/null +++ b/frameworks/taihe/inc/intell_voice_manager_callback_taihe.h @@ -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); + ~IntellVoiceManagerCallbackTaihe() override {}; + + void OnRemoteDied(const wptr &remote) override; + +private: + std::mutex mutex_; + std::shared_ptr> callback_ = nullptr; +}; +} // namespace IntellVoiceTaihe +} // namespace OHOS +#endif diff --git a/frameworks/taihe/inc/intell_voice_manager_taihe.h b/frameworks/taihe/inc/intell_voice_manager_taihe.h new file mode 100644 index 0000000..b9fea24 --- /dev/null +++ b/frameworks/taihe/inc/intell_voice_manager_taihe.h @@ -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 getCapabilityInfo(); + + void onServiceChange(callback_view callback); + + void offServiceChange(optional_view> callback); + +private: + std::mutex mutex_; + IntellVoiceManager *manager_ = nullptr; + sptr serviceChangeCb_ = nullptr; +}; +} // namespace IntellVoiceTaihe +} // namespace OHOS +#endif diff --git a/frameworks/taihe/inc/intell_voice_update_callback_taihe.h b/frameworks/taihe/inc/intell_voice_update_callback_taihe.h new file mode 100644 index 0000000..9cac50c --- /dev/null +++ b/frameworks/taihe/inc/intell_voice_update_callback_taihe.h @@ -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 +#include +#include +#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 diff --git a/frameworks/taihe/inc/intellvoice_taihe_utils.h b/frameworks/taihe/inc/intellvoice_taihe_utils.h new file mode 100644 index 0000000..57ebc72 --- /dev/null +++ b/frameworks/taihe/inc/intellvoice_taihe_utils.h @@ -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 &uploadFiles); + + static taihe::array<::ohos::ai::intelligentVoice::WakeupSourceFile> ToTaiheArrayWakeupSourceFile( + std::vector &cloneFile); + + template + static bool GetEnumKeyByValue(ValueType value, typename EnumType::key_t &key); +}; +} // namespace IntellVoiceTaihe +} // namespace OHOS +#endif \ No newline at end of file diff --git a/frameworks/taihe/inc/wakeup_intell_voice_engine_callback_taihe.h b/frameworks/taihe/inc/wakeup_intell_voice_engine_callback_taihe.h new file mode 100644 index 0000000..983776f --- /dev/null +++ b/frameworks/taihe/inc/wakeup_intell_voice_engine_callback_taihe.h @@ -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 +#include +#include +#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 + > 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 diff --git a/frameworks/taihe/inc/wakeup_intell_voice_engine_taihe.h b/frameworks/taihe/inc/wakeup_intell_voice_engine_taihe.h new file mode 100644 index 0000000..ac9d797 --- /dev/null +++ b/frameworks/taihe/inc/wakeup_intell_voice_engine_taihe.h @@ -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 GetPcmSync(); + + void StartCapturerSync(int32_t channels); + + ::taihe::array ReadSync(); + + void StopCapturerSync(); + + void ReleaseSync(); + + void onWakeupIntelligentVoiceEvent( + ::taihe::callback_view + callback); + + void offWakeupIntelligentVoiceEvent(::taihe::optional_view< + ::taihe::callback> + callback); + +private: + std::shared_ptr engine_ = nullptr; + std::shared_ptr callback_ = nullptr; + IntellVoice::WakeupIntelligentVoiceEngineDescriptor descriptor_; +}; + +} // namespace IntellVoiceTaihe +} // namespace OHOS + +#endif diff --git a/frameworks/taihe/inc/wakeup_manager_taihe.h b/frameworks/taihe/inc/wakeup_manager_taihe.h new file mode 100644 index 0000000..de06268 --- /dev/null +++ b/frameworks/taihe/inc/wakeup_manager_taihe.h @@ -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 callback_ = nullptr; +}; + +} // namespace IntellVoiceTaihe +} // namespace OHOS + +#endif diff --git a/frameworks/taihe/src/ani_constructor.cpp b/frameworks/taihe/src/ani_constructor.cpp new file mode 100644 index 0000000..9cc1637 --- /dev/null +++ b/frameworks/taihe/src/ani_constructor.cpp @@ -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; +} diff --git a/frameworks/taihe/src/enroll_intell_voice_engine_callback_taihe.cpp b/frameworks/taihe/src/enroll_intell_voice_engine_callback_taihe.cpp new file mode 100644 index 0000000..499a97d --- /dev/null +++ b/frameworks/taihe/src/enroll_intell_voice_engine_callback_taihe.cpp @@ -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 \ No newline at end of file diff --git a/frameworks/taihe/src/enroll_intell_voice_engine_taihe.cpp b/frameworks/taihe/src/enroll_intell_voice_engine_taihe.cpp new file mode 100644 index 0000000..cc837cd --- /dev/null +++ b/frameworks/taihe/src/enroll_intell_voice_engine_taihe.cpp @@ -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(descriptor_); + if (engine_ == nullptr) { + INTELL_VOICE_LOG_ERROR("create enroll engine failed"); + return; + } + + callback_ = std::make_shared(); + 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(descriptor); +} + +} // namespace IntellVoiceTaihe +} // namespace OHOS + +TH_EXPORT_CPP_API_CreateEnrollIntelligentVoiceEngineSync( + OHOS::IntellVoiceTaihe::CreateEnrollIntelligentVoiceEngineSync); diff --git a/frameworks/taihe/src/intell_voice_manager_callback_taihe.cpp b/frameworks/taihe/src/intell_voice_manager_callback_taihe.cpp new file mode 100644 index 0000000..6e4dc85 --- /dev/null +++ b/frameworks/taihe/src/intell_voice_manager_callback_taihe.cpp @@ -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): callback_(callback) +{ + INTELL_VOICE_LOG_INFO("enter"); +} + +void IntellVoiceManagerCallbackTaihe::OnRemoteDied(const wptr &remote) +{ + std::unique_lock 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 \ No newline at end of file diff --git a/frameworks/taihe/src/intell_voice_manager_taihe.cpp b/frameworks/taihe/src/intell_voice_manager_taihe.cpp new file mode 100644 index 0000000..2a97439 --- /dev/null +++ b/frameworks/taihe/src/intell_voice_manager_taihe.cpp @@ -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 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 callback) +{ + if (manager_ != nullptr) { + if (serviceChangeCb_ != nullptr) { + manager_->DeregisterServiceDeathRecipient(serviceChangeCb_); + } + serviceChangeCb_ = new (std::nothrow) IntellVoiceManagerCallbackTaihe( + std::make_shared>(callback)); + manager_->RegisterServiceDeathRecipient(serviceChangeCb_); + } +} + +void IntelligentVoiceManagerImpl::offServiceChange(optional_view> callback) +{ + (void)callback; + if (manager_ != nullptr && serviceChangeCb_ != nullptr) { + manager_->DeregisterServiceDeathRecipient(serviceChangeCb_); + } +} + +IntelligentVoiceManager GetIntelligentVoiceManager() +{ + INTELL_VOICE_LOG_INFO("enter"); + return make_holder(); +} +} // namespace IntellVoiceTaihe +} // namespace OHOS + +TH_EXPORT_CPP_API_GetIntelligentVoiceManager(GetIntelligentVoiceManager); diff --git a/frameworks/taihe/src/intell_voice_update_callback_taihe.cpp b/frameworks/taihe/src/intell_voice_update_callback_taihe.cpp new file mode 100644 index 0000000..ba3e3a3 --- /dev/null +++ b/frameworks/taihe/src/intell_voice_update_callback_taihe.cpp @@ -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 \ No newline at end of file diff --git a/frameworks/taihe/src/intellvoice_taihe_utils.cpp b/frameworks/taihe/src/intellvoice_taihe_utils.cpp new file mode 100644 index 0000000..29f763a --- /dev/null +++ b/frameworks/taihe/src/intellvoice_taihe_utils.cpp @@ -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 &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(uploadFiles.size())); + for (auto uploadFile : uploadFiles) { + std::vector> arrVec; + for (auto content : uploadFile.filesContent) { + arrVec.push_back(taihe::array(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>(arrVec), + }; + arrayUploadFile.push_back(filesInfo); + } + std::vector().swap(uploadFiles); + return taihe::array<::ohos::ai::intelligentVoice::UploadFile>(arrayUploadFile); +} + +taihe::array<::ohos::ai::intelligentVoice::WakeupSourceFile> IntellVoiceTaiheUtils::ToTaiheArrayWakeupSourceFile( + std::vector &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(cloneFile.size())); + for (auto file : cloneFile) { + ::ohos::ai::intelligentVoice::WakeupSourceFile filesInfo{ + .filePath = file.filePath, + .fileContent = taihe::array(file.fileContent), + }; + wakeupSourceFile.push_back(filesInfo); + } + std::vector().swap(cloneFile); + return taihe::array<::ohos::ai::intelligentVoice::WakeupSourceFile>(wakeupSourceFile); +} + +template +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(index); + return true; + } + } + return false; +} + +template bool IntellVoiceTaiheUtils::GetEnumKeyByValue( + int32_t value, typename EvaluationResultCode::key_t &key); + +template bool IntellVoiceTaiheUtils::GetEnumKeyByValue( + int32_t value, typename EnrollResult::key_t &key); + +template bool IntellVoiceTaiheUtils::GetEnumKeyByValue( + int32_t value, typename UploadFileType::key_t &key); + +} // namespace IntellVoiceTaihe +} // namespace OHOS \ No newline at end of file diff --git a/frameworks/taihe/src/wakeup_intell_voice_engine_callback_taihe.cpp b/frameworks/taihe/src/wakeup_intell_voice_engine_callback_taihe.cpp new file mode 100644 index 0000000..582c1e6 --- /dev/null +++ b/frameworks/taihe/src/wakeup_intell_voice_engine_callback_taihe.cpp @@ -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 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_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 \ No newline at end of file diff --git a/frameworks/taihe/src/wakeup_intell_voice_engine_taihe.cpp b/frameworks/taihe/src/wakeup_intell_voice_engine_taihe.cpp new file mode 100644 index 0000000..6fdfb14 --- /dev/null +++ b/frameworks/taihe/src/wakeup_intell_voice_engine_taihe.cpp @@ -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(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 WakeupIntelligentVoiceEngineImpl::GetPcmSync() +{ + std::vector data; + if (engine_ == nullptr) { + INTELL_VOICE_LOG_ERROR("engine is nullptr"); + return ::taihe::array(data); + } + engine_->GetWakeupPcm(data); + return ::taihe::array(data); +} + +void WakeupIntelligentVoiceEngineImpl::StartCapturerSync(int32_t channels) +{ + if (engine_ == nullptr) { + INTELL_VOICE_LOG_ERROR("engine is nullptr"); + return; + } + engine_->StartCapturer(channels); +} + +::taihe::array WakeupIntelligentVoiceEngineImpl::ReadSync() +{ + std::vector data; + if (engine_ == nullptr) { + INTELL_VOICE_LOG_ERROR("engine is nullptr"); + return ::taihe::array(data); + } + engine_->Read(data); + return ::taihe::array(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 + callback) +{ + auto callbackRef = std::make_shared>(callback); + callback_ = std::make_shared(callbackRef); + if (engine_ == nullptr) { + INTELL_VOICE_LOG_ERROR("engine is nullptr"); + return; + } + engine_->SetCallback(callback_); +} + +void WakeupIntelligentVoiceEngineImpl::offWakeupIntelligentVoiceEvent(::taihe::optional_view< + ::taihe::callback> + 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(descriptor); +} + +} // namespace IntellVoiceTaihe +} // namespace OHOS + +TH_EXPORT_CPP_API_CreateWakeupIntelligentVoiceEngineSync( + OHOS::IntellVoiceTaihe::CreateWakeupIntelligentVoiceEngineSync); \ No newline at end of file diff --git a/frameworks/taihe/src/wakeup_manager_taihe.cpp b/frameworks/taihe/src/wakeup_manager_taihe.cpp new file mode 100644 index 0000000..897bcc6 --- /dev/null +++ b/frameworks/taihe/src/wakeup_manager_taihe.cpp @@ -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 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 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(); + if (callback_ == nullptr) { + INTELL_VOICE_LOG_ERROR("create intell voice update callback taihe failed"); + return ohos::ai::intelligentVoice::EnrollResult(resultCodeKey); + } + std::vector cloneFiles; + for (int i = 0; i < wakeupFiles.size(); i++) { + std::vector 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(); +} +} // namespace IntellVoiceTaihe +} // namespace OHOS + +TH_EXPORT_CPP_API_GetWakeupManager(OHOS::IntellVoiceTaihe::GetWakeupManager); diff --git a/interfaces/kits/js/@ohos.ai.intelligentVoice.d.ts b/interfaces/kits/js/@ohos.ai.intelligentVoice.d.ts index 2b8c50f..a77179b 100755 --- a/interfaces/kits/js/@ohos.ai.intelligentVoice.d.ts +++ b/interfaces/kits/js/@ohos.ai.intelligentVoice.d.ts @@ -24,7 +24,8 @@ import type { AsyncCallback, Callback } from './@ohos.base'; * @namespace intelligentVoice * @syscap SystemCapability.AI.IntelligentVoice.Core * @systemapi - * @since 10 + * @since 10 dynamic + * @since 22 static */ declare namespace intelligentVoice { /** @@ -36,7 +37,8 @@ declare namespace intelligentVoice { * @throws { BusinessError } 22700101 - No memory. * @syscap SystemCapability.AI.IntelligentVoice.Core * @systemapi - * @since 10 + * @since 10 dynamic + * @since 22 static */ function getIntelligentVoiceManager(): IntelligentVoiceManager; @@ -45,7 +47,8 @@ declare namespace intelligentVoice { * @typedef IntelligentVoiceManager * @syscap SystemCapability.AI.IntelligentVoice.Core * @systemapi - * @since 10 + * @since 10 dynamic + * @since 22 static */ interface IntelligentVoiceManager { /** @@ -56,7 +59,8 @@ declare namespace intelligentVoice { * @throws { BusinessError } 202 - Not system application. * @syscap SystemCapability.AI.IntelligentVoice.Core * @systemapi - * @since 10 + * @since 10 dynamic + * @since 22 static */ getCapabilityInfo(): Array; /** @@ -69,9 +73,21 @@ declare namespace intelligentVoice { * @throws { BusinessError } 202 - Not system application. * @syscap SystemCapability.AI.IntelligentVoice.Core * @systemapi - * @since 10 + * @since 10 dynamic */ on(type: 'serviceChange', callback: Callback): void; + /** + * Subscribes service change events. When the state of intelligent voice service changes, + * the callback is invoked. + * @permission ohos.permission.MANAGE_INTELLIGENT_VOICE + * @param { Callback } callback - Callback is invoked when the event is triggered. + * @throws { BusinessError } 201 - Permission denied. + * @throws { BusinessError } 202 - Not system application. + * @syscap SystemCapability.AI.IntelligentVoice.Core + * @systemapi + * @since 22 static + */ + onServiceChange(callback: Callback): void; /** * Unsubscribes service change events. * @permission ohos.permission.MANAGE_INTELLIGENT_VOICE @@ -81,9 +97,20 @@ declare namespace intelligentVoice { * @throws { BusinessError } 202 - Not system application. * @syscap SystemCapability.AI.IntelligentVoice.Core * @systemapi - * @since 10 + * @since 10 dynamic */ off(type: 'serviceChange', callback?: Callback): void; + /** + * Unsubscribes service change events. + * @permission ohos.permission.MANAGE_INTELLIGENT_VOICE + * @param { Callback } [callback] - Callback is invoked when the event is triggered. + * @throws { BusinessError } 201 - Permission denied. + * @throws { BusinessError } 202 - Not system application. + * @syscap SystemCapability.AI.IntelligentVoice.Core + * @systemapi + * @since 22 static + */ + offServiceChange(callback?: Callback): void; } /** @@ -91,7 +118,8 @@ declare namespace intelligentVoice { * @typedef WakeupManager * @syscap SystemCapability.AI.IntelligentVoice.Core * @systemapi - * @since 12 + * @since 12 dynamic + * @since 22 static */ interface WakeupManager { /** @@ -107,7 +135,8 @@ declare namespace intelligentVoice { * @throws { BusinessError } 22700107 - System error. * @syscap SystemCapability.AI.IntelligentVoice.Core * @systemapi - * @since 12 + * @since 12 dynamic + * @since 22 static */ setParameter(key: string, value: string): Promise; /** @@ -122,13 +151,14 @@ declare namespace intelligentVoice { * @throws { BusinessError } 22700107 - System error. * @syscap SystemCapability.AI.IntelligentVoice.Core * @systemapi - * @since 12 + * @since 12 dynamic + * @since 22 static */ getParameter(key: string): Promise; /** * Obtains files needed to upload. This method uses a promise to return the files needed to upload. * @permission ohos.permission.MANAGE_INTELLIGENT_VOICE - * @param { number } maxCount - the maximum count of upload files. The maxCount should be greater than 0 and smaller than 101 + * @param { int } maxCount - the maximum count of upload files. The maxCount should be greater than 0 and smaller than 101 * @returns { Promise> } the promise used to return the upload files. * @throws { BusinessError } 201 - Permission denied. * @throws { BusinessError } 202 - Not system application. @@ -138,9 +168,10 @@ declare namespace intelligentVoice { * @throws { BusinessError } 22700107 - System error. * @syscap SystemCapability.AI.IntelligentVoice.Core * @systemapi - * @since 12 + * @since 12 dynamic + * @since 22 static */ - getUploadFiles (maxCount: number): Promise>; + getUploadFiles (maxCount: int): Promise>; /** * Obtains wakeup source files. This method uses a promise to return the wakeup source files. * @permission ohos.permission.MANAGE_INTELLIGENT_VOICE @@ -151,7 +182,8 @@ declare namespace intelligentVoice { * @throws { BusinessError } 22700107 - System error. * @syscap SystemCapability.AI.IntelligentVoice.Core * @systemapi - * @since 12 + * @since 12 dynamic + * @since 22 static */ getWakeupSourceFiles(): Promise>; /** @@ -168,7 +200,8 @@ declare namespace intelligentVoice { * @throws { BusinessError } 22700107 - System error. * @syscap SystemCapability.AI.IntelligentVoice.Core * @systemapi - * @since 12 + * @since 12 dynamic + * @since 22 static */ enrollWithWakeupFilesForResult(wakeupFiles: Array, wakeupInfo: string): Promise; /** @@ -180,7 +213,8 @@ declare namespace intelligentVoice { * @throws { BusinessError } 22700107 - System error. * @syscap SystemCapability.AI.IntelligentVoice.Core * @systemapi - * @since 12 + * @since 12 dynamic + * @since 22 static */ clearUserData(): Promise; } @@ -190,23 +224,26 @@ declare namespace intelligentVoice { * @enum {number} * @syscap SystemCapability.AI.IntelligentVoice.Core * @systemapi - * @since 12 + * @since 12 dynamic + * @since 22 static */ enum UploadFileType { /** * Enroll file. * @syscap SystemCapability.AI.IntelligentVoice.Core * @systemapi - * @since 12 + * @since 12 dynamic + * @since 22 static */ ENROLL_FILE = 0, /** * Wakeup file. * @syscap SystemCapability.AI.IntelligentVoice.Core * @systemapi - * @since 12 + * @since 12 dynamic + * @since 22 static */ - WAKEUP_FILE = 1, + WAKEUP_FILE = 1 } /** @@ -214,7 +251,8 @@ declare namespace intelligentVoice { * @typedef UploadFile * @syscap SystemCapability.AI.IntelligentVoice.Core * @systemapi - * @since 12 + * @since 12 dynamic + * @since 22 static */ interface UploadFile { /** @@ -222,7 +260,8 @@ declare namespace intelligentVoice { * @type { UploadFileType } * @syscap SystemCapability.AI.IntelligentVoice.Core * @systemapi - * @since 12 + * @since 12 dynamic + * @since 22 static */ type: UploadFileType; /** @@ -230,7 +269,8 @@ declare namespace intelligentVoice { * @type { string } * @syscap SystemCapability.AI.IntelligentVoice.Core * @systemapi - * @since 12 + * @since 12 dynamic + * @since 22 static */ filesDescription: string; /** @@ -238,7 +278,8 @@ declare namespace intelligentVoice { * @type { Array } * @syscap SystemCapability.AI.IntelligentVoice.Core * @systemapi - * @since 12 + * @since 12 dynamic + * @since 22 static */ filesContent: Array; } @@ -248,7 +289,8 @@ declare namespace intelligentVoice { * @typedef WakeupSourceFile * @syscap SystemCapability.AI.IntelligentVoice.Core * @systemapi - * @since 12 + * @since 12 dynamic + * @since 22 static */ interface WakeupSourceFile { /** @@ -256,7 +298,8 @@ declare namespace intelligentVoice { * @type { string } * @syscap SystemCapability.AI.IntelligentVoice.Core * @systemapi - * @since 12 + * @since 12 dynamic + * @since 22 static */ filePath: string; /** @@ -264,7 +307,8 @@ declare namespace intelligentVoice { * @type { ArrayBuffer } * @syscap SystemCapability.AI.IntelligentVoice.Core * @systemapi - * @since 12 + * @since 12 dynamic + * @since 22 static */ fileContent: ArrayBuffer; } @@ -274,16 +318,18 @@ declare namespace intelligentVoice { * @enum {number} * @syscap SystemCapability.AI.IntelligentVoice.Core * @systemapi - * @since 10 + * @since 10 dynamic + * @since 22 static */ enum ServiceChangeType { /** * Service unavailable. * @syscap SystemCapability.AI.IntelligentVoice.Core * @systemapi - * @since 10 + * @since 10 dynamic + * @since 22 static */ - SERVICE_UNAVAILABLE = 0, + SERVICE_UNAVAILABLE = 0 } /** @@ -291,30 +337,34 @@ declare namespace intelligentVoice { * @enum {number} * @syscap SystemCapability.AI.IntelligentVoice.Core * @systemapi - * @since 10 + * @since 10 dynamic + * @since 22 static */ enum IntelligentVoiceEngineType { /** * Enroll engine. * @syscap SystemCapability.AI.IntelligentVoice.Core * @systemapi - * @since 10 + * @since 10 dynamic + * @since 22 static */ ENROLL_ENGINE_TYPE = 0, /** * Wakeup engine. * @syscap SystemCapability.AI.IntelligentVoice.Core * @systemapi - * @since 10 + * @since 10 dynamic + * @since 22 static */ WAKEUP_ENGINE_TYPE = 1, /** * Update engine. * @syscap SystemCapability.AI.IntelligentVoice.Core * @systemapi - * @since 10 + * @since 10 dynamic + * @since 22 static */ - UPDATE_ENGINE_TYPE = 2, + UPDATE_ENGINE_TYPE = 2 } /** @@ -322,7 +372,8 @@ declare namespace intelligentVoice { * @typedef EnrollIntelligentVoiceEngineDescriptor * @syscap SystemCapability.AI.IntelligentVoice.Core * @systemapi - * @since 10 + * @since 10 dynamic + * @since 22 static */ interface EnrollIntelligentVoiceEngineDescriptor { /** @@ -330,7 +381,8 @@ declare namespace intelligentVoice { * @type { string } * @syscap SystemCapability.AI.IntelligentVoice.Core * @systemapi - * @since 10 + * @since 10 dynamic + * @since 22 static */ wakeupPhrase: string; } @@ -340,7 +392,8 @@ declare namespace intelligentVoice { * @typedef WakeupIntelligentVoiceEngineDescriptor * @syscap SystemCapability.AI.IntelligentVoice.Core * @systemapi - * @since 10 + * @since 10 dynamic + * @since 22 static */ interface WakeupIntelligentVoiceEngineDescriptor { /** @@ -348,7 +401,8 @@ declare namespace intelligentVoice { * @type { boolean } * @syscap SystemCapability.AI.IntelligentVoice.Core * @systemapi - * @since 10 + * @since 10 dynamic + * @since 22 static */ needReconfirm: boolean; /** @@ -356,7 +410,8 @@ declare namespace intelligentVoice { * @type { string } * @syscap SystemCapability.AI.IntelligentVoice.Core * @systemapi - * @since 10 + * @since 10 dynamic + * @since 22 static */ wakeupPhrase: string; } @@ -366,107 +421,122 @@ declare namespace intelligentVoice { * @enum {number} * @syscap SystemCapability.AI.IntelligentVoice.Core * @systemapi - * @since 12 + * @since 12 dynamic + * @since 22 static */ enum EvaluationResultCode { /** * Unknown. * @syscap SystemCapability.AI.IntelligentVoice.Core * @systemapi - * @since 12 + * @since 12 dynamic + * @since 22 static */ - UNKNOWN = 0, + UNKNOWN = 0, /** * Pass. * @syscap SystemCapability.AI.IntelligentVoice.Core * @systemapi - * @since 12 + * @since 12 dynamic + * @since 22 static */ PASS = 1, /** * Word is empty. * @syscap SystemCapability.AI.IntelligentVoice.Core * @systemapi - * @since 12 + * @since 12 dynamic + * @since 22 static */ WORD_EMPTY = 2, /** * Only chinese is supported. * @syscap SystemCapability.AI.IntelligentVoice.Core * @systemapi - * @since 12 + * @since 12 dynamic + * @since 22 static */ CHINESE_ONLY = 3, /** * Invalid length. * @syscap SystemCapability.AI.IntelligentVoice.Core * @systemapi - * @since 12 + * @since 12 dynamic + * @since 22 static */ INVALID_LENGTH = 4, /** * Unusual word. * @syscap SystemCapability.AI.IntelligentVoice.Core * @systemapi - * @since 12 + * @since 12 dynamic + * @since 22 static */ UNUSUAL_WORD = 5, /** * Consecutive same word. * @syscap SystemCapability.AI.IntelligentVoice.Core * @systemapi - * @since 12 + * @since 12 dynamic + * @since 22 static */ CONSECUTIVE_SAME_WORD = 6, /** * Too few phonemes. * @syscap SystemCapability.AI.IntelligentVoice.Core * @systemapi - * @since 12 + * @since 12 dynamic + * @since 22 static */ TOO_FEW_PHONEMES = 7, /** * Too many phonemes. * @syscap SystemCapability.AI.IntelligentVoice.Core * @systemapi - * @since 12 + * @since 12 dynamic + * @since 22 static */ TOO_MANY_PHONEMES = 8, /** * Contain common instruction. * @syscap SystemCapability.AI.IntelligentVoice.Core * @systemapi - * @since 12 + * @since 12 dynamic + * @since 22 static */ COMMON_INSTRUCTION = 9, /** * Contain common spoken language. * @syscap SystemCapability.AI.IntelligentVoice.Core * @systemapi - * @since 12 + * @since 12 dynamic + * @since 22 static */ COMMON_SPOKEN_LANGUAGE = 10, /** * Contain sensitive word. * @syscap SystemCapability.AI.IntelligentVoice.Core * @systemapi - * @since 12 + * @since 12 dynamic + * @since 22 static */ SENSITIVE_WORD = 11, /** * Two consecutive words without initial consonant. * @syscap SystemCapability.AI.IntelligentVoice.Core * @systemapi - * @since 12 + * @since 12 dynamic + * @since 22 static */ NO_INITIAL_CONSONANT = 12, /** * Contain repeated phoneme. * @syscap SystemCapability.AI.IntelligentVoice.Core * @systemapi - * @since 12 + * @since 12 dynamic + * @since 22 static */ - REPEATED_PHONEME = 13, + REPEATED_PHONEME = 13 } /** @@ -474,23 +544,26 @@ declare namespace intelligentVoice { * @typedef EvaluationResult * @syscap SystemCapability.AI.IntelligentVoice.Core * @systemapi - * @since 12 + * @since 12 dynamic + * @since 22 static */ interface EvaluationResult { /** * Evaluation score. - * @type { number } + * @type { int } * @syscap SystemCapability.AI.IntelligentVoice.Core * @systemapi - * @since 12 + * @since 12 dynamic + * @since 22 static */ - score: number; + score: int; /** * Describes evaluation result code. * @type { EvaluationResultCode } * @syscap SystemCapability.AI.IntelligentVoice.Core * @systemapi - * @since 12 + * @since 12 dynamic + * @since 22 static */ resultCode: EvaluationResultCode; } @@ -505,7 +578,8 @@ declare namespace intelligentVoice { * @throws { BusinessError } 22700107 - System error. * @syscap SystemCapability.AI.IntelligentVoice.Core * @systemapi - * @since 12 + * @since 12 dynamic + * @since 22 static */ function getWakeupManager(): WakeupManager; @@ -521,7 +595,8 @@ declare namespace intelligentVoice { * @throws { BusinessError } 22700102 - Invalid parameter. * @syscap SystemCapability.AI.IntelligentVoice.Core * @systemapi - * @since 10 + * @since 10 dynamic + * @since 22 static */ function createEnrollIntelligentVoiceEngine(descriptor: EnrollIntelligentVoiceEngineDescriptor, callback: AsyncCallback): void; @@ -537,7 +612,8 @@ declare namespace intelligentVoice { * @throws { BusinessError } 22700102 - Invalid parameter. * @syscap SystemCapability.AI.IntelligentVoice.Core * @systemapi - * @since 10 + * @since 10 dynamic + * @since 22 static */ function createEnrollIntelligentVoiceEngine(descriptor: EnrollIntelligentVoiceEngineDescriptor): Promise; @@ -553,7 +629,8 @@ declare namespace intelligentVoice { * @throws { BusinessError } 22700102 - Invalid parameter. * @syscap SystemCapability.AI.IntelligentVoice.Core * @systemapi - * @since 10 + * @since 10 dynamic + * @since 22 static */ function createWakeupIntelligentVoiceEngine(descriptor: WakeupIntelligentVoiceEngineDescriptor, callback: AsyncCallback): void; @@ -569,7 +646,8 @@ declare namespace intelligentVoice { * @throws { BusinessError } 22700102 - Invalid parameter. * @syscap SystemCapability.AI.IntelligentVoice.Core * @systemapi - * @since 10 + * @since 10 dynamic + * @since 22 static */ function createWakeupIntelligentVoiceEngine(descriptor: WakeupIntelligentVoiceEngineDescriptor): Promise; @@ -578,7 +656,8 @@ declare namespace intelligentVoice { * @typedef EnrollEngineConfig * @syscap SystemCapability.AI.IntelligentVoice.Core * @systemapi - * @since 10 + * @since 10 dynamic + * @since 22 static */ interface EnrollEngineConfig { /** @@ -586,7 +665,8 @@ declare namespace intelligentVoice { * @type { string } * @syscap SystemCapability.AI.IntelligentVoice.Core * @systemapi - * @since 10 + * @since 10 dynamic + * @since 22 static */ language: string; /** @@ -594,7 +674,8 @@ declare namespace intelligentVoice { * @type { string } * @syscap SystemCapability.AI.IntelligentVoice.Core * @systemapi - * @since 10 + * @since 10 dynamic + * @since 22 static */ region: string; } @@ -604,30 +685,34 @@ declare namespace intelligentVoice { * @enum {number} * @syscap SystemCapability.AI.IntelligentVoice.Core * @systemapi - * @since 10 + * @since 10 dynamic + * @since 22 static */ enum SensibilityType { /** * Low sensibility. * @syscap SystemCapability.AI.IntelligentVoice.Core * @systemapi - * @since 10 + * @since 10 dynamic + * @since 22 static */ LOW_SENSIBILITY = 1, /** * Middle sensibility. * @syscap SystemCapability.AI.IntelligentVoice.Core * @systemapi - * @since 10 + * @since 10 dynamic + * @since 22 static */ MIDDLE_SENSIBILITY = 2, /** * High sensibility. * @syscap SystemCapability.AI.IntelligentVoice.Core * @systemapi - * @since 10 + * @since 10 dynamic + * @since 22 static */ - HIGH_SENSIBILITY = 3, + HIGH_SENSIBILITY = 3 } /** @@ -635,7 +720,8 @@ declare namespace intelligentVoice { * @typedef WakeupHapInfo * @syscap SystemCapability.AI.IntelligentVoice.Core * @systemapi - * @since 10 + * @since 10 dynamic + * @since 22 static */ interface WakeupHapInfo { /** @@ -643,7 +729,8 @@ declare namespace intelligentVoice { * @type { string } * @syscap SystemCapability.AI.IntelligentVoice.Core * @systemapi - * @since 10 + * @since 10 dynamic + * @since 22 static */ bundleName: string; /** @@ -651,7 +738,8 @@ declare namespace intelligentVoice { * @type { string } * @syscap SystemCapability.AI.IntelligentVoice.Core * @systemapi - * @since 10 + * @since 10 dynamic + * @since 22 static */ abilityName: string; } @@ -661,30 +749,34 @@ declare namespace intelligentVoice { * @enum {number} * @syscap SystemCapability.AI.IntelligentVoice.Core * @systemapi - * @since 10 + * @since 10 dynamic + * @since 22 static */ enum WakeupIntelligentVoiceEventType { /** * Wakeup None. * @syscap SystemCapability.AI.IntelligentVoice.Core * @systemapi - * @since 10 + * @since 10 dynamic + * @since 22 static */ INTELLIGENT_VOICE_EVENT_WAKEUP_NONE = 0, /** * Recognize complete. * @syscap SystemCapability.AI.IntelligentVoice.Core * @systemapi - * @since 10 + * @since 10 dynamic + * @since 22 static */ INTELLIGENT_VOICE_EVENT_RECOGNIZE_COMPLETE = 1, /** * Headset Recognize complete. * @syscap SystemCapability.AI.IntelligentVoice.Core * @systemapi - * @since 12 + * @since 12 dynamic + * @since 22 static */ - INTELLIGENT_VOICE_EVENT_HEADSET_RECOGNIZE_COMPLETE = 2, + INTELLIGENT_VOICE_EVENT_HEADSET_RECOGNIZE_COMPLETE = 2 } /** @@ -692,58 +784,66 @@ declare namespace intelligentVoice { * @enum {number} * @syscap SystemCapability.AI.IntelligentVoice.Core * @systemapi - * @since 10 + * @since 10 dynamic + * @since 22 static */ enum IntelligentVoiceErrorCode { /** * No memory. * @syscap SystemCapability.AI.IntelligentVoice.Core * @systemapi - * @since 10 + * @since 10 dynamic + * @since 22 static */ INTELLIGENT_VOICE_NO_MEMORY = 22700101, /** * Invalid parameter. * @syscap SystemCapability.AI.IntelligentVoice.Core * @systemapi - * @since 10 + * @since 10 dynamic + * @since 22 static */ INTELLIGENT_VOICE_INVALID_PARAM = 22700102, /** * Init failed. * @syscap SystemCapability.AI.IntelligentVoice.Core * @systemapi - * @since 10 + * @since 10 dynamic + * @since 22 static */ INTELLIGENT_VOICE_INIT_FAILED = 22700103, /** * Failed to commit the enrollment. * @syscap SystemCapability.AI.IntelligentVoice.Core * @systemapi - * @since 10 + * @since 10 dynamic + * @since 22 static */ INTELLIGENT_VOICE_COMMIT_ENROLL_FAILED = 22700104, /** * Start capturer failed. * @syscap SystemCapability.AI.IntelligentVoice.Core * @systemapi - * @since 12 + * @since 12 dynamic + * @since 22 static */ INTELLIGENT_VOICE_START_CAPTURER_FAILED = 22700105, /** * Read failed. * @syscap SystemCapability.AI.IntelligentVoice.Core * @systemapi - * @since 12 + * @since 12 dynamic + * @since 22 static */ INTELLIGENT_VOICE_READ_FAILED = 22700106, /** * System error. * @syscap SystemCapability.AI.IntelligentVoice.Core * @systemapi - * @since 12 + * @since 12 dynamic + * @since 22 static */ - INTELLIGENT_VOICE_SYSTEM_ERROR = 22700107, + INTELLIGENT_VOICE_SYSTEM_ERROR = 22700107 } /** @@ -751,65 +851,74 @@ declare namespace intelligentVoice { * @enum {number} * @syscap SystemCapability.AI.IntelligentVoice.Core * @systemapi - * @since 10 + * @since 10 dynamic + * @since 22 static */ enum EnrollResult { /** * Success. * @syscap SystemCapability.AI.IntelligentVoice.Core * @systemapi - * @since 10 + * @since 10 dynamic + * @since 22 static */ SUCCESS = 0, /** * Vpr train failed. * @syscap SystemCapability.AI.IntelligentVoice.Core * @systemapi - * @since 10 + * @since 10 dynamic + * @since 22 static */ VPR_TRAIN_FAILED = -1, /** * Wakeup phrase not match. * @syscap SystemCapability.AI.IntelligentVoice.Core * @systemapi - * @since 10 + * @since 10 dynamic + * @since 22 static */ WAKEUP_PHRASE_NOT_MATCH = -2, /** * Too noisy. * @syscap SystemCapability.AI.IntelligentVoice.Core * @systemapi - * @since 10 + * @since 10 dynamic + * @since 22 static */ TOO_NOISY = -3, /** * Too loud. * @syscap SystemCapability.AI.IntelligentVoice.Core * @systemapi - * @since 10 + * @since 10 dynamic + * @since 22 static */ TOO_LOUD = -4, /** * Interval large. * @syscap SystemCapability.AI.IntelligentVoice.Core * @systemapi - * @since 10 + * @since 10 dynamic + * @since 22 static */ INTERVAL_LARGE = -5, /** * Different person. * @syscap SystemCapability.AI.IntelligentVoice.Core * @systemapi - * @since 10 + * @since 10 dynamic + * @since 22 static */ DIFFERENT_PERSON = -6, /** * Unknown error. * @syscap SystemCapability.AI.IntelligentVoice.Core * @systemapi - * @since 10 + * @since 10 dynamic + * @since 22 static */ - UNKNOWN_ERROR = -100, + UNKNOWN_ERROR = -100 } /** @@ -817,37 +926,42 @@ declare namespace intelligentVoice { * @enum {number} * @syscap SystemCapability.AI.IntelligentVoice.Core * @systemapi - * @since 12 + * @since 12 dynamic + * @since 22 static */ enum CapturerChannel { /** * Capturer channel 1. * @syscap SystemCapability.AI.IntelligentVoice.Core * @systemapi - * @since 12 + * @since 12 dynamic + * @since 22 static */ CAPTURER_CHANNEL_1 = 0x1 << 0, /** * Capturer channel 2. * @syscap SystemCapability.AI.IntelligentVoice.Core * @systemapi - * @since 12 + * @since 12 dynamic + * @since 22 static */ CAPTURER_CHANNEL_2 = 0x1 << 1, /** * Capturer channel 3. * @syscap SystemCapability.AI.IntelligentVoice.Core * @systemapi - * @since 12 + * @since 12 dynamic + * @since 22 static */ CAPTURER_CHANNEL_3 = 0x1 << 2, /** * Capturer channel 4. * @syscap SystemCapability.AI.IntelligentVoice.Core * @systemapi - * @since 12 + * @since 12 dynamic + * @since 22 static */ - CAPTURER_CHANNEL_4 = 0x1 << 3, + CAPTURER_CHANNEL_4 = 0x1 << 3 } /** @@ -855,7 +969,8 @@ declare namespace intelligentVoice { * @typedef EnrollCallbackInfo * @syscap SystemCapability.AI.IntelligentVoice.Core * @systemapi - * @since 10 + * @since 10 dynamic + * @since 22 static */ interface EnrollCallbackInfo { /** @@ -863,7 +978,8 @@ declare namespace intelligentVoice { * @type { EnrollResult } * @syscap SystemCapability.AI.IntelligentVoice.Core * @systemapi - * @since 10 + * @since 10 dynamic + * @since 22 static */ result: EnrollResult; /** @@ -871,7 +987,8 @@ declare namespace intelligentVoice { * @type { string } * @syscap SystemCapability.AI.IntelligentVoice.Core * @systemapi - * @since 10 + * @since 10 dynamic + * @since 22 static */ context: string; } @@ -881,7 +998,8 @@ declare namespace intelligentVoice { * @typedef WakeupIntelligentVoiceEngineCallbackInfo * @syscap SystemCapability.AI.IntelligentVoice.Core * @systemapi - * @since 10 + * @since 10 dynamic + * @since 22 static */ interface WakeupIntelligentVoiceEngineCallbackInfo { /** @@ -889,7 +1007,8 @@ declare namespace intelligentVoice { * @type { WakeupIntelligentVoiceEventType } * @syscap SystemCapability.AI.IntelligentVoice.Core * @systemapi - * @since 10 + * @since 10 dynamic + * @since 22 static */ eventId: WakeupIntelligentVoiceEventType; /** @@ -897,7 +1016,8 @@ declare namespace intelligentVoice { * @type { boolean } * @syscap SystemCapability.AI.IntelligentVoice.Core * @systemapi - * @since 10 + * @since 10 dynamic + * @since 22 static */ isSuccess: boolean; /** @@ -905,7 +1025,8 @@ declare namespace intelligentVoice { * @type { string } * @syscap SystemCapability.AI.IntelligentVoice.Core * @systemapi - * @since 10 + * @since 10 dynamic + * @since 22 static */ context: string; } @@ -915,7 +1036,8 @@ declare namespace intelligentVoice { * @typedef EnrollIntelligentVoiceEngine * @syscap SystemCapability.AI.IntelligentVoice.Core * @systemapi - * @since 10 + * @since 10 dynamic + * @since 22 static */ interface EnrollIntelligentVoiceEngine { /** @@ -926,7 +1048,8 @@ declare namespace intelligentVoice { * @throws { BusinessError } 202 - Not system application. * @syscap SystemCapability.AI.IntelligentVoice.Core * @systemapi - * @since 10 + * @since 10 dynamic + * @since 22 static */ getSupportedRegions(callback: AsyncCallback>): void; /** @@ -937,7 +1060,8 @@ declare namespace intelligentVoice { * @throws { BusinessError } 202 - Not system application. * @syscap SystemCapability.AI.IntelligentVoice.Core * @systemapi - * @since 10 + * @since 10 dynamic + * @since 22 static */ getSupportedRegions(): Promise>; /** @@ -952,7 +1076,8 @@ declare namespace intelligentVoice { * @throws { BusinessError } 22700103 - Init failed. * @syscap SystemCapability.AI.IntelligentVoice.Core * @systemapi - * @since 10 + * @since 10 dynamic + * @since 22 static */ init(config: EnrollEngineConfig, callback: AsyncCallback): void; /** @@ -967,7 +1092,8 @@ declare namespace intelligentVoice { * @throws { BusinessError } 22700103 - Init failed. * @syscap SystemCapability.AI.IntelligentVoice.Core * @systemapi - * @since 10 + * @since 10 dynamic + * @since 22 static */ init(config: EnrollEngineConfig): Promise; /** @@ -980,7 +1106,20 @@ declare namespace intelligentVoice { * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. * @syscap SystemCapability.AI.IntelligentVoice.Core * @systemapi - * @since 10 + * @since 10 dynamic + */ + /** + * Enrolls for result, This method uses an asynchronous callback to return the result. + * @permission ohos.permission.MANAGE_INTELLIGENT_VOICE and ohos.permission.MICROPHONE + * @param { boolean } isLast - isLast indicates if it is the last time to enroll. + * @param { AsyncCallback } callback - the callback used to return the result. + * @throws { BusinessError } 201 - Permission denied. + * @throws { BusinessError } 202 - Not system application. + * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. + * @throws { BusinessError } 22700107 - System error. + * @syscap SystemCapability.AI.IntelligentVoice.Core + * @systemapi + * @since 22 dynamic&static */ enrollForResult(isLast: boolean, callback: AsyncCallback): void; /** @@ -993,7 +1132,20 @@ declare namespace intelligentVoice { * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. * @syscap SystemCapability.AI.IntelligentVoice.Core * @systemapi - * @since 10 + * @since 10 dynamic + */ + /** + * Enrolls for result, This method uses a promise to return the result. + * @permission ohos.permission.MANAGE_INTELLIGENT_VOICE and ohos.permission.MICROPHONE + * @param { boolean } isLast - isLast indicates if it is the last time to enroll. + * @returns { Promise } the promise used to return the result. + * @throws { BusinessError } 201 - Permission denied. + * @throws { BusinessError } 202 - Not system application. + * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. + * @throws { BusinessError } 22700107 - System error. + * @syscap SystemCapability.AI.IntelligentVoice.Core + * @systemapi + * @since 22 dynamic&static */ enrollForResult(isLast: boolean): Promise; /** @@ -1004,7 +1156,8 @@ declare namespace intelligentVoice { * @throws { BusinessError } 202 - Not system application. * @syscap SystemCapability.AI.IntelligentVoice.Core * @systemapi - * @since 10 + * @since 10 dynamic + * @since 22 static */ stop(callback: AsyncCallback): void; /** @@ -1015,7 +1168,8 @@ declare namespace intelligentVoice { * @throws { BusinessError } 202 - Not system application. * @syscap SystemCapability.AI.IntelligentVoice.Core * @systemapi - * @since 10 + * @since 10 dynamic + * @since 22 static */ stop(): Promise; /** @@ -1027,7 +1181,8 @@ declare namespace intelligentVoice { * @throws { BusinessError } 22700104 - Failed to commit the enrollment. * @syscap SystemCapability.AI.IntelligentVoice.Core * @systemapi - * @since 10 + * @since 10 dynamic + * @since 22 static */ commit(callback: AsyncCallback): void; /** @@ -1039,7 +1194,8 @@ declare namespace intelligentVoice { * @throws { BusinessError } 22700104 - Failed to commit the enrollment. * @syscap SystemCapability.AI.IntelligentVoice.Core * @systemapi - * @since 10 + * @since 10 dynamic + * @since 22 static */ commit(): Promise; /** @@ -1053,7 +1209,8 @@ declare namespace intelligentVoice { * @throws { BusinessError } 22700102 - Invalid parameter. * @syscap SystemCapability.AI.IntelligentVoice.Core * @systemapi - * @since 10 + * @since 10 dynamic + * @since 22 static */ setWakeupHapInfo(info: WakeupHapInfo, callback: AsyncCallback): void; /** @@ -1067,7 +1224,8 @@ declare namespace intelligentVoice { * @throws { BusinessError } 22700102 - Invalid parameter. * @syscap SystemCapability.AI.IntelligentVoice.Core * @systemapi - * @since 10 + * @since 10 dynamic + * @since 22 static */ setWakeupHapInfo(info: WakeupHapInfo): Promise; /** @@ -1081,7 +1239,8 @@ declare namespace intelligentVoice { * @throws { BusinessError } 22700102 - Invalid parameter. * @syscap SystemCapability.AI.IntelligentVoice.Core * @systemapi - * @since 10 + * @since 10 dynamic + * @since 22 static */ setSensibility(sensibility: SensibilityType, callback: AsyncCallback): void; /** @@ -1095,7 +1254,8 @@ declare namespace intelligentVoice { * @throws { BusinessError } 22700102 - Invalid parameter. * @syscap SystemCapability.AI.IntelligentVoice.Core * @systemapi - * @since 10 + * @since 10 dynamic + * @since 22 static */ setSensibility(sensibility: SensibilityType): Promise; /** @@ -1110,7 +1270,8 @@ declare namespace intelligentVoice { * @throws { BusinessError } 22700102 - Invalid parameter. * @syscap SystemCapability.AI.IntelligentVoice.Core * @systemapi - * @since 10 + * @since 10 dynamic + * @since 22 static */ setParameter(key: string, value: string, callback: AsyncCallback): void; /** @@ -1125,7 +1286,8 @@ declare namespace intelligentVoice { * @throws { BusinessError } 22700102 - Invalid parameter. * @syscap SystemCapability.AI.IntelligentVoice.Core * @systemapi - * @since 10 + * @since 10 dynamic + * @since 22 static */ setParameter(key: string, value: string): Promise; /** @@ -1139,7 +1301,8 @@ declare namespace intelligentVoice { * @throws { BusinessError } 22700102 - Invalid parameter. * @syscap SystemCapability.AI.IntelligentVoice.Core * @systemapi - * @since 10 + * @since 10 dynamic + * @since 22 static */ getParameter(key: string, callback: AsyncCallback): void; /** @@ -1153,7 +1316,8 @@ declare namespace intelligentVoice { * @throws { BusinessError } 22700102 - Invalid parameter. * @syscap SystemCapability.AI.IntelligentVoice.Core * @systemapi - * @since 10 + * @since 10 dynamic + * @since 22 static */ getParameter(key: string): Promise; /** @@ -1167,7 +1331,8 @@ declare namespace intelligentVoice { * @throws { BusinessError } 22700107 - System error. * @syscap SystemCapability.AI.IntelligentVoice.Core * @systemapi - * @since 12 + * @since 12 dynamic + * @since 22 static */ evaluateForResult(word: string): Promise; /** @@ -1178,7 +1343,8 @@ declare namespace intelligentVoice { * @throws { BusinessError } 202 - Not system application. * @syscap SystemCapability.AI.IntelligentVoice.Core * @systemapi - * @since 10 + * @since 10 dynamic + * @since 22 static */ release(callback: AsyncCallback): void; /** @@ -1189,7 +1355,8 @@ declare namespace intelligentVoice { * @throws { BusinessError } 202 - Not system application. * @syscap SystemCapability.AI.IntelligentVoice.Core * @systemapi - * @since 10 + * @since 10 dynamic + * @since 22 static */ release(): Promise; } @@ -1199,7 +1366,8 @@ declare namespace intelligentVoice { * @typedef WakeupIntelligentVoiceEngine * @syscap SystemCapability.AI.IntelligentVoice.Core * @systemapi - * @since 10 + * @since 10 dynamic + * @since 22 static */ interface WakeupIntelligentVoiceEngine { /** @@ -1210,7 +1378,8 @@ declare namespace intelligentVoice { * @throws { BusinessError } 202 - Not system application. * @syscap SystemCapability.AI.IntelligentVoice.Core * @systemapi - * @since 10 + * @since 10 dynamic + * @since 22 static */ getSupportedRegions(callback: AsyncCallback>): void; /** @@ -1221,7 +1390,8 @@ declare namespace intelligentVoice { * @throws { BusinessError } 202 - Not system application. * @syscap SystemCapability.AI.IntelligentVoice.Core * @systemapi - * @since 10 + * @since 10 dynamic + * @since 22 static */ getSupportedRegions(): Promise>; /** @@ -1235,7 +1405,8 @@ declare namespace intelligentVoice { * @throws { BusinessError } 22700102 - Invalid parameter. * @syscap SystemCapability.AI.IntelligentVoice.Core * @systemapi - * @since 10 + * @since 10 dynamic + * @since 22 static */ setWakeupHapInfo(info: WakeupHapInfo, callback: AsyncCallback): void; /** @@ -1249,7 +1420,8 @@ declare namespace intelligentVoice { * @throws { BusinessError } 22700102 - Invalid parameter. * @syscap SystemCapability.AI.IntelligentVoice.Core * @systemapi - * @since 10 + * @since 10 dynamic + * @since 22 static */ setWakeupHapInfo(info: WakeupHapInfo): Promise; /** @@ -1263,7 +1435,8 @@ declare namespace intelligentVoice { * @throws { BusinessError } 22700102 - Invalid parameter. * @syscap SystemCapability.AI.IntelligentVoice.Core * @systemapi - * @since 10 + * @since 10 dynamic + * @since 22 static */ setSensibility(sensibility: SensibilityType, callback: AsyncCallback): void; /** @@ -1277,7 +1450,8 @@ declare namespace intelligentVoice { * @throws { BusinessError } 22700102 - Invalid parameter. * @syscap SystemCapability.AI.IntelligentVoice.Core * @systemapi - * @since 10 + * @since 10 dynamic + * @since 22 static */ setSensibility(sensibility: SensibilityType): Promise; /** @@ -1292,7 +1466,8 @@ declare namespace intelligentVoice { * @throws { BusinessError } 22700102 - Invalid parameter. * @syscap SystemCapability.AI.IntelligentVoice.Core * @systemapi - * @since 10 + * @since 10 dynamic + * @since 22 static */ setParameter(key: string, value: string, callback: AsyncCallback): void; /** @@ -1307,7 +1482,8 @@ declare namespace intelligentVoice { * @throws { BusinessError } 22700102 - Invalid parameter. * @syscap SystemCapability.AI.IntelligentVoice.Core * @systemapi - * @since 10 + * @since 10 dynamic + * @since 22 static */ setParameter(key: string, value: string): Promise; /** @@ -1321,7 +1497,8 @@ declare namespace intelligentVoice { * @throws { BusinessError } 22700102 - Invalid parameter. * @syscap SystemCapability.AI.IntelligentVoice.Core * @systemapi - * @since 10 + * @since 10 dynamic + * @since 22 static */ getParameter(key: string, callback: AsyncCallback): void; /** @@ -1335,7 +1512,8 @@ declare namespace intelligentVoice { * @throws { BusinessError } 22700102 - Invalid parameter. * @syscap SystemCapability.AI.IntelligentVoice.Core * @systemapi - * @since 10 + * @since 10 dynamic + * @since 22 static */ getParameter(key: string): Promise; /** @@ -1348,25 +1526,45 @@ declare namespace intelligentVoice { * @throws { BusinessError } 22700107 - System error. * @syscap SystemCapability.AI.IntelligentVoice.Core * @systemapi - * @since 12 + * @since 12 dynamic + * @since 22 static */ getPcm(): Promise; /** * Starts the capturer. This method uses a promise to return the result. * @permission ohos.permission.MANAGE_INTELLIGENT_VOICE - * @param { number } channels - the channels needed in reading. The channels should be greater than 0 and smaller than 16. + * @param { number } channels - the channels needed in reading. The channels should be + * greater than 0 and smaller than 16. * @returns { Promise } the promise used to return the result. * @throws { BusinessError } 201 - Permission denied. * @throws { BusinessError } 202 - Not system application. - * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types. 3.Parameter verification failed. + * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. + * 2. Incorrect parameter types. 3.Parameter verification failed. * @throws { BusinessError } 22700102 - Invalid parameter. * @throws { BusinessError } 22700105 - Start capturer failed. * @throws { BusinessError } 22700107 - System error. * @syscap SystemCapability.AI.IntelligentVoice.Core * @systemapi - * @since 12 + * @since 12 dynamic */ - startCapturer(channels: number): Promise; + /** + * Starts the capturer. This method uses a promise to return the result. + * @permission ohos.permission.MANAGE_INTELLIGENT_VOICE and ohos.permission.MICROPHONE + * @param { int } channels - the channels needed in reading. The channels should be + * greater than 0 and smaller than 16. + * @returns { Promise } the promise used to return the result. + * @throws { BusinessError } 201 - Permission denied. + * @throws { BusinessError } 202 - Not system application. + * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. + * 2. Incorrect parameter types. 3.Parameter verification failed. + * @throws { BusinessError } 22700102 - Invalid parameter. + * @throws { BusinessError } 22700105 - Start capturer failed. + * @throws { BusinessError } 22700107 - System error. + * @syscap SystemCapability.AI.IntelligentVoice.Core + * @systemapi + * @since 22 dynamic&static + */ + startCapturer(channels: int): Promise; /** * Reads the buffer from wakeup engine. This method uses a promise to return the result. * @permission ohos.permission.MANAGE_INTELLIGENT_VOICE @@ -1378,7 +1576,8 @@ declare namespace intelligentVoice { * @throws { BusinessError } 22700107 - System error. * @syscap SystemCapability.AI.IntelligentVoice.Core * @systemapi - * @since 12 + * @since 12 dynamic + * @since 22 static */ read(): Promise; /** @@ -1390,7 +1589,8 @@ declare namespace intelligentVoice { * @throws { BusinessError } 22700107 - System error. * @syscap SystemCapability.AI.IntelligentVoice.Core * @systemapi - * @since 12 + * @since 12 dynamic + * @since 22 static */ stopCapturer(): Promise; /** @@ -1401,7 +1601,8 @@ declare namespace intelligentVoice { * @throws { BusinessError } 202 - Not system application. * @syscap SystemCapability.AI.IntelligentVoice.Core * @systemapi - * @since 10 + * @since 10 dynamic + * @since 22 static */ release(callback: AsyncCallback): void; /** @@ -1412,34 +1613,64 @@ declare namespace intelligentVoice { * @throws { BusinessError } 202 - Not system application. * @syscap SystemCapability.AI.IntelligentVoice.Core * @systemapi - * @since 10 + * @since 10 dynamic + * @since 22 static */ release(): Promise; /** * Subscribes wakeup intelligent voice events. When wakeup intelligent voice events reach, * the callback is invoked. * @permission ohos.permission.MANAGE_INTELLIGENT_VOICE - * @param { 'wakeupIntelligentVoiceEvent' } type - Type of the event to listen for. Only the wakeupIntelligentVoice event is supported. - * @param { Callback } callback - the callback invoked when the event is triggered. + * @param { 'wakeupIntelligentVoiceEvent' } type - Type of the event to listen for. + * Only the wakeupIntelligentVoice event is supported. + * @param { Callback } callback + * - the callback invoked when the event is triggered. * @throws { BusinessError } 201 - Permission denied. * @throws { BusinessError } 202 - Not system application. * @syscap SystemCapability.AI.IntelligentVoice.Core * @systemapi - * @since 10 + * @since 10 dynamic */ on(type: 'wakeupIntelligentVoiceEvent', callback: Callback): void; /** - * Unsubscribes wakeup intelligent voice events. + * Subscribes wakeup intelligent voice events. When wakeup intelligent voice events reach, + * the callback is invoked. * @permission ohos.permission.MANAGE_INTELLIGENT_VOICE - * @param { 'wakeupIntelligentVoiceEvent' } type - Type of the event to listen for. Only the wakeupIntelligentVoice event is supported. - * @param { Callback } [callback] - the callback invoked when the event is triggered. + * @param { Callback } callback + * - the callback invoked when the event is triggered. * @throws { BusinessError } 201 - Permission denied. * @throws { BusinessError } 202 - Not system application. * @syscap SystemCapability.AI.IntelligentVoice.Core * @systemapi - * @since 10 + * @since 22 static + */ + onWakeupIntelligentVoiceEvent(callback: Callback): void; + /** + * Unsubscribes wakeup intelligent voice events. + * @permission ohos.permission.MANAGE_INTELLIGENT_VOICE + * @param { 'wakeupIntelligentVoiceEvent' } type - Type of the event to listen for. + * Only the wakeupIntelligentVoice event is supported. + * @param { Callback } [callback] + * - the callback invoked when the event is triggered. + * @throws { BusinessError } 201 - Permission denied. + * @throws { BusinessError } 202 - Not system application. + * @syscap SystemCapability.AI.IntelligentVoice.Core + * @systemapi + * @since 10 dynamic */ off(type: 'wakeupIntelligentVoiceEvent', callback?: Callback): void; + /** + * Unsubscribes wakeup intelligent voice events. + * @permission ohos.permission.MANAGE_INTELLIGENT_VOICE + * @param { Callback } [callback] + * - the callback invoked when the event is triggered. + * @throws { BusinessError } 201 - Permission denied. + * @throws { BusinessError } 202 - Not system application. + * @syscap SystemCapability.AI.IntelligentVoice.Core + * @systemapi + * @since 22 static + */ + offWakeupIntelligentVoiceEvent(callback?: Callback): void; } }