@ohos.ai.intelligentVoice (智能语音)(系统接口)

智能语音主要提供了语音注册及语音唤醒相关功能。

该模块提供以下智能语音相关的常用功能:

  • IntelligentVoiceManager:智能语音管理类,明确当前智能语音提供的相关功能,当前支持语音注册、语音唤醒。在进行智能语音相关开发前,需先调用getIntelligentVoiceManager()确认当前支持智能语音的相关功能,再进行语音注册和语音唤醒的相关开发。
  • EnrollIntelligentVoiceEngine:实现语音注册。开发者需要先进行智能语音的注册,然后才能进行唤醒。
  • WakeupIntelligentVoiceEngine:实现语音唤醒。开发者需要先进行智能语音的注册,然后才能进行唤醒。

说明:

  • 本模块首批接口从API version 10开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。

  • 本模块接口为系统接口。

导入模块

import intelligentVoice from '@ohos.ai.intelligentVoice';

intelligentVoice.getIntelligentVoiceManager

getIntelligentVoiceManager(): IntelligentVoiceManager

获取智能语音管理类。

需要权限: ohos.permission.MANAGE_INTELLIGENT_VOICE

系统能力: SystemCapability.AI.IntelligentVoice.Core

返回值:

类型 说明
IntelligentVoiceManager 智能语音管理类。

错误码:

以下错误码的详细介绍请参见智能语音错误码

错误码ID 错误信息
22700101 No memory.

示例:

import { BusinessError } from '@ohos.base';

let intelligentVoiceManager: intelligentVoice.IntelligentVoiceManager | null = null;
try {
  intelligentVoiceManager = intelligentVoice.getIntelligentVoiceManager();
} catch (err) {
  let error = err as BusinessError;
  console.error(`Get IntelligentVoiceManager failed. Code:${error.code}, message:${error.message}`);
}

intelligentVoice.createEnrollIntelligentVoiceEngine

createEnrollIntelligentVoiceEngine(descriptor: EnrollIntelligentVoiceEngineDescriptor, callback: AsyncCallback<EnrollIntelligentVoiceEngine>): void

创建智能语音注册引擎实例,使用callback异步回调。

需要权限: ohos.permission.MANAGE_INTELLIGENT_VOICE

系统能力: SystemCapability.AI.IntelligentVoice.Core

参数:

参数名 类型 必填 说明
descriptor EnrollIntelligentVoiceEngineDescriptor 智能语音注册引擎描述符。
callback AsyncCallback<EnrollIntelligentVoiceEngine> 返回注册智能语音引擎。

错误码:

以下错误码的详细介绍请参见智能语音错误码

错误码ID 错误信息
22700101 No memory.
22700102 Input parameter value error.

示例:

import { BusinessError } from '@ohos.base';

let engineDescriptor: intelligentVoice.EnrollIntelligentVoiceEngineDescriptor = {
  wakeupPhrase: '小华小华',
}
let enrollIntelligentVoiceEngine: intelligentVoice.EnrollIntelligentVoiceEngine | null = null;
intelligentVoice.createEnrollIntelligentVoiceEngine(engineDescriptor, (err: BusinessError, data: intelligentVoice.EnrollIntelligentVoiceEngine) => {
  if (err) {
    console.error(`Failed to create enrollIntelligentVoice engine, Code:${err.code}, message:${err.message}`);
  } else {
    console.info(`Succeeded in creating enrollIntelligentVoice engine.`);
    enrollIntelligentVoiceEngine = data;
  }
});

intelligentVoice.createEnrollIntelligentVoiceEngine

createEnrollIntelligentVoiceEngine(descriptor: EnrollIntelligentVoiceEngineDescriptor): Promise<EnrollIntelligentVoiceEngine>

创建智能语音注册引擎实例,使用Promise异步回调。

需要权限: ohos.permission.MANAGE_INTELLIGENT_VOICE

系统能力: SystemCapability.AI.IntelligentVoice.Core

参数:

参数名 类型 必填 说明
descriptor EnrollIntelligentVoiceEngineDescriptor 智能语音注册引擎描述符。

返回值:

类型 说明
Promise<EnrollIntelligentVoiceEngine> 返回注册智能语音引擎。

错误码:

以下错误码的详细介绍请参见智能语音错误码

错误码ID 错误信息
22700101 No memory.
22700102 Input parameter value error.

示例:

import { BusinessError } from '@ohos.base';

let engineDescriptor: intelligentVoice.EnrollIntelligentVoiceEngineDescriptor = {
  wakeupPhrase: '小华小华',
}
let enrollIntelligentVoiceEngine: intelligentVoice.EnrollIntelligentVoiceEngine | null = null;
intelligentVoice.createEnrollIntelligentVoiceEngine(engineDescriptor).then((data: intelligentVoice.EnrollIntelligentVoiceEngine) => {
  enrollIntelligentVoiceEngine = data;
  console.info(`Succeeded in creating enrollIntelligentVoice engine.`);
}).catch((err: BusinessError) => {
  console.error(`Failed to create enrollIntelligentVoice engine, Code:${err.code}, message:${err.message}`);
});

intelligentVoice.createWakeupIntelligentVoiceEngine

createWakeupIntelligentVoiceEngine(descriptor: WakeupIntelligentVoiceEngineDescriptor, callback: AsyncCallback<WakeupIntelligentVoiceEngine>): void

创建智能语音唤醒引擎实例,使用callback异步回调。

需要权限: ohos.permission.MANAGE_INTELLIGENT_VOICE

系统能力: SystemCapability.AI.IntelligentVoice.Core

参数:

参数名 类型 必填 说明
descriptor WakeupIntelligentVoiceEngineDescriptor 唤醒智能语音引擎描述符。
callback AsyncCallback<WakeupIntelligentVoiceEngine> 返回唤醒智能语音引擎。

错误码:

以下错误码的详细介绍请参见智能语音错误码

错误码ID 错误信息
22700101 No memory.
22700102 Input parameter value error.

示例:

import { BusinessError } from '@ohos.base';

