diff --git a/LICENSE b/LICENSE
new file mode 100755
index 0000000..4947287
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,177 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
\ No newline at end of file
diff --git a/OAT.xml b/OAT.xml
new file mode 100755
index 0000000..d298c05
--- /dev/null
+++ b/OAT.xml
@@ -0,0 +1,64 @@
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/README_zh.md b/README_zh.md
new file mode 100755
index 0000000..64b2e18
--- /dev/null
+++ b/README_zh.md
@@ -0,0 +1,195 @@
+# 智能语音组件
+
+## 概述
+
+### 功能简介
+
+智能语音组件包括智能语音服务框架和智能语音驱动,主要实现了语音注册及语音唤醒相关功能。
+
+**图 1** 智能语音组件架构图
+
+
+
+智能语音服务框架支持如下功能:
+系统事件监测:开机解锁、亮灭屏等系统事件监测
+并发策略:智能语音业务并发管理
+智能语音业务:语音注册、语音唤醒等智能语音业务处理
+声音触发器:DSP模型加载、DSP算法启停、DSP事件处理
+
+智能语音驱动支持如下功能:
+引擎算法:智能语音算法引擎以及事件上报
+设备驱动:DSP模型加载卸载、算法启停、事件上报以及硬件相关通路配置
+
+### 基本概念
+- 语音注册:将用户说的唤醒词转换为声学模型以及声纹特征,以便后续的语音唤醒。
+- 语音唤醒:判断当前说话人是否为已注册的特定用户。
+- DSP:数字信号处理器(Digital Signal Processors),DSP芯片即指能够实现数字信号处理技术的芯片。
+
+### 目录结构
+
+仓目录结构如下:
+
+```shell
+/foundation/ai/intelligent_voice_framework # 智能音频组件业务代码
+├── frameworks # 框架代码
+│ ├── native # 内部接口实现
+│ └── js # 外部接口实现
+├── interfaces # 接口代码
+│ ├── inner_api # 内部接口
+│ └── kits # 外部接口
+├── sa_profile # 服务配置文件
+├── services # 服务代码
+├── LICENSE # 证书文件
+├── tests # 开发者测试
+└── utils # 公共函数
+```
+
+### 约束与限制
+
+- 智能语音服务当前只支持一个唤醒词的注册以及唤醒。
+
+
+## 接口说明
+### 语音注册接口说明
+
+|接口名称|接口描述|
+|---|---|
+|createEnrollIntelligentVoiceEngine(descriptor: EnrollIntelligentVoiceEngineDescriptor): EnrollIntelligentVoiceEngine|创建注册引擎。|
+|init(config: EnrollEngineConfig): EnrollIntelligentVoiceEngineCallbackInfo|初始化注册引擎。|
+|start(isLast: boolean): EnrollIntelligentVoiceEngineCallbackInfo|启动注册。|
+|stop(): void|停止注册。|
+|commit(): EnrollIntelligentVoiceEngineCallbackInfo|确认注册结果。|
+|setWakeupHapInfo(info: WakeupHapInfo): void|设置唤醒应用信息。|
+|setSensibility(sensibility: SensibilityType): void|设置灵敏度。|
+|release(): void|释放注册引擎。|
+
+### 语音唤醒接口说明
+
+|接口名称|接口描述|
+|---|---|
+|createWakeupIntelligentVoiceEngine(descriptor: WakeupIntelligentVoiceEngineDescriptor): WakeupIntelligentVoiceEngine|创建唤醒引擎。|
+|setWakeupHapInfo(info: WakeupHapInfo): void|设置唤醒应用信息。|
+|setSensibility(sensibility: SensibilityType): void|设置灵敏度。|
+|on(type: 'wakeupIntelligentVoiceEvent', callback: Callback): void|订阅唤醒事件。|
+|release(): void|释放唤醒引擎。|
+
+
+## 开发实例
+
+### 语音注册
+
+语音注册流程是用户通过应用的注册界面主动发起的交互流程,主要流程如下:
+1. 用户启动注册(创建注册引擎并初始化注册引擎)后,进入注册界面。
+2. 界面提示用户说出唤醒词,用户根据提示说出相应唤醒词(启动注册),界面会让用户再次重复说出唤醒词,直到最后一次。
+3. 注册完成(确认注册结果)后,注册流程全部完成。
+示例代码如下:
+
+```js
+// 引入智能音频
+import intelligentVoice from '@ohos.ai.intelligentVoice';
+
+// 获取智能音频管理服务
+var manager = intellVoice.getIntelligentVoiceManager();
+if (manager == null) {
+ console.error("Get IntelligentVoiceManager failed.");
+} else {
+ console.info("Get IntelligentVoiceManager success.");
+ return;
+}
+
+// 创建注册引擎
+var engine = null;
+let engineDescriptor = {
+ wakeupPhrase: '', // 设置唤醒词
+}
+await intellVoice.createEnrollIntelligentVoiceEngine(engineDescriptor).then((data) => {
+ engine = data;
+ console.info('Create EnrollIntelligentVoice Engine finish');
+}).catch((err) => {
+ console.error('Create EnrollIntelligentVoice Engine failed, err: ' + err.message);
+});
+if (engine == null) {
+ console.error('Create EnrollIntelligentVoice Engine failed');
+ return;
+}
+
+// 初始化注册引擎
+let config = {
+ language: "zh", // 中文
+ area: "CN", // 中国
+}
+engine.init(config).then((data) => {
+ console.info('Init EnrollIntelligentVoice Engine finish');
+}).catch((err) => {
+ console.info('Init EnrollIntelligentVoice Engine failed, err: '+ err.message);
+});
+
+// 启动注册
+let isLast = true; // true: 最后一次启动,false: 非最后一次启动,实例为true
+engine.start(isLast).then((data) => {
+ console.info('Start enrollment finish');
+}).catch((err) => {
+ console.info('Start enrollment failed, err: '+ err.message);
+});
+
+// 确认注册结果
+engine.commit().then((data) => {
+ console.info('Commit enroll result finish');
+}).catch((err) => {
+ console.info('Commit enroll result failed, err: '+ err.message);
+});
+
+// 下发语音唤醒应用信息
+let info = {
+ bundleName: "demo", // 应用的bundle name,demo只是个参考例子,具体填写由应用确定
+ abilityName: "demo", // 应用的ability name,demo只是个参考例子,具体填写由应用确定
+}
+engine.setWakeupHapInfo(info).then((data) => {
+ console.info('Set wakeup hap info finish');
+}).catch((err) => {
+ console.info('Set wakeup hap info failed, err: '+ err.message);
+});
+
+// 释放注册引擎
+engine.release().then((data) => {
+ console.info('Release EnrollIntelligentVoice engine success.');
+}).catch((err) => {
+ console.info('Release EnrollIntelligentVoice engine failed, err: '+ err.message);
+});
+```
+
+### 语音唤醒
+
+语言唤醒由智能语音组件控制,上层应用只需要调用`createWakeupIntelligentVoiceEngine`获取唤醒引擎后注册唤醒事件回调即可。
+
+```js
+// 获取唤醒引擎
+var engine = null;
+let engineDescriptor = {
+ needApAlgEngine: true, // 是否需要框架提供ap侧算法引擎
+ wakeupPhrase: '', // 设置唤醒词
+}
+await intellVoice.createWakeupIntelligentVoiceEngine(engineDescriptor).then((data) => {
+ engine = data;
+ console.info('Create WakeupIntelligentVoice Engine finish');
+}).catch((err) => {
+ console.error('Create WakeupIntelligentVoice Engine failed, err: ' + err.message);
+});
+if (engine == null) {
+ console.error('Create WakeupIntelligentVoice Engine failed');
+ return;
+}
+
+// 注册事件回调
+engine.on('wakeupIntelligentVoiceEvent',(callback) => {
+ console.info('wakeupIntelligentVoiceEvent CallBackInfo:')
+ for (let prop in callback) {
+ console.info('wakeupIntelligentVoiceEvent prop: ' + prop);
+ console.info('wakeupIntelligentVoiceEvent value: ' + callback[prop]);
+ }
+});
+```
+
+## 相关仓
+
+intelligent_voice_framework
diff --git a/bundle.json b/bundle.json
new file mode 100755
index 0000000..3963be1
--- /dev/null
+++ b/bundle.json
@@ -0,0 +1,57 @@
+{
+ "name": "@ohos/intelligent_voice_framework",
+ "description": "intelligent_voice framework",
+ "version": "1.0",
+ "license": "Apache License 2.0",
+ "publishAs": "code-segment",
+ "segment": {
+ "destPath": "foundation/ai/intelligent_voice_framework"
+ },
+ "component": {
+ "name": "intelligent_voice_framework",
+ "subsystem": "ai",
+ "syscap": [
+ "SystemCapability.AI.IntelligentVoice.Core"
+ ],
+ "adapter_system_type": ["standard"],
+ "rom": "",
+ "ram": "",
+ "deps": {
+ "components": ["intelligent_voice_framework"],
+ "third_party": []
+ },
+ "features": [
+ ],
+ "build": {
+ "sub_component": [
+ "//foundation/ai/intelligent_voice_framework/services:intell_voice_server",
+ "//foundation/ai/intelligent_voice_framework/services:intell_voice_proxy",
+ "//foundation/ai/intelligent_voice_framework/services/etc:intell_voice_service.rc",
+ "//foundation/ai/intelligent_voice_framework/frameworks/js:intelligentvoice",
+ "//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"
+ ],
+ "inner_kits": [
+ {
+ "type": "none",
+ "name": "//foundation/ai/intelligent_voice_framework/frameworks/js:intelligentvoice_js",
+ "header": {
+ "header_files": [
+ "intell_voice_manager_napi.h",
+ "intell_voice_engine_napi.h",
+ "enroll_intell_voice_engine_napi.h"
+ ],
+ "header_base": [
+ "//foundation/ai/intelligent_voice_framework/frameworks/js/napi/include"
+ ]
+ }
+ }
+ ],
+ "test": [
+ "//foundation/ai/intelligent_voice_framework/tests:intell_voice_unit_test",
+ "//foundation/ai/intelligent_voice_framework/tests:intell_voice_fuzz_test"
+ ]
+ }
+ }
+}
diff --git a/figures/intelligent-voice-framework.png b/figures/intelligent-voice-framework.png
new file mode 100755
index 0000000..d176720
Binary files /dev/null and b/figures/intelligent-voice-framework.png differ
diff --git a/frameworks/js/BUILD.gn b/frameworks/js/BUILD.gn
new file mode 100755
index 0000000..be6b399
--- /dev/null
+++ b/frameworks/js/BUILD.gn
@@ -0,0 +1,73 @@
+# Copyright (c) 2023 Huawei Device Co., Ltd.
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import("//build/ohos.gni")
+import("//build/ohos/ace/ace.gni")
+
+js_declaration("intelligentvoice_js") {
+ part_name = "intelligent_voice_framework"
+ sources = [ "//foundation/ai/intelligent_voice_framework/interfaces/kits/js/@ohos.ai.intelligentVoice.d.ts" ]
+}
+
+ohos_copy("intelligentvoice_declaration") {
+ sources = [ "//foundation/ai/intelligent_voice_framework/interfaces/kits/js/@ohos.ai.intelligentVoice.d.ts" ]
+ outputs = [ target_out_dir + "/$target_name/" ]
+ module_source_dir = target_out_dir + "/$target_name"
+ module_install_name = ""
+}
+
+ohos_shared_library("intelligentvoice") {
+ sources = [
+ "napi/engine_event_callback_napi.cpp",
+ "napi/enroll_intell_voice_engine_callback_napi.cpp",
+ "napi/enroll_intell_voice_engine_napi.cpp",
+ "napi/intell_voice_manager_napi.cpp",
+ "napi/intell_voice_napi_queue.cpp",
+ "napi/intell_voice_napi_util.cpp",
+ "napi/wakeup_intell_voice_engine_napi.cpp",
+ ]
+
+ include_dirs = [
+ "//foundation/arkui/napi/interfaces/kits",
+ "//foundation/ai/intelligent_voice_framework/interfaces/inner_api/native",
+ "//foundation/ai/intelligent_voice_framework/services/intell_voice_engine",
+ "//foundation/ai/intelligent_voice_framework/services/intell_voice_engine/proxy",
+ "//foundation/ai/intelligent_voice_framework/utils",
+ "napi",
+ ]
+
+ cflags_cc = [
+ "-Wno-error=unused-parameter",
+ "-DHILOG_ENABLE",
+ "-DENABLE_DEBUG",
+ ]
+
+ deps = [
+ "//foundation/ai/intelligent_voice_framework/frameworks/native:intellvoice_native",
+ "//foundation/ai/intelligent_voice_framework/services:intell_voice_proxy",
+ "//foundation/arkui/napi:ace_napi",
+ ]
+
+ external_deps = [
+ "ability_base:want",
+ "c_utils:utils",
+ "hiviewdfx_hilog_native:libhilog",
+ "ipc:ipc_core",
+ "safwk:system_ability_fwk",
+ "samgr:samgr_proxy",
+ ]
+
+ relative_install_dir = "module/ai"
+ subsystem_name = "ai"
+ part_name = "intelligent_voice_framework"
+}
diff --git a/frameworks/js/napi/engine_event_callback_napi.cpp b/frameworks/js/napi/engine_event_callback_napi.cpp
new file mode 100755
index 0000000..e0683b2
--- /dev/null
+++ b/frameworks/js/napi/engine_event_callback_napi.cpp
@@ -0,0 +1,118 @@
+/*
+ * Copyright (c) 2023 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "engine_event_callback_napi.h"
+#include
+#include "intell_voice_log.h"
+
+using namespace std;
+using namespace OHOS::IntellVoiceEngine;
+#define LOG_TAG "EngineEventCallbackNapi"
+
+namespace OHOS {
+namespace IntellVoiceNapi {
+EngineEventCallbackNapi::EngineEventCallbackNapi(napi_env env, napi_value callback)
+{
+ INTELL_VOICE_LOG_INFO("enter");
+ env_ = env;
+ if (env_ != nullptr) {
+ napi_get_uv_event_loop(env_, &loop_);
+ }
+ callbackRef_ = make_shared(env_, callback);
+}
+
+EngineEventCallbackNapi::~EngineEventCallbackNapi()
+{
+ INTELL_VOICE_LOG_INFO("enter");
+ callbackRef_ = nullptr;
+}
+
+void EngineEventCallbackNapi::OnEvent(const IntellVoiceEngineCallBackEvent &event)
+{
+ INTELL_VOICE_LOG_INFO("enter");
+ if (callbackRef_ == nullptr) {
+ INTELL_VOICE_LOG_ERROR("Failed to get engine event callback");
+ return;
+ }
+
+ EngineCallBackInfo cbInfo = {event.msgId, event.result, event.info};
+
+ INTELL_VOICE_LOG_INFO("OnEvent EngineCallBackInfo: msgId: %{public}d, errCode: %{public}d, context: %{public}s",
+ cbInfo.msgId,
+ cbInfo.errCode,
+ cbInfo.context.c_str());
+
+ return OnEventUvCallback(cbInfo);
+}
+
+void EngineEventCallbackNapi::OnEventUvCallback(EngineCallBackInfo &cbInfo)
+{
+ CHECK_RETURN_VOID(loop_ != nullptr, "loop is nullptr");
+ uv_work_t *work = new (nothrow) uv_work_t;
+ CHECK_RETURN_VOID(work != nullptr, "Create uv work failed, no memory");
+
+ work->data = new EngineEventUvCallback {env_, cbInfo, callbackRef_};
+
+ uv_queue_work(
+ loop_,
+ work,
+ [](uv_work_t *work) {},
+ [](uv_work_t *work, int uvStatus) {
+ shared_ptr uvCallback(
+ static_cast(work->data), [work](EngineEventUvCallback *data) {
+ delete data;
+ delete work;
+ });
+ CHECK_RETURN_VOID(uvCallback != nullptr, "uvCallback is nullptr");
+ CHECK_RETURN_VOID(uvCallback->callback != nullptr, "uvCallback callback is nullptr");
+ napi_env env = uvCallback->env_;
+ INTELL_VOICE_LOG_INFO("uv_queue_work start");
+
+ napi_value jsCallback = uvCallback->callback->GetRefValue();
+ if (jsCallback == nullptr) {
+ INTELL_VOICE_LOG_ERROR("get reference value fail");
+ return;
+ }
+
+ const size_t argc = 1;
+ napi_value args[argc] = {nullptr};
+ GetJsCallbackInfo(env, uvCallback->cbInfo, args[0]);
+ if (args[0] == nullptr) {
+ INTELL_VOICE_LOG_ERROR("failed to create engine event callback");
+ return;
+ }
+
+ napi_value result = nullptr;
+ napi_status status = napi_call_function(env, nullptr, jsCallback, argc, args, &result);
+ if (status != napi_ok) {
+ INTELL_VOICE_LOG_ERROR("failed to call engine event callback, error: %{public}d", status);
+ }
+ });
+}
+
+void GetJsCallbackInfo(const napi_env &env, const EngineCallBackInfo &callbackInfo, napi_value &jsObj)
+{
+ napi_status status = napi_create_object(env, &jsObj);
+ if (status != napi_ok || jsObj == nullptr) {
+ INTELL_VOICE_LOG_ERROR("failed to create js callbackInfo, error: %{public}d", status);
+ return;
+ }
+
+ napi_set_named_property(env, jsObj, "msgId", SetValue(env, callbackInfo.msgId));
+ napi_set_named_property(env, jsObj, "errCode", SetValue(env, callbackInfo.errCode));
+ napi_set_named_property(env, jsObj, "context", SetValue(env, callbackInfo.context));
+}
+} // namespace IntellVoiceNapi
+} // namespace OHOS
\ No newline at end of file
diff --git a/frameworks/js/napi/engine_event_callback_napi.h b/frameworks/js/napi/engine_event_callback_napi.h
new file mode 100755
index 0000000..145662d
--- /dev/null
+++ b/frameworks/js/napi/engine_event_callback_napi.h
@@ -0,0 +1,59 @@
+/*
+ * Copyright (c) 2023 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef ENGINE_EVENT_CALLBACK_H
+#define ENGINE_EVENT_CALLBACK_H
+
+#include "napi/native_api.h"
+#include "napi/native_node_api.h"
+#include "intell_voice_napi_util.h"
+#include "i_intell_voice_engine_callback.h"
+
+namespace OHOS {
+namespace IntellVoiceNapi {
+using OHOS::IntellVoiceEngine::IIntellVoiceEngineEventCallback;
+using OHOS::IntellVoiceEngine::IntellVoiceEngineCallBackEvent;
+
+struct EngineCallBackInfo {
+ int32_t msgId;
+ int32_t errCode;
+ std::string context;
+};
+
+class EngineEventCallbackNapi : public IIntellVoiceEngineEventCallback {
+public:
+ explicit EngineEventCallbackNapi(napi_env env, napi_value callback);
+ virtual ~EngineEventCallbackNapi();
+
+ void OnEvent(const IntellVoiceEngineCallBackEvent &event) override;
+
+private:
+ struct EngineEventUvCallback {
+ napi_env env_ = nullptr;
+ EngineCallBackInfo cbInfo;
+ std::shared_ptr callback;
+ };
+
+ void OnEventUvCallback(EngineCallBackInfo &cbInfo);
+
+ napi_env env_ = nullptr;
+ uv_loop_s *loop_ = nullptr;
+ std::shared_ptr callbackRef_ = nullptr;
+};
+
+void GetJsCallbackInfo(const napi_env &env, const EngineCallBackInfo &callbackInfo, napi_value &jsObj);
+} // namespace IntellVoiceNapi
+} // namespace OHOS
+#endif
diff --git a/frameworks/js/napi/enroll_intell_voice_engine_callback_napi.cpp b/frameworks/js/napi/enroll_intell_voice_engine_callback_napi.cpp
new file mode 100755
index 0000000..53c63f6
--- /dev/null
+++ b/frameworks/js/napi/enroll_intell_voice_engine_callback_napi.cpp
@@ -0,0 +1,152 @@
+/*
+ * Copyright (c) 2023 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "enroll_intell_voice_engine_callback_napi.h"
+#include "intell_voice_log.h"
+
+using namespace std;
+using namespace OHOS::IntellVoiceEngine;
+#define LOG_TAG "EnrollIntellVoiceEngineCallbackNapi"
+
+namespace OHOS {
+namespace IntellVoiceNapi {
+void EnrollIntellVoiceEngineCallBackInfo::GetCallBackInfoNapiValue(const napi_env &env, napi_value &result)
+{
+ napi_status status = napi_create_object(env, &result);
+ if (status != napi_ok || result == nullptr) {
+ INTELL_VOICE_LOG_ERROR("failed to create js callbackInfo, error: %{public}d", status);
+ return;
+ }
+
+ napi_set_named_property(env, result, "eventId", SetValue(env, eventId));
+ napi_set_named_property(env, result, "errCode", SetValue(env, errCode));
+ napi_set_named_property(env, result, "context", SetValue(env, context));
+}
+
+EnrollIntellVoiceEngineCallbackNapi::EnrollIntellVoiceEngineCallbackNapi(const napi_env env)
+{
+ env_ = env;
+ contextMap_.clear();
+}
+
+EnrollIntellVoiceEngineCallbackNapi::~EnrollIntellVoiceEngineCallbackNapi()
+{
+ contextMap_.clear();
+}
+
+void EnrollIntellVoiceEngineCallbackNapi::QueueAsyncWork(EnrollAsyncContext *context)
+{
+ std::lock_guard lock(mutex_);
+ if (contextMap_.find(context->type) == contextMap_.end()) {
+ std::queue contextQue;
+ contextQue.push(context);
+ contextMap_[context->type] = contextQue;
+ } else {
+ contextMap_.at(context->type).push(context);
+ }
+}
+
+void EnrollIntellVoiceEngineCallbackNapi::ClearAsyncWork(bool error, const std::string &msg)
+{
+ INTELL_VOICE_LOG_INFO("%{public}s", msg.c_str());
+ std::lock_guard lock(mutex_);
+ for (auto it = contextMap_.begin(); it != contextMap_.end(); it++) {
+ auto &contextQue = it->second;
+ while (!contextQue.empty()) {
+ EnrollAsyncContext *context = contextQue.front();
+ contextQue.pop();
+ if (error) {
+ INTELL_VOICE_LOG_WARN("error occured");
+ }
+ OnJsCallBack(context);
+ }
+ }
+ contextMap_.clear();
+}
+
+void EnrollIntellVoiceEngineCallbackNapi::OnEvent(const IntellVoiceEngineCallBackEvent &event)
+{
+ INTELL_VOICE_LOG_INFO("OnEvent: msgId: %{public}d, errCode: %{public}d, context: %{public}s",
+ event.msgId,
+ event.result,
+ event.info.c_str());
+ EnrollAsyncWorkType asyncType = ASYNC_WORK_INVALID;
+ switch (event.msgId) {
+ case HDI::IntelligentVoice::Engine::V1_0::INTELL_VOICE_ENGINE_MSG_INIT_DONE:
+ asyncType = ASYNC_WORK_INIT;
+ break;
+ case HDI::IntelligentVoice::Engine::V1_0::INTELL_VOICE_ENGINE_MSG_ENROLL_COMPLETE:
+ asyncType = ASYNC_WORK_START;
+ break;
+ case HDI::IntelligentVoice::Engine::V1_0::INTELL_VOICE_ENGINE_MSG_COMMIT_ENROLL_COMPLETE:
+ asyncType = ASYNC_WORK_COMMIT;
+ break;
+ default:
+ break;
+ }
+ if (contextMap_.find(asyncType) == contextMap_.end() || contextMap_.at(asyncType).empty()) {
+ INTELL_VOICE_LOG_ERROR("callback is called, But context is empty");
+ return;
+ }
+
+ EnrollAsyncContext *context = contextMap_.at(asyncType).front();
+ if (context == nullptr) {
+ INTELL_VOICE_LOG_ERROR("context is nullptr");
+ return;
+ }
+ contextMap_.at(asyncType).pop();
+
+ context->callbackInfo = {event.msgId, event.result, event.info};
+ OnJsCallBack(context);
+}
+
+void EnrollIntellVoiceEngineCallbackNapi::UvWorkCallBack(uv_work_t *work, int status)
+{
+ INTELL_VOICE_LOG_INFO("enter");
+ auto asyncContext = reinterpret_cast(work->data);
+ napi_value result = nullptr;
+ if (asyncContext != nullptr) {
+ napi_env env = asyncContext->env_;
+ asyncContext->callbackInfo.GetCallBackInfoNapiValue(env, result);
+ NapiAsync::CommonCallbackRoutine(asyncContext, result);
+ }
+ delete work;
+}
+
+void EnrollIntellVoiceEngineCallbackNapi::OnJsCallBack(EnrollAsyncContext *context)
+{
+ INTELL_VOICE_LOG_INFO("enter");
+ uv_loop_s *loop = nullptr;
+ napi_get_uv_event_loop(env_, &loop);
+ if (loop != nullptr) {
+ uv_work_t *work = new (std::nothrow) uv_work_t;
+ if (work != nullptr) {
+ work->data = reinterpret_cast(context);
+ int ret = uv_queue_work(
+ loop, work, [](uv_work_t *work) {}, UvWorkCallBack);
+ if (ret != 0) {
+ INTELL_VOICE_LOG_INFO("Failed to execute libuv work queue");
+ delete context;
+ delete work;
+ }
+ } else {
+ delete context;
+ }
+ } else {
+ delete context;
+ }
+}
+} // namespace IntellVoiceNapi
+} // namespace OHOS
\ No newline at end of file
diff --git a/frameworks/js/napi/enroll_intell_voice_engine_callback_napi.h b/frameworks/js/napi/enroll_intell_voice_engine_callback_napi.h
new file mode 100755
index 0000000..0ffd197
--- /dev/null
+++ b/frameworks/js/napi/enroll_intell_voice_engine_callback_napi.h
@@ -0,0 +1,78 @@
+/*
+ * Copyright (c) 2023 Huawei Device Co., Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef ENROLL_INTELL_VOICE_ENGINE_CALLBACK_NAPI_H
+#define ENROLL_INTELL_VOICE_ENGINE_CALLBACK_NAPI_H
+
+#include
+#include