let wakeupEngineDescriptor: intelligentVoice.WakeupIntelligentVoiceEngineDescriptor = {
  needReconfirm: true,
  wakeupPhrase: '小华小华',
}
let wakeupIntelligentVoiceEngine: intelligentVoice.WakeupIntelligentVoiceEngine | null = null;
intelligentVoice.createWakeupIntelligentVoiceEngine(wakeupEngineDescriptor, (err: BusinessError, data: intelligentVoice.WakeupIntelligentVoiceEngine) => {
  if (err) {
    console.error(`Failed to create wakeupIntelligentVoice engine, Code:${err.code}, message:${err.message}`);
  } else {
    console.info(`Succeeded in creating wakeupIntelligentVoice engine.`);
    wakeupIntelligentVoiceEngine = data;
  }
});

intelligentVoice.createWakeupIntelligentVoiceEngine

createWakeupIntelligentVoiceEngine(descriptor: WakeupIntelligentVoiceEngineDescriptor): Promise<WakeupIntelligentVoiceEngine>

创建智能语音唤醒引擎实例,使用Promise异步回调。

需要权限: ohos.permission.MANAGE_INTELLIGENT_VOICE

系统能力: SystemCapability.AI.IntelligentVoice.Core

参数:

参数名 类型 必填 说明
descriptor WakeupIntelligentVoiceEngineDescriptor 唤醒智能语音引擎描述符。

返回值:

类型 说明
Promise<WakeupIntelligentVoiceEngine> 返回唤醒智能语音引擎。

错误码:

以下错误码的详细介绍请参见智能语音错误码

错误码ID 错误信息
22700101 No memory.
22700102 Input parameter value error.

示例:

import { BusinessError } from '@ohos.base';

let wakeupEngineDescriptor: intelligentVoice.WakeupIntelligentVoiceEngineDescriptor = {
  needReconfirm: true,
  wakeupPhrase: '小华小华',
}
let wakeupIntelligentVoiceEngine: intelligentVoice.WakeupIntelligentVoiceEngine | null = null;
intelligentVoice.createWakeupIntelligentVoiceEngine(wakeupEngineDescriptor).then((data: intelligentVoice.WakeupIntelligentVoiceEngine) => {
  wakeupIntelligentVoiceEngine = data;
  console.info(`Succeeded in creating wakeupIntelligentVoice engine.`);
}).catch((err: BusinessError) => {
  console.error(`Failed to create wakeupIntelligentVoice engine, Code:${err.code}, message:${err.message}`);
});

IntelligentVoiceManager

智能语音管理类,使用前需要通过getIntelligentVoiceManager()获取智能语音管理实例。

getCapabilityInfo

getCapabilityInfo(): Array<IntelligentVoiceEngineType>

获取支持的智能语音引擎列表信息。

需要权限: ohos.permission.MANAGE_INTELLIGENT_VOICE

系统能力: SystemCapability.AI.IntelligentVoice.Core

返回值:

类型 说明
Array<IntelligentVoiceEngineType> 支持的智能语音引擎类型数组。

示例:

if (intelligentVoiceManager != null) {
  let info = intelligentVoiceManager.getCapabilityInfo();
}

on('serviceChange')

on(type: 'serviceChange', callback: Callback<ServiceChangeType>): void

订阅服务变更事件。当智能语音业务状态发生变化时,调用回调。

需要权限: ohos.permission.MANAGE_INTELLIGENT_VOICE

系统能力: SystemCapability.AI.IntelligentVoice.Core

参数:

参数名 类型 必填 说明
type string 系统服务变更事件,固定取值为'serviceChange',表示服务变更事件。
callback Callback<ServiceChangeType> 服务状态变更对应的处理。

示例:

if (intelligentVoiceManager != null) {
  intelligentVoiceManager.on('serviceChange', (serviceChangeType: intelligentVoice.ServiceChangeType) => {});
}

off('serviceChange')

off(type: 'serviceChange', callback?: Callback<ServiceChangeType>): void

取消订阅服务变更事件。

需要权限: ohos.permission.MANAGE_INTELLIGENT_VOICE

系统能力: SystemCapability.AI.IntelligentVoice.Core

参数:

参数名 类型 必填 说明
type string 系统服务变更事件,固定取值为'serviceChange'。
callback Callback<ServiceChangeType> 服务状态变更对应的处理,无参数,则取消所有订阅,否则,取消对应的处理。

示例:

if (intelligentVoiceManager != null) {
  intelligentVoiceManager.off('serviceChange');
}

ServiceChangeType

枚举,服务状态变更类型。

系统能力: SystemCapability.AI.IntelligentVoice.Core

名称 说明
SERVICE_UNAVAILABLE 0 服务状态不可用。

IntelligentVoiceEngineType

枚举,智能语音引擎类型。

系统能力: SystemCapability.AI.IntelligentVoice.Core

名称 说明
ENROLL_ENGINE_TYPE 0 语音注册引擎。
WAKEUP_ENGINE_TYPE 1 语音唤醒引擎。
UPDATE_ENGINE_TYPE 2 静默升级引擎。

EnrollIntelligentVoiceEngineDescriptor

注册智能语音引擎描述符。

系统能力: SystemCapability.AI.IntelligentVoice.Core

名称 类型 必填 说明
wakeupPhrase string 唤醒词。

WakeupIntelligentVoiceEngineDescriptor

唤醒智能语音引擎描述符。

系统能力: SystemCapability.AI.IntelligentVoice.Core

名称 类型 必填 说明
needReconfirm boolean 是否需要再次确认唤醒结果,true为需要,false为不需要。
wakeupPhrase string 唤醒词。

EnrollEngineConfig

描述注册引擎配置。

系统能力: SystemCapability.AI.IntelligentVoice.Core

名称 类型 必填 说明
language string 注册引擎支持的语言,当前仅支持中文,取值为'zh'。
region string 注册引擎支持的区域。当前仅支持中国,取值为'CN'。

SensibilityType

枚举,唤醒灵敏度类型。 灵敏度用于调整唤醒的门限,灵敏度越高,门限越低,就越容易唤醒。

系统能力: SystemCapability.AI.IntelligentVoice.Core

名称 说明
LOW_SENSIBILITY 1 低灵敏度。
MIDDLE_SENSIBILITY 2 中灵敏度。
HIGH_SENSIBILITY 3 高灵敏度。

WakeupHapInfo

描述唤醒应用的hap信息。

系统能力: SystemCapability.AI.IntelligentVoice.Core

名称 类型 必填 说明
bundleName string 唤醒应用的bundleName。
abilityName string 唤醒应用的ailityName。

WakeupIntelligentVoiceEventType

枚举,唤醒智能语音事件类型。

系统能力: SystemCapability.AI.IntelligentVoice.Core

名称 说明
INTELLIGENT_VOICE_EVENT_WAKEUP_NONE 0 无唤醒。
INTELLIGENT_VOICE_EVENT_RECOGNIZE_COMPLETE 1 唤醒识别完成。

IntelligentVoiceErrorCode

枚举,智能语音错误码。

系统能力: SystemCapability.AI.IntelligentVoice.Core

名称 说明
INTELLIGENT_VOICE_NO_MEMORY 22700101 内存不足。
INTELLIGENT_VOICE_INVALID_PARAM 22700102 参数无效。
INTELLIGENT_VOICE_INIT_FAILED 22700103 注册失败。
INTELLIGENT_VOICE_COMMIT_ENROLL_FAILED 22700104 确认注册结果失败。

EnrollResult

枚举,注册结果。

系统能力: SystemCapability.AI.IntelligentVoice.Core

名称 说明
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 未知错误。

EnrollCallbackInfo

注册回调信息。

系统能力: SystemCapability.AI.IntelligentVoice.Core

名称 类型 必填 说明
result EnrollResult 注册结果。
context string 描述注册事件上下文。

WakeupIntelligentVoiceEngineCallbackInfo

描述唤醒智能语音引擎回调信息。

系统能力: SystemCapability.AI.IntelligentVoice.Core

名称 类型 必填 说明
eventId WakeupIntelligentVoiceEventType 唤醒智能语音事件类型。
isSuccess boolean 是否唤醒成功,false为唤醒失败,true为唤醒成功。
context string 描述唤醒事件上下文。

EnrollIntelligentVoiceEngine

实现注册智能语音引擎,通过createEnrollIntelligentVoiceEngine()获取注册智能语音引擎。

getSupportedRegions

getSupportedRegions(callback: AsyncCallback<Array<string>>): void

获取支持的区域,使用callback异步回调。

需要权限: ohos.permission.MANAGE_INTELLIGENT_VOICE

系统能力: SystemCapability.AI.IntelligentVoice.Core

参数:

参数名 类型 必填 说明
callback AsyncCallback<Array<string>> 返回支持区域的数组,当前只支持中国,对应取值为'CN'。

示例:

import { BusinessError } from '@ohos.base';

let regions: Array<string> | null = null;
if (enrollIntelligentVoiceEngine != null) {
  (enrollIntelligentVoiceEngine as intelligentVoice.EnrollIntelligentVoiceEngine).getSupportedRegions((err: BusinessError, data: Array<string>) => {
    if (err) {
      console.error(`Failed to get supported regions, Code:${err.code}, message:${err.message}`);
    } else {
      regions = data;
      console.info(`Succeeded in getting supported regions, regions:${regions}.`);
    }
  });
}

getSupportedRegions

getSupportedRegions(): Promise<Array<string>>

获取支持的区域,使用Promise异步回调。

需要权限: ohos.permission.MANAGE_INTELLIGENT_VOICE

系统能力: SystemCapability.AI.IntelligentVoice.Core

返回值:

类型 说明
Promise<Array<string>> 返回支持区域的数组,当前只支持中国,对应取值为'CN'。

示例:

import { BusinessError } from '@ohos.base';

let regions: Array<string> | null = null;
if (enrollIntelligentVoiceEngine != null) {
  (enrollIntelligentVoiceEngine as intelligentVoice.EnrollIntelligentVoiceEngine).getSupportedRegions().then((data: Array<string>) => {
    regions = data;
    console.info('Succeeded in getting supported regions, regions:${regions}.');
  }).catch((err: BusinessError) => {
    console.error(`Failed to get supported regions, Code:${err.code}, message:${err.message}`);
  });
}

init

init(config: EnrollEngineConfig, callback: AsyncCallback<void>): void

初始化注册智能语音引擎,使用callback异步回调。

需要权限: ohos.permission.MANAGE_INTELLIGENT_VOICE

系统能力: SystemCapability.AI.IntelligentVoice.Core

参数:

参数名 类型 必填 说明
config EnrollEngineConfig 注册引擎配置。
callback AsyncCallback<void> 返回初始化结果。

错误码:

以下错误码的详细介绍请参见智能语音错误码

错误码ID 错误信息
22700102 Input parameter value error.
22700103 Init failed.

示例:

import { BusinessError } from '@ohos.base';

let config: intelligentVoice.EnrollEngineConfig = {
  language: 'zh',
  region: 'CN',
}
if (enrollIntelligentVoiceEngine != null) {
  (enrollIntelligentVoiceEngine as intelligentVoice.EnrollIntelligentVoiceEngine).init(config, (err: BusinessError) => {
    if (err) {
      console.error(`Failed to initialize enrollIntelligentVoice engine. Code:${err.code}, message:${err.message}`);
    } else {
      console.info(`Succeeded in initialzing enrollIntelligentVoice engine.`);
    }
  });
}

init

init(config: EnrollEngineConfig): Promise<void>

初始化注册智能语音引擎,使用Promise异步回调。

需要权限: ohos.permission.MANAGE_INTELLIGENT_VOICE

系统能力: SystemCapability.AI.IntelligentVoice.Core

参数:

参数名 类型 必填 说明
config EnrollEngineConfig config表示注册引擎配置。

返回值:

类型 说明
Promise<void> 无返回结果的Promise对象。

错误码:

以下错误码的详细介绍请参见智能语音错误码

错误码ID 错误信息
22700102 Input parameter value error.
22700103 Init failed.

示例:

import { BusinessError } from '@ohos.base';

let config: intelligentVoice.EnrollEngineConfig = {
  language: 'zh',
  region: 'CN',
}
if (enrollIntelligentVoiceEngine != null) {
  (enrollIntelligentVoiceEngine as intelligentVoice.EnrollIntelligentVoiceEngine).init(config).then(() => {
    console.info(`Succeeded in initializing enrollIntelligentVoice engine.`);
  }).catch((err: BusinessError) => {
    console.error(`Failed to initialize enrollIntelligentVoice engine. Code:${err.code}, message:${err.message}`);
  });
}

enrollForResult

enrollForResult(isLast: boolean, callback: AsyncCallback<EnrollCallbackInfo>): void

获取注册结果,使用callback异步回调。

需要权限: ohos.permission.MANAGE_INTELLIGENT_VOICE

系统能力: SystemCapability.AI.IntelligentVoice.Core

参数:

参数名 类型 必填 说明
isLast boolean isLast表示是否为最后一次注册,false为非最后一次,true为最后一次。
callback AsyncCallback<EnrollCallbackInfo> 返回注册结果。

示例:

import { BusinessError } from '@ohos.base';

let callbackInfo: intelligentVoice.EnrollCallbackInfo | null = null;
if (enrollIntelligentVoiceEngine != null) {
  (enrollIntelligentVoiceEngine as intelligentVoice.EnrollIntelligentVoiceEngine).enrollForResult(true, (err: BusinessError, data: intelligentVoice.EnrollCallbackInfo) => {
    if (err) {
      console.error(`Failed to enroll for result, Code:${err.code}, message:${err.message}`);
    } else {
      callbackInfo = data;
      console.info(`Succeeded in enrolling for result, info:${callbackInfo}.`);
    }
  });
}

enrollForResult

enrollForResult(isLast: boolean): Promise<EnrollCallbackInfo>

获取注册结果,使用Promise异步回调。

需要权限: ohos.permission.MANAGE_INTELLIGENT_VOICE

系统能力: SystemCapability.AI.IntelligentVoice.Core

参数:

参数名 类型 必填 说明
isLast boolean isLast表示是否为最后一次注册,false为非最后一次,true为最后一次。

返回值:

类型 说明
Promise<EnrollCallbackInfo> 返回注册结果。

示例:

import { BusinessError } from '@ohos.base';

let callbackInfo: intelligentVoice.EnrollCallbackInfo | null = null;
if (enrollIntelligentVoiceEngine != null) {
  (enrollIntelligentVoiceEngine as intelligentVoice.EnrollIntelligentVoiceEngine).enrollForResult(true).then((data: intelligentVoice.EnrollCallbackInfo) => {
    callbackInfo = data;
    console.info(`Succeeded in enrolling for result, info:${callbackInfo}.`);
  }).catch((err: BusinessError) => {
    console.error(`Failed to enroll for result, Code:${err.code}, message:${err.message}`);
  });
}

stop

stop(callback: AsyncCallback<void>): void

停止注册,使用callback异步回调。

需要权限: ohos.permission.MANAGE_INTELLIGENT_VOICE

系统能力: SystemCapability.AI.IntelligentVoice.Core

参数名 类型 必填 说明
callback AsyncCallback<void> 返回停止结果。

示例:

import { BusinessError } from '@ohos.base';

if (enrollIntelligentVoiceEngine != null) {
  (enrollIntelligentVoiceEngine as intelligentVoice.EnrollIntelligentVoiceEngine).stop((err: BusinessError) => {
    if (err) {
      console.error(`Failed to stop enrollIntelligentVoice engine, Code:${err.code}, message:${err.message}`);
    } else {
      console.info(`Succeeded in stopping enrollIntelligentVoice engine.`);
    }
  });
}

stop

stop(): Promise<void>

停止注册,使用Promise异步回调。

需要权限: ohos.permission.MANAGE_INTELLIGENT_VOICE

系统能力: SystemCapability.AI.IntelligentVoice.Core

返回值:

类型 说明
Promise<void> 无返回结果的Promise对象。

示例:

import { BusinessError } from '@ohos.base';

if (enrollIntelligentVoiceEngine != null) {
  (enrollIntelligentVoiceEngine as intelligentVoice.EnrollIntelligentVoiceEngine).stop().then(() => {
    console.info(`Succeeded in stopping enrollIntelligentVoice engine.`);
  }).catch((err:BusinessError) => {
    console.error(`Failed to stop enrollIntelligentVoice engine, Code:${err.code}, message:${err.message}`);
  });
}

commit

commit(callback: AsyncCallback<void>): void

提交注册,使用callback异步回调。

需要权限: ohos.permission.MANAGE_INTELLIGENT_VOICE

系统能力: SystemCapability.AI.IntelligentVoice.Core

参数:

参数名 类型 必填 说明
callback AsyncCallback<void> 返回确认注册结果。

错误码:

以下错误码的详细介绍请参见智能语音错误码

错误码ID 错误信息
22700104 Commit enroll failed.

示例:

import { BusinessError } from '@ohos.base';

if (enrollIntelligentVoiceEngine != null) {
  (enrollIntelligentVoiceEngine as intelligentVoice.EnrollIntelligentVoiceEngine).commit((err: BusinessError) => {
    if (err) {
      console.error(`Failed to commit enroll, Code:${err.code}, message:${err.message}`);
    } else {
      console.info(`Succeeded in committing enroll.`);
    }
  });
}

commit

commit(): Promise<void>

提交注册,使用Promise异步回调。

需要权限: ohos.permission.MANAGE_INTELLIGENT_VOICE

系统能力: SystemCapability.AI.IntelligentVoice.Core

返回值:

类型 说明
Promise<void> 无返回结果的Promise对象。

错误码:

以下错误码的详细介绍请参见智能语音错误码

错误码ID 错误信息
22700104 Commit enroll failed.

示例:

import { BusinessError } from '@ohos.base';

if (enrollIntelligentVoiceEngine != null) {
  (enrollIntelligentVoiceEngine as intelligentVoice.EnrollIntelligentVoiceEngine).commit().then(() => {
    console.info(`Succeeded in committing enroll.`);
  }).catch((err: BusinessError) => {
    console.error(`Failed to commit enroll, Code:${err.code}, message:${err.message}`);
  });
}

setWakeupHapInfo

setWakeupHapInfo(info: WakeupHapInfo, callback: AsyncCallback<void>): void

设置唤醒应用的hap信息,使用callback异步回调。

需要权限: ohos.permission.MANAGE_INTELLIGENT_VOICE

系统能力: SystemCapability.AI.IntelligentVoice.Core

参数:

参数名 类型 必填 说明
info WakeupHapInfo 唤醒hap信息。
callback AsyncCallback<void> 返回设置唤醒hap信息的结果。

错误码:

以下错误码的详细介绍请参见智能语音错误码

错误码ID 错误信息
22700102 Input parameter value error.

示例:

import { BusinessError } from '@ohos.base';

let info: intelligentVoice.WakeupHapInfo = {
  bundleName: 'com.wakeup',
  abilityName: 'WakeUpExtAbility',
}
if (enrollIntelligentVoiceEngine != null) {
  (enrollIntelligentVoiceEngine as intelligentVoice.EnrollIntelligentVoiceEngine).setWakeupHapInfo(info, (err: BusinessError) => {
    if (err) {
      console.error(`Failed to set wakeup hap info, Code:${err.code}, message:${err.message}`);
    } else {
      console.info(`Succeeded in setting wakeup hap info.`);
    }
  });
}

setWakeupHapInfo

setWakeupHapInfo(info: WakeupHapInfo): Promise<void>

设置唤醒应用的hap信息,使用Promise异步回调。

需要权限: ohos.permission.MANAGE_INTELLIGENT_VOICE

系统能力: SystemCapability.AI.IntelligentVoice.Core

返回值:

类型 说明
Promise<void> 无返回结果的Promise对象。

错误码:

以下错误码的详细介绍请参见智能语音错误码

错误码ID 错误信息
22700102 Input parameter value error.

示例:

import { BusinessError } from '@ohos.base';

let info: intelligentVoice.WakeupHapInfo = {
  bundleName: 'com.wakeup',
  abilityName: 'WakeUpExtAbility',
}
if (enrollIntelligentVoiceEngine != null) {
  (enrollIntelligentVoiceEngine as intelligentVoice.EnrollIntelligentVoiceEngine).setWakeupHapInfo(info).then(() => {
    console.info(`Succeeded in setting wakeup hap info.`);
  }).catch((err: BusinessError) => {
    console.error(`Failed to set wakeup hap info, Code:${err.code}, message:${err.message}`);
  });
}

setSensibility

setSensibility(sensibility: SensibilityType, callback: AsyncCallback<void>): void

设置唤醒灵敏度,使用callback异步回调。

需要权限: ohos.permission.MANAGE_INTELLIGENT_VOICE

系统能力: SystemCapability.AI.IntelligentVoice.Core

参数:

参数名 类型 必填 说明
sensibility SensibilityType 灵敏度类型。
callback AsyncCallback<void> 返回设置灵敏度的结果。

错误码:

以下错误码的详细介绍请参见智能语音错误码

错误码ID 错误信息
22700102 Input parameter value error.

示例:

import { BusinessError } from '@ohos.base';

if (enrollIntelligentVoiceEngine != null) {
  (enrollIntelligentVoiceEngine as intelligentVoice.EnrollIntelligentVoiceEngine).setSensibility(intelligentVoice.SensibilityType.LOW_SENSIBILITY, (err: BusinessError) => {
    if (err) {
      console.error(`Failed to set sensibility, Code:${err.code}, message:${err.message}`);
    } else {
      console.info(`Succeeded in setting sensibility.`);
    }
  });
}

setSensibility

setSensibility(sensibility: SensibilityType): Promise<void>

设置唤醒灵敏度,使用Promise异步回调。

需要权限: ohos.permission.MANAGE_INTELLIGENT_VOICE

系统能力: SystemCapability.AI.IntelligentVoice.Core

参数:

参数名 类型 必填 说明
sensibility SensibilityType 灵敏度类型。

返回值:

类型 说明
Promise<void> 无返回结果的Promise对象。

错误码:

以下错误码的详细介绍请参见智能语音错误码

错误码ID 错误信息
22700102 Input parameter value error.

示例:

import { BusinessError } from '@ohos.base';

if (enrollIntelligentVoiceEngine != null) {
  (enrollIntelligentVoiceEngine as intelligentVoice.EnrollIntelligentVoiceEngine).setSensibility(intelligentVoice.SensibilityType.LOW_SENSIBILITY).then(() => {
    console.info(`Succeeded in setting sensibility.`);
  }).catch((err: BusinessError) => {
    console.error(`Failed to set sensibility, Code:${err.code}, message:${err.message}`);
  });
}

setParameter

setParameter(key: string, value: string, callback: AsyncCallback<void>): void

设置指定的智能语音参数,使用callback异步回调。

需要权限: ohos.permission.MANAGE_INTELLIGENT_VOICE

系统能力: SystemCapability.AI.IntelligentVoice.Core

参数:

参数名 类型 必填 说明
key string 键。
value string 值。
callback AsyncCallback<void> 返回设置智能语音参数的结果。

错误码:

以下错误码的详细介绍请参见智能语音错误码

错误码ID 错误信息
22700102 Input parameter value error.

示例:

import { BusinessError } from '@ohos.base';

if (enrollIntelligentVoiceEngine != null) {
  (enrollIntelligentVoiceEngine as intelligentVoice.EnrollIntelligentVoiceEngine).setParameter('scene', '0', (err: BusinessError) => {
    if (err) {
      console.error(`Failed to set parameter, Code:${err.code}, message:${err.message}`);
    } else {
      console.info(`Succeeded in setting parameter`);
    }
  });
}

setParameter

setParameter(key: string, value: string): Promise<void>

设置指定的智能语音参数,使用Promise异步回调。

需要权限: ohos.permission.MANAGE_INTELLIGENT_VOICE

系统能力: SystemCapability.AI.IntelligentVoice.Core

参数:

参数名 类型 必填 说明
key string 键。
value string 值。

返回值:

类型 说明
Promise<void> 无返回结果的Promise对象。

错误码:

以下错误码的详细介绍请参见智能语音错误码

错误码ID 错误信息
22700102 Input parameter value error.

示例:

import { BusinessError } from '@ohos.base';

if (enrollIntelligentVoiceEngine != null) {
  (enrollIntelligentVoiceEngine as intelligentVoice.EnrollIntelligentVoiceEngine).setParameter('scene', '0').then(() => {
    console.info(`Succeeded in setting parameter`);
  }).catch((err: BusinessError) => {
    console.error(`Failed to set parameter, Code:${err.code}, message:${err.message}`);
  });
}

getParameter

getParameter(key: string, callback: AsyncCallback<string>): void

获取指定的智能语音参数,使用callback异步回调。

需要权限: ohos.permission.MANAGE_INTELLIGENT_VOICE

系统能力: SystemCapability.AI.IntelligentVoice.Core

参数:

参数名 类型 必填 说明
key string 键。
callback AsyncCallback<string> 返回智能语音参数。

错误码:

以下错误码的详细介绍请参见智能语音错误码

错误码ID 错误信息
22700102 Input parameter value error.

示例:

import { BusinessError } from '@ohos.base';

if (enrollIntelligentVoiceEngine != null) {
  (enrollIntelligentVoiceEngine as intelligentVoice.EnrollIntelligentVoiceEngine).getParameter('key', (err: BusinessError, data: string) => {
    if (err) {
      console.error(`Failed to get parameter, Code:${err.code}, message:${err.message}`);
    } else {
      let param: string = data;
      console.info(`Succeeded in getting parameter, param:${param}`);
    }
  });
}

getParameter

getParameter(key: string): Promise<string>

获取指定的智能语音参数,使用Promise异步回调。

需要权限: ohos.permission.MANAGE_INTELLIGENT_VOICE

系统能力: SystemCapability.AI.IntelligentVoice.Core

参数:

参数名 类型 必填 说明
key string 键。

返回值:

类型 说明
Promise<string> 返回智能语音参数。

错误码:

以下错误码的详细介绍请参见智能语音错误码

错误码ID 错误信息
22700102 Input parameter value error.

示例:

import { BusinessError } from '@ohos.base';

if (enrollIntelligentVoiceEngine != null) {
  (enrollIntelligentVoiceEngine as intelligentVoice.EnrollIntelligentVoiceEngine).getParameter('key').then((data: string) => {
    let param: string = data;
    console.info(`Succeeded in getting parameter, param:${param}`);
  }).catch((err: BusinessError) => {
    console.error(`Failed to get parameter, Code:${err.code}, message:${err.message}`);
  });
}

release

release(callback: AsyncCallback<void>): void

释放注册智能语音引擎,使用callback异步回调。

需要权限: ohos.permission.MANAGE_INTELLIGENT_VOICE

系统能力: SystemCapability.AI.IntelligentVoice.Core

参数:

参数名 类型 必填 说明
callback AsyncCallback<void> 返回释放注册引擎的结果。

示例:

import { BusinessError } from '@ohos.base';

if (enrollIntelligentVoiceEngine != null) {
  (enrollIntelligentVoiceEngine as intelligentVoice.EnrollIntelligentVoiceEngine).release((err: BusinessError) => {
    if (err) {
      console.error(`Failed to release enrollIntelligentVoice engine, Code:${err.code}, message:${err.message}`);
    } else {
      console.info(`Succeeded in releasing enrollIntelligentVoice engine.`);
    }
  });
}

release

release(): Promise<void>

释放注册智能语音引擎,使用Promise异步回调。

需要权限: ohos.permission.MANAGE_INTELLIGENT_VOICE

系统能力: SystemCapability.AI.IntelligentVoice.Core

返回值:

类型 说明
Promise<void> 无返回结果的Promise对象。

示例:

import { BusinessError } from '@ohos.base';

if (enrollIntelligentVoiceEngine != null) {
  (enrollIntelligentVoiceEngine as intelligentVoice.EnrollIntelligentVoiceEngine).release().then(() => {
    console.info(`Succeeded in releasing enrollIntelligentVoice engine.`);
  }).catch((err: BusinessError) => {
    console.error(`Failed to release enrollIntelligentVoice engine, Code:${err.code}, message:${err.message}`);
  });
}

WakeupIntelligentVoiceEngine

实现唤醒智能语音引擎,通过createWakeupIntelligentVoiceEngine()获取唤醒智能语音引擎。

getSupportedRegions

getSupportedRegions(callback: AsyncCallback<Array<string>>): void

获取支持的区域,使用callback异步回调。

需要权限: ohos.permission.MANAGE_INTELLIGENT_VOICE

系统能力: SystemCapability.AI.IntelligentVoice.Core

参数名 类型 必填 说明
callback AsyncCallback<Array<string>> 返回支持区域的数组,当前只支持中国,对应取值为'CN'。

示例:

import { BusinessError } from '@ohos.base';

if (wakeupIntelligentVoiceEngine != null) {
  (wakeupIntelligentVoiceEngine as intelligentVoice.WakeupIntelligentVoiceEngine).getSupportedRegions((err: BusinessError, data: Array<string>) => {
    if (err) {
      console.error(`Failed to get supported regions, Code:${err.code}, message:${err.message}`);
    } else {
      let regions: Array<string> = data;
      console.info(`Succeeded in getting supported regions, regions:${regions}.`);
    }
  });
}

getSupportedRegions

getSupportedRegions(): Promise<Array<string>>

获取支持的区域,使用Promise异步回调。

需要权限: ohos.permission.MANAGE_INTELLIGENT_VOICE

系统能力: SystemCapability.AI.IntelligentVoice.Core

返回值:

类型 说明
Promise<Array<string>> 返回支持区域的数组,当前只支持中国,对应取值为'CN'。

示例:

import { BusinessError } from '@ohos.base';

if (wakeupIntelligentVoiceEngine != null) {
  (wakeupIntelligentVoiceEngine as intelligentVoice.WakeupIntelligentVoiceEngine).getSupportedRegions().then((data: Array<string>) => {
    let regions: Array<string> = data;
    console.info(`Succeeded in getting supported regions, regions:${regions}.`);
  }).catch((err: BusinessError) => {
    console.error(`Failed to get supported regions, Code:${err.code}, message:${err.message}`);
  });
}

setWakeupHapInfo

setWakeupHapInfo(info: WakeupHapInfo, callback: AsyncCallback<void>): void

设置唤醒应用的hap信息,使用callback异步回调。

需要权限: ohos.permission.MANAGE_INTELLIGENT_VOICE

系统能力: SystemCapability.AI.IntelligentVoice.Core

参数:

参数名 类型 必填 说明
info WakeupHapInfo 唤醒hap信息。
callback AsyncCallback<void> 返回设置唤醒hap信息的结果。

错误码:

以下错误码的详细介绍请参见智能语音错误码

错误码ID 错误信息
22700102 Input parameter value error.

示例:

import { BusinessError } from '@ohos.base';

let hapInfo: intelligentVoice.WakeupHapInfo = {
  bundleName: 'com.wakeup',
  abilityName: 'WakeUpExtAbility',
}

if (wakeupIntelligentVoiceEngine != null) {
  (wakeupIntelligentVoiceEngine as intelligentVoice.WakeupIntelligentVoiceEngine).setWakeupHapInfo(hapInfo, (err: BusinessError) => {
    if (err) {
      console.error(`Failed to set wakeup hap info, Code:${err.code}, message:${err.message}`);
    } else {
      console.info(`Succeeded in setting wakeup hap info.`);
    }
  });
}

setWakeupHapInfo

setWakeupHapInfo(info: WakeupHapInfo): Promise<void>

设置唤醒应用的hap信息,使用promise异步回调。

需要权限: ohos.permission.MANAGE_INTELLIGENT_VOICE

系统能力: SystemCapability.AI.IntelligentVoice.Core

参数:

参数名 类型 必填 说明
info WakeupHapInfo 唤醒hap信息。

返回值:

类型 说明
Promise<void> 无返回结果的Promise对象。

错误码:

以下错误码的详细介绍请参见智能语音错误码

错误码ID 错误信息
22700102 Input parameter value error.

示例:

import { BusinessError } from '@ohos.base';

let hapInfo: intelligentVoice.WakeupHapInfo = {
  bundleName: 'com.wakeup',
  abilityName: 'WakeUpExtAbility',
}
if (wakeupIntelligentVoiceEngine != null) {
  (wakeupIntelligentVoiceEngine as intelligentVoice.WakeupIntelligentVoiceEngine).setWakeupHapInfo(hapInfo).then(() => {
    console.info(`Succeeded in setting wakeup hap info.`);
  }).catch((err: BusinessError) => {
    console.error(`Failed to set wakeup hap info, Code:${err.code}, message:${err.message}`);
  });
}

setSensibility

setSensibility(sensibility: SensibilityType, callback: AsyncCallback<void>): void

设置唤醒灵敏度,使用callback异步回调。

需要权限: ohos.permission.MANAGE_INTELLIGENT_VOICE

系统能力: SystemCapability.AI.IntelligentVoice.Core

参数:

参数名 类型 必填 说明
sensibility SensibilityType 灵敏度类型。
callback AsyncCallback<void> 返回设置灵敏度的结果。

错误码:

以下错误码的详细介绍请参见智能语音错误码

错误码ID 错误信息
22700102 Input parameter value error.

示例:

import { BusinessError } from '@ohos.base';

if (wakeupIntelligentVoiceEngine != null) {
  (wakeupIntelligentVoiceEngine as intelligentVoice.WakeupIntelligentVoiceEngine).setSensibility(intelligentVoice.SensibilityType.LOW_SENSIBILITY, (err: BusinessError) => {
    if (err) {
      console.error(`Failed to set sensibility, Code:${err.code}, message:${err.message}`);
    } else {
      console.info(`Succeeded in setting sensibility.`);
    }
  });
}

setSensibility

setSensibility(sensibility: SensibilityType): Promise<void>

设置唤醒灵敏度,使用Promise异步回调。

需要权限: ohos.permission.MANAGE_INTELLIGENT_VOICE

系统能力: SystemCapability.AI.IntelligentVoice.Core

参数:

参数名 类型 必填 说明
sensibility SensibilityType 灵敏度类型。

返回值:

类型 说明
Promise<void> 无返回结果的Promise对象。

错误码:

以下错误码的详细介绍请参见智能语音错误码

错误码ID 错误信息
22700102 Input parameter value error.

示例:

import { BusinessError } from '@ohos.base';

if (wakeupIntelligentVoiceEngine != null) {
  (wakeupIntelligentVoiceEngine as intelligentVoice.WakeupIntelligentVoiceEngine).setSensibility(intelligentVoice.SensibilityType.LOW_SENSIBILITY).then(() => {
    console.info(`Succeeded in setting sensibility.`);
  }).catch((err: BusinessError) => {
    console.error(`Failed to set sensibility, Code:${err.code}, message:${err.message}`);
  });
}

setParameter

setParameter(key: string, value: string, callback: AsyncCallback<void>): void

设置指定的智能语音参数,使用callback异步回调。

需要权限: ohos.permission.MANAGE_INTELLIGENT_VOICE

系统能力: SystemCapability.AI.IntelligentVoice.Core

参数:

参数名 类型 必填 说明
key string 键。
value string 值。
callback AsyncCallback<void> 返回设置智能语音参数的结果。

错误码:

以下错误码的详细介绍请参见智能语音错误码

错误码ID 错误信息
22700102 Input parameter value error.

示例:

import { BusinessError } from '@ohos.base';

if (wakeupIntelligentVoiceEngine != null) {
  (wakeupIntelligentVoiceEngine as intelligentVoice.WakeupIntelligentVoiceEngine).setParameter('scene', '0', (err: BusinessError) => {
    if (err) {
      console.error(`Failed to set parameter, Code:${err.code}, message:${err.message}`);
    } else {
      console.info(`Succeeded in setting parameter`);
    }
  });
}

setParameter

setParameter(key: string, value: string): Promise<void>

设置指定的智能语音参数,使用Promise异步回调。

需要权限: ohos.permission.MANAGE_INTELLIGENT_VOICE

系统能力: SystemCapability.AI.IntelligentVoice.Core

参数:

参数名 类型 必填 说明
key string 键。
value string 值。

返回值:

类型 说明
Promise<void> 无返回结果的Promise对象。

错误码:

以下错误码的详细介绍请参见智能语音错误码

错误码ID 错误信息
22700102 Input parameter value error.

示例:

import { BusinessError } from '@ohos.base';

if (wakeupIntelligentVoiceEngine != null) {
  (wakeupIntelligentVoiceEngine as intelligentVoice.WakeupIntelligentVoiceEngine).setParameter('scene', '0').then(() => {
    console.info(`Succeeded in setting parameter`);
  }).catch((err: BusinessError) => {
    console.error(`Failed to set parameter, Code:${err.code}, message:${err.message}`);
  });
}

getParameter

getParameter(key: string, callback: AsyncCallback<string>): void

获取指定的智能语音参数,使用callback异步回调。

需要权限: ohos.permission.MANAGE_INTELLIGENT_VOICE

系统能力: SystemCapability.AI.IntelligentVoice.Core

参数:

参数名 类型 必填 说明
key string 键。
callback AsyncCallback<string> 返回智能语音参数。

错误码:

以下错误码的详细介绍请参见智能语音错误码

错误码ID 错误信息
22700102 Input parameter value error.

示例:

import { BusinessError } from '@ohos.base';

if (wakeupIntelligentVoiceEngine != null) {
  (wakeupIntelligentVoiceEngine as intelligentVoice.WakeupIntelligentVoiceEngine).getParameter('key', (err: BusinessError, data: string) => {
    if (err) {
      console.error(`Failed to get parameter, Code:${err.code}, message:${err.message}`);
    } else {
      let param: string = data;
      console.info(`Succeeded in getting parameter, param:${param}`);
    }
  });
}

getParameter

getParameter(key: string): Promise<string>

获取指定的智能语音参数,使用Promise异步回调。

需要权限: ohos.permission.MANAGE_INTELLIGENT_VOICE

系统能力: SystemCapability.AI.IntelligentVoice.Core

参数:

参数名 类型 必填 说明
key string 键。

返回值:

类型 说明
Promise<string> 返回智能语音参数。

错误码:

以下错误码的详细介绍请参见智能语音错误码

错误码ID 错误信息
22700102 Input parameter value error.

示例:

import { BusinessError } from '@ohos.base';

if (wakeupIntelligentVoiceEngine != null) {
  (wakeupIntelligentVoiceEngine as intelligentVoice.WakeupIntelligentVoiceEngine).getParameter('key').then((data: string) => {
    let param: string = data;
    console.info(`Succeeded in getting parameter, param:${param}`);
  }).catch((err: BusinessError) => {
    console.error(`Failed to get parameter, Code:${err.code}, message:${err.message}`);
  });
}

release

release(callback: AsyncCallback<void>): void

释放唤醒智能语音引擎,使用callback异步回调。

需要权限: ohos.permission.MANAGE_INTELLIGENT_VOICE

系统能力: SystemCapability.AI.IntelligentVoice.Core

参数:

参数名 类型 必填 说明
callback AsyncCallback<void> 返回释放唤醒引擎的结果。

示例:

import { BusinessError } from '@ohos.base';

if (wakeupIntelligentVoiceEngine != null) {
  (wakeupIntelligentVoiceEngine as intelligentVoice.WakeupIntelligentVoiceEngine).release((err: BusinessError) => {
    if (err) {
      console.error(`Failed to release wakeupIntelligentVoice engine, Code:${err.code}, message:${err.message}`);
    } else {
      console.info(`Succeeded in releasing wakeupIntelligentVoice engine.`);
    }
  });
}

release

release(): Promise<void>

释放唤醒智能语音引擎,使用Promise异步回调。

需要权限: ohos.permission.MANAGE_INTELLIGENT_VOICE

系统能力: SystemCapability.AI.IntelligentVoice.Core

返回值:

类型 说明
Promise<void> 无返回结果的Promise对象。

示例:

import { BusinessError } from '@ohos.base';

if (wakeupIntelligentVoiceEngine != null) {
  (wakeupIntelligentVoiceEngine as intelligentVoice.WakeupIntelligentVoiceEngine).release().then(() => {
    console.info(`Succeeded in releasing wakeupIntelligentVoice engine.`);
  }).catch((err: BusinessError) => {
    console.error(`Failed to release wakeupIntelligentVoice engine, Code:${err.code}, message:${err.message}`);
  });
}

on

on(type: 'wakeupIntelligentVoiceEvent', callback: Callback<WakeupIntelligentVoiceEngineCallbackInfo>): void

订阅唤醒事件。

需要权限: ohos.permission.MANAGE_INTELLIGENT_VOICE

系统能力: SystemCapability.AI.IntelligentVoice.Core

参数:

参数名 类型 必填 说明
type string 唤醒智能语音事件,固定取为'wakeupIntelligentVoiceEvent',表示智能语音唤醒事件。
callback Callback<WakeupIntelligentVoiceEngineCallbackInfo> 收到唤醒事件的对应处理。

示例:

if (wakeupIntelligentVoiceEngine != null) {
  (wakeupIntelligentVoiceEngine as intelligentVoice.WakeupIntelligentVoiceEngine).on('wakeupIntelligentVoiceEvent',
    (info: intelligentVoice.WakeupIntelligentVoiceEngineCallbackInfo) => {
    let callbackInfo: intelligentVoice.WakeupIntelligentVoiceEngineCallbackInfo = info;
    console.info(`wakeup intelligentvoice event, info:${callbackInfo}`);
  });
}

off

off(type: 'wakeupIntelligentVoiceEvent', callback?: Callback<WakeupIntelligentVoiceEngineCallbackInfo>): void;

取消订阅唤醒事件。

需要权限: ohos.permission.MANAGE_INTELLIGENT_VOICE

系统能力: SystemCapability.AI.IntelligentVoice.Core

参数:

参数名 类型 必填 说明
type string 唤醒智能语音事件,固定取为'wakeupIntelligentVoiceEvent'。
callback Callback<WakeupIntelligentVoiceEngineCallbackInfo> 收到唤醒事件的对应处理。无参数,则取消所有的订阅,否则,取消对应的订阅

示例:

if (wakeupIntelligentVoiceEngine != null) {
  (wakeupIntelligentVoiceEngine as intelligentVoice.WakeupIntelligentVoiceEngine).off('wakeupIntelligentVoiceEvent');
}