1# @ohos.ai.intelligentVoice (智能语音)(系统接口) 2 3智能语音主要提供了语音注册及语音唤醒相关功能。 4 5该模块提供以下智能语音相关的常用功能: 6 7- [IntelligentVoiceManager](#intelligentvoicemanager):智能语音管理类,明确当前智能语音提供的相关功能,当前支持语音注册、语音唤醒。在进行智能语音相关开发前,需先调用[getIntelligentVoiceManager()](#intelligentvoicegetintelligentvoicemanager)确认当前支持智能语音的相关功能,再进行语音注册和语音唤醒的相关开发。 8- [EnrollIntelligentVoiceEngine](#enrollintelligentvoiceengine):实现语音注册。开发者需要先进行智能语音的注册,然后才能进行唤醒。 9- [WakeupIntelligentVoiceEngine](#wakeupintelligentvoiceengine):实现语音唤醒。开发者需要先进行智能语音的注册,然后才能进行唤醒。 10 11> **说明:** 12> 13> - 本模块首批接口从API version 10开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 14> 15> - 本模块接口为系统接口。 16> 17> - @ohos.ai.intelligentVoice归属的Kit已由'MindSpore Lite Kit'变更为'Basic Services Kit',请开发者使用新模块名'@kit.BasicServicesKit'完成模块导入。如果使用'@kit.MindSporeLiteKit'导入,将无法使用本模块的接口。 18 19## 导入模块 20```ts 21import { intelligentVoice } from '@kit.BasicServicesKit'; 22``` 23 24## intelligentVoice.getIntelligentVoiceManager 25 26getIntelligentVoiceManager(): IntelligentVoiceManager 27 28获取智能语音管理类。 29 30**需要权限:** ohos.permission.MANAGE_INTELLIGENT_VOICE 31 32**系统能力:** SystemCapability.AI.IntelligentVoice.Core 33 34**返回值:** 35 36| 类型 | 说明 | 37| ----------------------------- | ------------ | 38| [IntelligentVoiceManager](#intelligentvoicemanager) | 智能语音管理类。 | 39 40**错误码:** 41 42以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[智能语音错误码](errorcode-intelligentVoice.md)。 43 44| 错误码ID | 错误信息 | 45| ------- | --------------------------------------------| 46| 201 | Permission denied. | 47| 22700101 | No memory. | 48 49**示例:** 50 51```ts 52import { BusinessError } from '@kit.BasicServicesKit'; 53 54let intelligentVoiceManager: intelligentVoice.IntelligentVoiceManager | null = null; 55try { 56 intelligentVoiceManager = intelligentVoice.getIntelligentVoiceManager(); 57} catch (err) { 58 let error = err as BusinessError; 59 console.error(`Get IntelligentVoiceManager failed. Code:${error.code}, message:${error.message}`); 60} 61``` 62 63## intelligentVoice.getWakeupManager<sup>12+</sup> 64 65getWakeupManager(): WakeupManager 66 67获取唤醒管理类。 68 69**需要权限:** ohos.permission.MANAGE_INTELLIGENT_VOICE 70 71**系统能力:** SystemCapability.AI.IntelligentVoice.Core 72 73**返回值:** 74 75| 类型 | 说明 | 76| ----------------------------- | ------------ | 77| [WakeupManager](#wakeupmanager12) | 智能语音管理类。 | 78 79**错误码:** 80 81以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[智能语音错误码](errorcode-intelligentVoice.md)。 82 83| 错误码ID | 错误信息 | 84| ------- | --------------------------------------------| 85| 201 | Permission denied. | 86| 22700101 | No memory. | 87| 22700107 | System error. | 88 89**示例:** 90 91```ts 92import { BusinessError } from '@kit.BasicServicesKit'; 93 94let wakeupManager: intelligentVoice.WakeupManager | null = null; 95try { 96 wakeupManager = intelligentVoice.getWakeupManager(); 97} catch (err) { 98 let error = err as BusinessError; 99 console.error(`Get WakeupManager failed. Code:${error.code}, message:${error.message}`); 100} 101``` 102 103## intelligentVoice.createEnrollIntelligentVoiceEngine 104 105createEnrollIntelligentVoiceEngine(descriptor: EnrollIntelligentVoiceEngineDescriptor, callback: AsyncCallback<EnrollIntelligentVoiceEngine>): void 106 107创建智能语音注册引擎实例,使用callback异步回调。 108 109**需要权限:** ohos.permission.MANAGE_INTELLIGENT_VOICE 110 111**系统能力:** SystemCapability.AI.IntelligentVoice.Core 112 113**参数:** 114 115| 参数名 | 类型 | 必填 | 说明 | 116| -------- | ----------------------------------- | ---- | ---------------------- | 117| descriptor | [EnrollIntelligentVoiceEngineDescriptor](#enrollintelligentvoiceenginedescriptor) | 是 | 智能语音注册引擎描述符。 | 118| callback | AsyncCallback\<[EnrollIntelligentVoiceEngine](#enrollintelligentvoiceengine)\> | 是 | 返回注册智能语音引擎。 | 119 120**错误码:** 121 122以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[智能语音错误码](errorcode-intelligentVoice.md)。 123 124| 错误码ID | 错误信息 | 125| ------- | --------------------------------------------| 126| 201 | Permission denied. | 127| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.| 128| 22700101 | No memory. | 129| 22700102 | Invalid parameter. | 130 131**示例:** 132 133```ts 134import { BusinessError } from '@kit.BasicServicesKit'; 135 136let engineDescriptor: intelligentVoice.EnrollIntelligentVoiceEngineDescriptor = { 137 wakeupPhrase: '小华小华', 138} 139let enrollIntelligentVoiceEngine: intelligentVoice.EnrollIntelligentVoiceEngine | null = null; 140intelligentVoice.createEnrollIntelligentVoiceEngine(engineDescriptor, (err: BusinessError, data: intelligentVoice.EnrollIntelligentVoiceEngine) => { 141 if (err) { 142 console.error(`Failed to create enrollIntelligentVoice engine, Code:${err.code}, message:${err.message}`); 143 } else { 144 console.info(`Succeeded in creating enrollIntelligentVoice engine.`); 145 enrollIntelligentVoiceEngine = data; 146 } 147}); 148``` 149 150## intelligentVoice.createEnrollIntelligentVoiceEngine 151 152createEnrollIntelligentVoiceEngine(descriptor: EnrollIntelligentVoiceEngineDescriptor): Promise<EnrollIntelligentVoiceEngine> 153 154 155创建智能语音注册引擎实例,使用Promise异步回调。 156 157**需要权限:** ohos.permission.MANAGE_INTELLIGENT_VOICE 158 159**系统能力:** SystemCapability.AI.IntelligentVoice.Core 160 161**参数:** 162 163| 参数名 | 类型 | 必填 | 说明 | 164| -------- | ----------------------------------- | ---- | ---------------------- | 165| descriptor | [EnrollIntelligentVoiceEngineDescriptor](#enrollintelligentvoiceenginedescriptor) | 是 | 智能语音注册引擎描述符。 | 166 167**返回值:** 168 169| 类型 | 说明 | 170| ----------------------------------------------- | ---------------------------- | 171| Promise\<[EnrollIntelligentVoiceEngine](#enrollintelligentvoiceengine)\> | 返回注册智能语音引擎。 | 172 173**错误码:** 174 175以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[智能语音错误码](errorcode-intelligentVoice.md)。 176 177| 错误码ID | 错误信息 | 178| ------- | --------------------------------------------| 179| 201 | Permission denied. | 180| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.| 181| 22700101 | No memory. | 182| 22700102 | Invalid parameter. | 183 184**示例:** 185 186```ts 187import { BusinessError } from '@kit.BasicServicesKit'; 188 189let engineDescriptor: intelligentVoice.EnrollIntelligentVoiceEngineDescriptor = { 190 wakeupPhrase: '小华小华', 191} 192let enrollIntelligentVoiceEngine: intelligentVoice.EnrollIntelligentVoiceEngine | null = null; 193intelligentVoice.createEnrollIntelligentVoiceEngine(engineDescriptor).then((data: intelligentVoice.EnrollIntelligentVoiceEngine) => { 194 enrollIntelligentVoiceEngine = data; 195 console.info(`Succeeded in creating enrollIntelligentVoice engine.`); 196}).catch((err: BusinessError) => { 197 console.error(`Failed to create enrollIntelligentVoice engine, Code:${err.code}, message:${err.message}`); 198}); 199``` 200 201## intelligentVoice.createWakeupIntelligentVoiceEngine 202 203createWakeupIntelligentVoiceEngine(descriptor: WakeupIntelligentVoiceEngineDescriptor, callback: AsyncCallback<WakeupIntelligentVoiceEngine>): void 204 205 206创建智能语音唤醒引擎实例,使用callback异步回调。 207 208**需要权限:** ohos.permission.MANAGE_INTELLIGENT_VOICE 209 210**系统能力:** SystemCapability.AI.IntelligentVoice.Core 211 212**参数:** 213 214| 参数名 | 类型 | 必填 | 说明 | 215| -------- | ----------------------------------- | ---- | ---------------------- | 216| descriptor | [WakeupIntelligentVoiceEngineDescriptor](#wakeupintelligentvoiceenginedescriptor) | 是 | 唤醒智能语音引擎描述符。 | 217| callback | AsyncCallback\<[WakeupIntelligentVoiceEngine](#wakeupintelligentvoiceengine)\> | 是 | 返回唤醒智能语音引擎。 | 218 219**错误码:** 220 221以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[智能语音错误码](errorcode-intelligentVoice.md)。 222 223| 错误码ID | 错误信息 | 224| ------- | --------------------------------------------| 225| 201 | Permission denied. | 226| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.| 227| 22700101 | No memory. | 228| 22700102 | Invalid parameter. | 229 230**示例:** 231 232```ts 233import { BusinessError } from '@kit.BasicServicesKit'; 234 235let wakeupEngineDescriptor: intelligentVoice.WakeupIntelligentVoiceEngineDescriptor = { 236 needReconfirm: true, 237 wakeupPhrase: '小华小华', 238} 239let wakeupIntelligentVoiceEngine: intelligentVoice.WakeupIntelligentVoiceEngine | null = null; 240intelligentVoice.createWakeupIntelligentVoiceEngine(wakeupEngineDescriptor, (err: BusinessError, data: intelligentVoice.WakeupIntelligentVoiceEngine) => { 241 if (err) { 242 console.error(`Failed to create wakeupIntelligentVoice engine, Code:${err.code}, message:${err.message}`); 243 } else { 244 console.info(`Succeeded in creating wakeupIntelligentVoice engine.`); 245 wakeupIntelligentVoiceEngine = data; 246 } 247}); 248``` 249 250## intelligentVoice.createWakeupIntelligentVoiceEngine 251 252createWakeupIntelligentVoiceEngine(descriptor: WakeupIntelligentVoiceEngineDescriptor): Promise<WakeupIntelligentVoiceEngine> 253 254创建智能语音唤醒引擎实例,使用Promise异步回调。 255 256**需要权限:** ohos.permission.MANAGE_INTELLIGENT_VOICE 257 258**系统能力:** SystemCapability.AI.IntelligentVoice.Core 259 260**参数:** 261 262| 参数名 | 类型 | 必填 | 说明 | 263| -------- | ----------------------------------- | ---- | ---------------------- | 264| descriptor | [WakeupIntelligentVoiceEngineDescriptor](#wakeupintelligentvoiceenginedescriptor) | 是 | 唤醒智能语音引擎描述符。 | 265 266**返回值:** 267 268| 类型 | 说明 | 269| ----------------------------------------------- | ---------------------------- | 270| Promise\<[WakeupIntelligentVoiceEngine](#wakeupintelligentvoiceengine)> | 返回唤醒智能语音引擎。 | 271 272**错误码:** 273 274以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[智能语音错误码](errorcode-intelligentVoice.md)。 275 276| 错误码ID | 错误信息 | 277| ------- | --------------------------------------------| 278| 201 | Permission denied. | 279| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.| 280| 22700101 | No memory. | 281| 22700102 | Invalid parameter. | 282 283**示例:** 284 285```ts 286import { BusinessError } from '@kit.BasicServicesKit'; 287 288let wakeupEngineDescriptor: intelligentVoice.WakeupIntelligentVoiceEngineDescriptor = { 289 needReconfirm: true, 290 wakeupPhrase: '小华小华', 291} 292let wakeupIntelligentVoiceEngine: intelligentVoice.WakeupIntelligentVoiceEngine | null = null; 293intelligentVoice.createWakeupIntelligentVoiceEngine(wakeupEngineDescriptor).then((data: intelligentVoice.WakeupIntelligentVoiceEngine) => { 294 wakeupIntelligentVoiceEngine = data; 295 console.info(`Succeeded in creating wakeupIntelligentVoice engine.`); 296}).catch((err: BusinessError) => { 297 console.error(`Failed to create wakeupIntelligentVoice engine, Code:${err.code}, message:${err.message}`); 298}); 299``` 300 301## IntelligentVoiceManager 302 303智能语音管理类,使用前需要通过[getIntelligentVoiceManager()](#intelligentvoicegetintelligentvoicemanager)获取智能语音管理实例。 304 305### getCapabilityInfo 306 307getCapabilityInfo(): Array<IntelligentVoiceEngineType> 308 309获取支持的智能语音引擎列表信息。 310 311**需要权限:** ohos.permission.MANAGE_INTELLIGENT_VOICE 312 313**系统能力:** SystemCapability.AI.IntelligentVoice.Core 314 315**返回值:** 316 317| 类型 | 说明 | 318| ----------------------------------------------- | ---------------------------- | 319| Array\<[IntelligentVoiceEngineType](#intelligentvoiceenginetype)\> | 支持的智能语音引擎类型数组。 | 320 321**错误码:** 322 323以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 324 325| 错误码ID | 错误信息 | 326| ------- | --------------------------------------------| 327| 201 | Permission denied. | 328 329**示例:** 330 331```ts 332if (intelligentVoiceManager != null) { 333 let info = intelligentVoiceManager.getCapabilityInfo(); 334} 335``` 336 337### on('serviceChange') 338 339on(type: 'serviceChange', callback: Callback<ServiceChangeType>): void 340 341订阅服务变更事件。当智能语音业务状态发生变化时,调用回调。 342 343**需要权限:** ohos.permission.MANAGE_INTELLIGENT_VOICE 344 345**系统能力:** SystemCapability.AI.IntelligentVoice.Core 346 347**参数:** 348 349| 参数名 | 类型 | 必填 | 说明 | 350| -------- | -------------------------------- | --- | ------------------------------------------- | 351| type | string | 是 | 系统服务变更事件,固定取值为'serviceChange',表示服务变更事件。 | 352| callback | Callback\<[ServiceChangeType](#servicechangetype)\> | 是 | 服务状态变更对应的处理。| 353 354**错误码:** 355 356以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 357 358| 错误码ID | 错误信息 | 359| ------- | --------------------------------------------| 360| 201 | Permission denied. | 361 362**示例:** 363 364```ts 365if (intelligentVoiceManager != null) { 366 intelligentVoiceManager.on('serviceChange', (serviceChangeType: intelligentVoice.ServiceChangeType) => {}); 367} 368``` 369 370### off('serviceChange') 371 372off(type: 'serviceChange', callback?: Callback\<ServiceChangeType\>): void 373 374取消订阅服务变更事件。 375 376**需要权限:** ohos.permission.MANAGE_INTELLIGENT_VOICE 377 378**系统能力:** SystemCapability.AI.IntelligentVoice.Core 379 380**参数:** 381 382| 参数名 | 类型 | 必填 | 说明 | 383| -------- | -------------------------------- | --- | ------------------------------------------- | 384| type | string | 是 | 系统服务变更事件,固定取值为'serviceChange'。 | 385| callback | Callback\<[ServiceChangeType](#servicechangetype)\> | 否 | 服务状态变更对应的处理,无参数,则取消所有订阅,否则,取消对应的处理。| 386 387**错误码:** 388 389以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 390 391| 错误码ID | 错误信息 | 392| ------- | --------------------------------------------| 393| 201 | Permission denied. | 394 395**示例:** 396 397```ts 398if (intelligentVoiceManager != null) { 399 intelligentVoiceManager.off('serviceChange'); 400} 401``` 402 403## WakeupManager<sup>12+</sup> 404 405唤醒管理类,使用前需要通过[getWakeupManager()](#intelligentvoicegetwakeupmanager12)获取唤醒管理实例。 406 407### setParameter<sup>12+</sup> 408 409setParameter(key: string, value: string): Promise\<void\> 410 411设置指定的唤醒参数,使用Promise异步回调。 412 413**需要权限:** ohos.permission.MANAGE_INTELLIGENT_VOICE 414 415**系统能力:** SystemCapability.AI.IntelligentVoice.Core 416 417**参数:** 418 419| 参数名 | 类型 | 必填 | 说明 | 420| -------- | -------------------------------- | --- | ------------------------------------------- | 421| key | string | 是 | 键,对应的是唤醒词的设置,当前仅支持'wakeup_phrase'。 | 422| value | string | 是 | 值。 | 423 424**返回值:** 425 426| 类型 | 说明 | 427| ----------------------------------------------- | ---------------------------- | 428| Promise<void> | Promise对象,无返回结果。 | 429 430**错误码:** 431 432以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[智能语音错误码](errorcode-intelligentVoice.md)。 433 434| 错误码ID | 错误信息 | 435| ------- | --------------------------------------------| 436| 201 | Permission denied. | 437| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.| 438| 22700102 | Invalid parameter. | 439| 22700107 | System error. | 440 441**示例:** 442 443```ts 444import { BusinessError } from '@kit.BasicServicesKit'; 445 446if (wakeupManager != null) { 447 (wakeupManager as intelligentVoice.WakeupManager).setParameter('wakeup_phrase', 'xiaohuaxiaohua').then(() => { 448 console.info(`Succeeded in setting parameter`); 449 }).catch((err: BusinessError) => { 450 console.error(`Failed to set parameter, Code:${err.code}, message:${err.message}`); 451 }); 452} 453``` 454 455### getParameter<sup>12+</sup> 456 457getParameter(key: string): Promise\<string\> 458 459获取指定的智能语音参数,使用Promise异步回调。 460 461**需要权限:** ohos.permission.MANAGE_INTELLIGENT_VOICE 462 463**系统能力:** SystemCapability.AI.IntelligentVoice.Core 464 465**参数:** 466 467| 参数名 | 类型 | 必填 | 说明 | 468| -------- | -------------------------------- | --- | ------------------------------------------- | 469| key | string | 是 | 键,只支持注册信息查询,当前仅支持'isEnrolled'。 | 470 471**返回值:** 472 473| 类型 | 说明 | 474| ----------------------------------------------- | ---------------------------- | 475| Promise\<string\> | Promise对象,返回是否已经注册,'true'表示注册过,'false'表示未注册过。 | 476 477**错误码:** 478 479以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[智能语音错误码](errorcode-intelligentVoice.md)。 480 481| 错误码ID | 错误信息 | 482| ------- | --------------------------------------------| 483| 201 | Permission denied. | 484| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.| 485| 22700102 | Invalid parameter. | 486| 22700107 | System error. | 487 488**示例:** 489 490```ts 491import { BusinessError } from '@kit.BasicServicesKit'; 492 493if (wakeupManager != null) { 494 (wakeupManager as intelligentVoice.WakeupManager).getParameter('isEnrolled').then((data: string) => { 495 let param: string = data; 496 console.info(`Succeeded in getting parameter, param:${param}`); 497 }).catch((err: BusinessError) => { 498 console.error(`Failed to get parameter, Code:${err.code}, message:${err.message}`); 499 }); 500} 501``` 502 503### getUploadFiles<sup>12+</sup> 504 505getUploadFiles(maxCount: number): Promise<Array<UploadFile>> 506 507获取保存的唤醒词文件,使用Promise异步回调。 508 509**需要权限:** ohos.permission.MANAGE_INTELLIGENT_VOICE 510 511**系统能力:** SystemCapability.AI.IntelligentVoice.Core 512 513**参数:** 514 515| 参数名 | 类型 | 必填 | 说明 | 516| -------- | -------------------------------- | --- | ------------------------------------------- | 517| maxCount | number | 是 | 获取的文件数量。 | 518 519**返回值:** 520 521| 类型 | 说明 | 522| ----------------------------------------------- | ---------------------------- | 523| Promise<Array<[UploadFile](#uploadfile12)>> | Promise对象,返回获取的文件。 | 524 525**错误码:** 526 527以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[智能语音错误码](errorcode-intelligentVoice.md)。 528 529| 错误码ID | 错误信息 | 530| ------- | --------------------------------------------| 531| 201 | Permission denied. | 532| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.| 533| 22700101 | No memory. | 534| 22700102 | Invalid parameter. | 535| 22700107 | System error. | 536 537**示例:** 538 539```ts 540import { BusinessError } from '@kit.BasicServicesKit'; 541 542if (wakeupManager != null) { 543 (wakeupManager as intelligentVoice.WakeupManager).getUploadFiles(2).then((data: Array<intelligentVoice.UploadFile>) => { 544 let param: Array<intelligentVoice.UploadFile> = data; 545 console.info(`Succeeded in getting upload files, param:${param}`); 546 }).catch((err: BusinessError) => { 547 console.error(`Failed to get upload files, Code:${err.code}, message:${err.message}`); 548 }); 549} 550``` 551 552 553### getWakeupSourceFiles<sup>12+</sup> 554 555getWakeupSourceFiles(): Promise<Array<WakeupSourceFile>> 556 557获取唤醒资源文件,如注册语料、路径信息等,使用Promise异步回调。 558 559**需要权限:** ohos.permission.MANAGE_INTELLIGENT_VOICE 560 561**系统能力:** SystemCapability.AI.IntelligentVoice.Core 562 563**返回值:** 564 565| 类型 | 说明 | 566| ----------------------------------------------- | ---------------------------- | 567| Promise<Array<[WakeupSourceFile](#wakeupsourcefile12)>> | Promise对象,返回唤醒资源文件。 | 568 569**错误码:** 570 571以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[智能语音错误码](errorcode-intelligentVoice.md)。 572 573| 错误码ID | 错误信息 | 574| ------- | --------------------------------------------| 575| 201 | Permission denied. | 576| 22700101 | No memory. | 577| 22700107 | System error. | 578 579**示例:** 580 581```ts 582import { BusinessError } from '@kit.BasicServicesKit'; 583 584if (wakeupManager != null) { 585 (wakeupManager as intelligentVoice.WakeupManager).getWakeupSourceFiles().then( 586 (data: Array<intelligentVoice.WakeupSourceFile>) => { 587 let param: Array<intelligentVoice.WakeupSourceFile> = data; 588 console.info(`Succeeded in getting wakeup source files, param:${param}`); 589 }).catch((err: BusinessError) => { 590 console.error(`Failed to get wakeup source files, Code:${err.code}, message:${err.message}`); 591 }); 592} 593``` 594 595### enrollWithWakeupFilesForResult<sup>12+</sup> 596 597enrollWithWakeupFilesForResult(wakeupFiles: Array\<WakeupSourceFile\>, wakeupInfo: string): Promise\<EnrollResult\> 598 599使用唤醒文件注册以获得结果,使用Promise异步回调。 600 601**需要权限:** ohos.permission.MANAGE_INTELLIGENT_VOICE 602 603**系统能力:** SystemCapability.AI.IntelligentVoice.Core 604 605**参数:** 606 607| 参数名 | 类型 | 必填 | 说明 | 608| -------- | -------------------------------- | --- | ------------------------------------------- | 609| wakeupFiles | Array\<[WakeupSourceFile](#wakeupsourcefile12)\> | 是 | 唤醒资源文件(注册语料、路径信息等)。 | 610| wakeupInfo | string | 是 | 唤醒相关信息(源侧设备类型、版本,目标侧设备类型、版本等)。 | 611 612**返回值:** 613 614| 类型 | 说明 | 615| ----------------------------------------------- | ---------------------------- | 616| Promise<[EnrollResult](#enrollresult)> | Promise对象,返回注册结果。 | 617 618**错误码:** 619 620以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[智能语音错误码](errorcode-intelligentVoice.md)。 621 622| 错误码ID | 错误信息 | 623| ------- | --------------------------------------------| 624| 201 | Permission denied. | 625| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.| 626| 22700101 | No memory. | 627| 22700102 | Invalid parameter. | 628| 22700107 | System error. | 629 630**示例:** 631 632```ts 633import { BusinessError } from '@kit.BasicServicesKit'; 634 635let filesInfo: Array<intelligentVoice.WakeupSourceFile> = []; 636filesInfo[0] = {filePath: "", fileContent: new ArrayBuffer(100)}; 637let wakeupInfo: string = "version: 123" 638 639if (wakeupManager != null) { 640 (wakeupManager as intelligentVoice.WakeupManager).enrollWithWakeupFilesForResult( 641 filesInfo, wakeupInfo).then( 642 (data: intelligentVoice.EnrollResult) => { 643 let param: intelligentVoice.EnrollResult = data; 644 console.info(`Succeeded in enrolling with wakeup files for result, param:${param}`); 645 }).catch((err: BusinessError) => { 646 console.error(`Failed to enroll with wakeup files for result, Code:${err.code}, message:${err.message}`); 647 }); 648} 649``` 650 651### clearUserData<sup>12+</sup> 652 653clearUserData(): Promise<void> 654 655清楚用户数据,使用Promise异步回调。 656 657**需要权限:** ohos.permission.MANAGE_INTELLIGENT_VOICE 658 659**系统能力:** SystemCapability.AI.IntelligentVoice.Core 660 661**返回值:** 662 663| 类型 | 说明 | 664| ----------------------------------------------- | ---------------------------- | 665| Promise<void> | Promise对象,无返回结果。 | 666 667**错误码:** 668 669以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[智能语音错误码](errorcode-intelligentVoice.md)。 670 671| 错误码ID | 错误信息 | 672| ------- | --------------------------------------------| 673| 201 | Permission denied. | 674| 22700107 | System error. | 675 676**示例:** 677 678```ts 679import { BusinessError } from '@kit.BasicServicesKit'; 680 681if (wakeupManager != null) { 682 (wakeupManager as intelligentVoice.WakeupManager).clearUserData().then(() => { 683 console.info(`Succeeded in clearing user data.`); 684 }).catch((err: BusinessError) => { 685 console.error(`Failed to clear user data, Code:${err.code}, message:${err.message}`); 686 }); 687} 688``` 689 690## UploadFileType<sup>12+</sup> 691 692枚举,上传文件类型。 693 694**系统能力:** SystemCapability.AI.IntelligentVoice.Core 695 696| 名称 | 值 | 说明 | 697| ------------------------- | ---- | ------------ | 698| ENROLL_FILE | 0 | 注册文件。 | 699| WAKEUP_FILE | 1 | 唤醒文件。 | 700 701## UploadFile<sup>12+</sup> 702 703上传文件内容,包含文件类型,文件描述和内容。 704 705**系统能力:** SystemCapability.AI.IntelligentVoice.Core 706 707| 名称 | 类型 | 必填 | 说明 | 708| ------ | ----------------------------- | -------------- | ---------- | 709| type | [UploadFileType](#uploadfiletype12) | 是 | 文件类型。 | 710| filesDescription | string | 是 | 文件描述。 | 711| filesContent | Array\<ArrayBuffer\> | 是 | 文件内容。 | 712 713## WakeupSourceFile<sup>12+</sup> 714 715唤醒资源文件。 716 717**系统能力:** SystemCapability.AI.IntelligentVoice.Core 718 719| 名称 | 类型 | 必填 | 说明 | 720| ------ | ----------------------------- | -------------- | ---------- | 721| filePath | string | 是 | 文件路径。 | 722| fileContent | ArrayBuffer | 是 | 文件内容。 | 723 724## EvaluationResultCode<sup>12+</sup> 725 726枚举,自定义唤醒词返回错误码类型。 727 728**系统能力:** SystemCapability.AI.IntelligentVoice.Core 729 730| 名称 | 值 | 说明 | 731| ------------------------- | ---- | ------------ | 732| UNKNOWN | 0 | 未知错误。 | 733| PASS | 1 | 通过。 | 734| WORD_EMPTY | 2 | 字是空的。 | 735| CHINESE_ONLY | 3 | 只支持中文。 | 736| INVALID_LENGTH | 4 | 无效的长度。 | 737| UNUSUAL_WORD | 5 | 不寻常的词。 | 738| CONSECUTIVE_SAME_WORD | 6 | 连续相同的字。 | 739| TOO_FEW_PHONEMES | 7 | 音素太少。 | 740| TOO_MANY_PHONEMES | 8 | 音素太多。 | 741| COMMON_INSTRUCTION | 9 | 包含常用指令。 | 742| COMMON_SPOKEN_LANGUAGE | 10 | 包含常用口语。 | 743| SENSITIVE_WORD | 11 | 包含敏感词。 | 744| NO_INITIAL_CONSONANT | 12 | 两个连续的词,没有首辅音。 | 745| REPEATED_PHONEME | 13 | 包含重复的音素。 | 746 747## EvaluationResult<sup>12+</sup> 748 749唤醒词评估结果。 750 751**系统能力:** SystemCapability.AI.IntelligentVoice.Core 752 753| 名称 | 类型 | 必填 | 说明 | 754| ------ | ----------------------------- | -------------- | ---------- | 755| score | number | 是 | 自定义唤醒词的评估得分,范围在0到5之间。 | 756| resultCode | [EvaluationResultCode](#evaluationresultcode12) | 是 | 评估结果错误码。 | 757 758## ServiceChangeType 759 760枚举,服务状态变更类型。 761 762**系统能力:** SystemCapability.AI.IntelligentVoice.Core 763 764| 名称 | 值 | 说明 | 765| ------------------------- | ---- | ------------ | 766| SERVICE_UNAVAILABLE | 0 | 服务状态不可用。 | 767 768## IntelligentVoiceEngineType 769 770枚举,智能语音引擎类型。 771 772**系统能力:** SystemCapability.AI.IntelligentVoice.Core 773 774| 名称 | 值 | 说明 | 775| ------------------------- | ---- | ------------ | 776| ENROLL_ENGINE_TYPE | 0 | 语音注册引擎。 | 777| WAKEUP_ENGINE_TYPE | 1 | 语音唤醒引擎。 | 778| UPDATE_ENGINE_TYPE | 2 | 静默升级引擎。 | 779 780## EnrollIntelligentVoiceEngineDescriptor 781 782注册智能语音引擎描述符。 783 784**系统能力:** SystemCapability.AI.IntelligentVoice.Core 785 786| 名称 | 类型 | 必填 | 说明 | 787| ------ | ----------------------------- | -------------- | ---------- | 788| wakeupPhrase | string | 是 | 唤醒词。 | 789 790## WakeupIntelligentVoiceEngineDescriptor 791 792唤醒智能语音引擎描述符。 793 794**系统能力:** SystemCapability.AI.IntelligentVoice.Core 795 796| 名称 | 类型 | 必填 | 说明 | 797| ------ | ----------------------------- | -------------- | ---------- | 798| needReconfirm | boolean | 是 | 是否需要再次确认唤醒结果,true为需要,false为不需要。 | 799| wakeupPhrase | string | 是 | 唤醒词。 | 800 801## EnrollEngineConfig 802 803描述注册引擎配置。 804 805**系统能力:** SystemCapability.AI.IntelligentVoice.Core 806 807| 名称 | 类型 | 必填 | 说明 | 808| ------ | ----------------------------- | -------------- | ---------- | 809| language | string | 是 | 注册引擎支持的语言,当前仅支持中文,取值为'zh'。 | 810| region | string | 是 | 注册引擎支持的区域。当前仅支持中国,取值为'CN'。 | 811 812## SensibilityType 813 814枚举,唤醒灵敏度类型。 815灵敏度用于调整唤醒的门限,灵敏度越高,门限越低,就越容易唤醒。 816 817**系统能力:** SystemCapability.AI.IntelligentVoice.Core 818 819| 名称 | 值 | 说明 | 820| ------------------------- | ---- | ------------ | 821| LOW_SENSIBILITY | 1 | 低灵敏度。 | 822| MIDDLE_SENSIBILITY | 2 | 中灵敏度。 | 823| HIGH_SENSIBILITY | 3 | 高灵敏度。 | 824 825## WakeupHapInfo 826 827描述唤醒应用的hap信息。 828 829**系统能力:** SystemCapability.AI.IntelligentVoice.Core 830 831| 名称 | 类型 | 必填 | 说明 | 832| ------ | ----------------------------- | -------------- | ---------- | 833| bundleName | string | 是 | 唤醒应用的bundleName。 | 834| abilityName | string | 是 | 唤醒应用的ailityName。 | 835 836## WakeupIntelligentVoiceEventType 837 838枚举,唤醒智能语音事件类型。 839 840**系统能力:** SystemCapability.AI.IntelligentVoice.Core 841 842| 名称 | 值 | 说明 | 843| ------------------------- | ---- | ------------ | 844| INTELLIGENT_VOICE_EVENT_WAKEUP_NONE | 0 | 无唤醒。 | 845| INTELLIGENT_VOICE_EVENT_RECOGNIZE_COMPLETE | 1 | 唤醒识别完成。 | 846| INTELLIGENT_VOICE_EVENT_HEADSET_RECOGNIZE_COMPLETE | 2 | 耳机唤醒识别完成。 | 847 848## IntelligentVoiceErrorCode 849 850枚举,智能语音错误码。 851 852**系统能力:** SystemCapability.AI.IntelligentVoice.Core 853 854| 名称 | 值 | 说明 | 855| ------------------------- | ---- | ------------ | 856| INTELLIGENT_VOICE_NO_MEMORY | 22700101 | 内存不足。 | 857| INTELLIGENT_VOICE_INVALID_PARAM | 22700102 | 参数无效。 | 858| INTELLIGENT_VOICE_INIT_FAILED | 22700103 | 注册失败。 | 859| INTELLIGENT_VOICE_COMMIT_ENROLL_FAILED | 22700104 | 确认注册结果失败。 | 860| INTELLIGENT_VOICE_START_CAPTURER_FAILED<sup>12+</sup> | 22700105 | 启动读流失败。 | 861| INTELLIGENT_VOICE_READ_FAILED<sup>12+</sup> | 22700106 | 读流失败。 | 862| INTELLIGENT_VOICE_SYSTEM_ERROR<sup>12+</sup> | 22700107 | 系统错误。 | 863 864## CapturerChannel<sup>12+</sup> 865 866枚举,枚举捕获器通道。 867 868**系统能力:** SystemCapability.AI.IntelligentVoice.Core 869 870| 名称 | 值 | 说明 | 871| ------------------------- | ---- | ------------ | 872| CAPTURER_CHANNEL_1 | 0x1 << 0 | 1声道。 | 873| CAPTURER_CHANNEL_2 | 0x1 << 1 | 2声道。 | 874| CAPTURER_CHANNEL_3 | 0x1 << 2 | 3声道。 | 875| CAPTURER_CHANNEL_4 | 0x1 << 3 | 4声道。 | 876 877## EnrollResult 878 879枚举,注册结果。 880 881**系统能力:** SystemCapability.AI.IntelligentVoice.Core 882 883| 名称 | 值 | 说明 | 884| ------------------------- | ---- | ------------ | 885| SUCCESS | 0 | 注册成功。 | 886| VPR_TRAIN_FAILED | -1 | 声纹训练失败。 | 887| WAKEUP_PHRASE_NOT_MATCH | -2 | 唤醒短语不匹配。 | 888| TOO_NOISY | -3 | 周边环境太吵。 | 889| TOO_LOUD | -4 | 声音太大。 | 890| INTERVAL_LARGE | -5 | 唤醒词时间间隔太大。 | 891| DIFFERENT_PERSON | -6 | 不同人注册唤醒词。 | 892| UNKNOWN_ERROR | -100 | 未知错误。 | 893 894## EnrollCallbackInfo 895 896注册回调信息。 897 898**系统能力:** SystemCapability.AI.IntelligentVoice.Core 899 900| 名称 | 类型 | 必填 | 说明 | 901| ------ | ----------------------------- | -------------- | ---------- | 902| result | [EnrollResult](#enrollresult) | 是 | 注册结果。 | 903| context | string | 是 | 描述注册事件上下文。 | 904 905## WakeupIntelligentVoiceEngineCallbackInfo 906 907描述唤醒智能语音引擎回调信息。 908 909**系统能力:** SystemCapability.AI.IntelligentVoice.Core 910 911| 名称 | 类型 | 必填 | 说明 | 912| ------ | ----------------------------- | -------------- | ---------- | 913| eventId | [WakeupIntelligentVoiceEventType](#wakeupintelligentvoiceeventtype) | 是 | 唤醒智能语音事件类型。 | 914| isSuccess | boolean | 是 | 是否唤醒成功,false为唤醒失败,true为唤醒成功。 | 915| context | string | 是 | 描述唤醒事件上下文。 | 916 917## EnrollIntelligentVoiceEngine 918 919实现注册智能语音引擎,通过[createEnrollIntelligentVoiceEngine()](#intelligentvoicecreateenrollintelligentvoiceengine)获取注册智能语音引擎。 920 921### getSupportedRegions 922 923getSupportedRegions(callback: AsyncCallback<Array<string>>): void 924 925获取支持的区域,使用callback异步回调。 926 927**需要权限:** ohos.permission.MANAGE_INTELLIGENT_VOICE 928 929**系统能力:** SystemCapability.AI.IntelligentVoice.Core 930 931**参数:** 932 933| 参数名 | 类型 | 必填 | 说明 | 934| -------- | -------------------------------- | --- | ------------------------------------------- | 935| callback | AsyncCallback<Array<string>> | 是 | 返回支持区域的数组,当前只支持中国,对应取值为'CN'。 | 936 937**错误码:** 938 939以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 940 941| 错误码ID | 错误信息 | 942| ------- | --------------------------------------------| 943| 201 | Permission denied. | 944 945**示例:** 946 947```ts 948import { BusinessError } from '@kit.BasicServicesKit'; 949 950let regions: Array<string> | null = null; 951if (enrollIntelligentVoiceEngine != null) { 952 (enrollIntelligentVoiceEngine as intelligentVoice.EnrollIntelligentVoiceEngine).getSupportedRegions((err: BusinessError, data: Array<string>) => { 953 if (err) { 954 console.error(`Failed to get supported regions, Code:${err.code}, message:${err.message}`); 955 } else { 956 regions = data; 957 console.info(`Succeeded in getting supported regions, regions:${regions}.`); 958 } 959 }); 960} 961``` 962 963### getSupportedRegions 964 965getSupportedRegions(): Promise<Array<string>> 966 967获取支持的区域,使用Promise异步回调。 968 969**需要权限:** ohos.permission.MANAGE_INTELLIGENT_VOICE 970 971**系统能力:** SystemCapability.AI.IntelligentVoice.Core 972 973**返回值:** 974 975| 类型 | 说明 | 976| ----------------------------------------------- | ---------------------------- | 977| Promise<Array<string>> | 返回支持区域的数组,当前只支持中国,对应取值为'CN'。 | 978 979**错误码:** 980 981以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 982 983| 错误码ID | 错误信息 | 984| ------- | --------------------------------------------| 985| 201 | Permission denied. | 986 987**示例:** 988 989```ts 990import { BusinessError } from '@kit.BasicServicesKit'; 991 992let regions: Array<string> | null = null; 993if (enrollIntelligentVoiceEngine != null) { 994 (enrollIntelligentVoiceEngine as intelligentVoice.EnrollIntelligentVoiceEngine).getSupportedRegions().then((data: Array<string>) => { 995 regions = data; 996 console.info('Succeeded in getting supported regions, regions:${regions}.'); 997 }).catch((err: BusinessError) => { 998 console.error(`Failed to get supported regions, Code:${err.code}, message:${err.message}`); 999 }); 1000} 1001``` 1002 1003### init 1004 1005init(config: EnrollEngineConfig, callback: AsyncCallback<void>): void 1006 1007初始化注册智能语音引擎,使用callback异步回调。 1008 1009**需要权限:** ohos.permission.MANAGE_INTELLIGENT_VOICE 1010 1011**系统能力:** SystemCapability.AI.IntelligentVoice.Core 1012 1013**参数:** 1014 1015| 参数名 | 类型 | 必填 | 说明 | 1016| -------- | -------------------------------- | --- | ------------------------------------------- | 1017| config | [EnrollEngineConfig](#enrollengineconfig) | 是 | 注册引擎配置。 | 1018| callback |AsyncCallback<void> | 是 | 返回初始化结果。 | 1019 1020**错误码:** 1021 1022以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[智能语音错误码](errorcode-intelligentVoice.md)。 1023 1024| 错误码ID | 错误信息 | 1025| ------- | --------------------------------------------| 1026| 201 | Permission denied. | 1027| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.| 1028| 22700102 | Invalid parameter. | 1029| 22700103 | Init failed. | 1030 1031**示例:** 1032 1033```ts 1034import { BusinessError } from '@kit.BasicServicesKit'; 1035 1036let config: intelligentVoice.EnrollEngineConfig = { 1037 language: 'zh', 1038 region: 'CN', 1039} 1040if (enrollIntelligentVoiceEngine != null) { 1041 (enrollIntelligentVoiceEngine as intelligentVoice.EnrollIntelligentVoiceEngine).init(config, (err: BusinessError) => { 1042 if (err) { 1043 console.error(`Failed to initialize enrollIntelligentVoice engine. Code:${err.code}, message:${err.message}`); 1044 } else { 1045 console.info(`Succeeded in initialzing enrollIntelligentVoice engine.`); 1046 } 1047 }); 1048} 1049``` 1050 1051### init 1052 1053init(config: EnrollEngineConfig): Promise<void> 1054 1055初始化注册智能语音引擎,使用Promise异步回调。 1056 1057**需要权限:** ohos.permission.MANAGE_INTELLIGENT_VOICE 1058 1059**系统能力:** SystemCapability.AI.IntelligentVoice.Core 1060 1061**参数:** 1062 1063| 参数名 | 类型 | 必填 | 说明 | 1064| -------- | -------------------------------- | --- | ------------------------------------------- | 1065| config | [EnrollEngineConfig](#enrollengineconfig) | 是 | config表示注册引擎配置。 | 1066 1067**返回值:** 1068 1069| 类型 | 说明 | 1070| ----------------------------------------------- | ---------------------------- | 1071| Promise<void> | 无返回结果的Promise对象。 | 1072 1073**错误码:** 1074 1075以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[智能语音错误码](errorcode-intelligentVoice.md)。 1076 1077| 错误码ID | 错误信息 | 1078| ------- | --------------------------------------------| 1079| 201 | Permission denied. | 1080| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.| 1081| 22700102 | Invalid parameter. | 1082| 22700103 | Init failed. | 1083 1084**示例:** 1085 1086```ts 1087import { BusinessError } from '@kit.BasicServicesKit'; 1088 1089let config: intelligentVoice.EnrollEngineConfig = { 1090 language: 'zh', 1091 region: 'CN', 1092} 1093if (enrollIntelligentVoiceEngine != null) { 1094 (enrollIntelligentVoiceEngine as intelligentVoice.EnrollIntelligentVoiceEngine).init(config).then(() => { 1095 console.info(`Succeeded in initializing enrollIntelligentVoice engine.`); 1096 }).catch((err: BusinessError) => { 1097 console.error(`Failed to initialize enrollIntelligentVoice engine. Code:${err.code}, message:${err.message}`); 1098 }); 1099} 1100 1101``` 1102 1103### enrollForResult 1104 1105enrollForResult(isLast: boolean, callback: AsyncCallback<EnrollCallbackInfo>): void 1106 1107获取注册结果,使用callback异步回调。 1108 1109**需要权限:** ohos.permission.MANAGE_INTELLIGENT_VOICE 1110 1111**系统能力:** SystemCapability.AI.IntelligentVoice.Core 1112 1113**参数:** 1114 1115| 参数名 | 类型 | 必填 | 说明 | 1116| -------- | -------------------------------- | --- | ------------------------------------------- | 1117| isLast | boolean | 是 | isLast表示是否为最后一次注册,false为非最后一次,true为最后一次。 | 1118| callback | AsyncCallback<[EnrollCallbackInfo](#enrollcallbackinfo)> | 是 | 返回注册结果。 | 1119 1120**错误码:** 1121 1122以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 1123 1124| 错误码ID | 错误信息 | 1125| ------- | --------------------------------------------| 1126| 201 | Permission denied. | 1127| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.| 1128 1129**示例:** 1130 1131```ts 1132import { BusinessError } from '@kit.BasicServicesKit'; 1133 1134let callbackInfo: intelligentVoice.EnrollCallbackInfo | null = null; 1135if (enrollIntelligentVoiceEngine != null) { 1136 (enrollIntelligentVoiceEngine as intelligentVoice.EnrollIntelligentVoiceEngine).enrollForResult(true, (err: BusinessError, data: intelligentVoice.EnrollCallbackInfo) => { 1137 if (err) { 1138 console.error(`Failed to enroll for result, Code:${err.code}, message:${err.message}`); 1139 } else { 1140 callbackInfo = data; 1141 console.info(`Succeeded in enrolling for result, info:${callbackInfo}.`); 1142 } 1143 }); 1144} 1145``` 1146 1147### enrollForResult 1148 1149enrollForResult(isLast: boolean): Promise<EnrollCallbackInfo> 1150 1151获取注册结果,使用Promise异步回调。 1152 1153**需要权限:** ohos.permission.MANAGE_INTELLIGENT_VOICE 1154 1155**系统能力:** SystemCapability.AI.IntelligentVoice.Core 1156 1157**参数:** 1158 1159| 参数名 | 类型 | 必填 | 说明 | 1160| -------- | -------------------------------- | --- | ------------------------------------------- | 1161| isLast | boolean | 是 | isLast表示是否为最后一次注册,false为非最后一次,true为最后一次。 | 1162 1163**返回值:** 1164 1165| 类型 | 说明 | 1166| ----------------------------------------------- | ---------------------------- | 1167| Promise<[EnrollCallbackInfo](#enrollcallbackinfo)> | 返回注册结果。 | 1168 1169**错误码:** 1170 1171以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 1172 1173| 错误码ID | 错误信息 | 1174| ------- | --------------------------------------------| 1175| 201 | Permission denied. | 1176| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.| 1177 1178**示例:** 1179 1180```ts 1181import { BusinessError } from '@kit.BasicServicesKit'; 1182 1183let callbackInfo: intelligentVoice.EnrollCallbackInfo | null = null; 1184if (enrollIntelligentVoiceEngine != null) { 1185 (enrollIntelligentVoiceEngine as intelligentVoice.EnrollIntelligentVoiceEngine).enrollForResult(true).then((data: intelligentVoice.EnrollCallbackInfo) => { 1186 callbackInfo = data; 1187 console.info(`Succeeded in enrolling for result, info:${callbackInfo}.`); 1188 }).catch((err: BusinessError) => { 1189 console.error(`Failed to enroll for result, Code:${err.code}, message:${err.message}`); 1190 }); 1191} 1192``` 1193 1194### stop 1195 1196stop(callback: AsyncCallback<void>): void 1197 1198停止注册,使用callback异步回调。 1199 1200**需要权限:** ohos.permission.MANAGE_INTELLIGENT_VOICE 1201 1202**系统能力:** SystemCapability.AI.IntelligentVoice.Core 1203 1204| 参数名 | 类型 | 必填 | 说明 | 1205| -------- | -------------------------------- | --- | ------------------------------------------- | 1206| callback | AsyncCallback<void> | 是 | 返回停止结果。 | 1207 1208**错误码:** 1209 1210以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 1211 1212| 错误码ID | 错误信息 | 1213| ------- | --------------------------------------------| 1214| 201 | Permission denied. | 1215 1216**示例:** 1217 1218```ts 1219import { BusinessError } from '@kit.BasicServicesKit'; 1220 1221if (enrollIntelligentVoiceEngine != null) { 1222 (enrollIntelligentVoiceEngine as intelligentVoice.EnrollIntelligentVoiceEngine).stop((err: BusinessError) => { 1223 if (err) { 1224 console.error(`Failed to stop enrollIntelligentVoice engine, Code:${err.code}, message:${err.message}`); 1225 } else { 1226 console.info(`Succeeded in stopping enrollIntelligentVoice engine.`); 1227 } 1228 }); 1229} 1230``` 1231 1232### stop 1233 1234stop(): Promise<void> 1235 1236停止注册,使用Promise异步回调。 1237 1238**需要权限:** ohos.permission.MANAGE_INTELLIGENT_VOICE 1239 1240**系统能力:** SystemCapability.AI.IntelligentVoice.Core 1241 1242**返回值:** 1243 1244| 类型 | 说明 | 1245| ----------------------------------------------- | ---------------------------- | 1246| Promise<void> | 无返回结果的Promise对象。 | 1247 1248**错误码:** 1249 1250以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 1251 1252| 错误码ID | 错误信息 | 1253| ------- | --------------------------------------------| 1254| 201 | Permission denied. | 1255 1256**示例:** 1257 1258```ts 1259import { BusinessError } from '@kit.BasicServicesKit'; 1260 1261if (enrollIntelligentVoiceEngine != null) { 1262 (enrollIntelligentVoiceEngine as intelligentVoice.EnrollIntelligentVoiceEngine).stop().then(() => { 1263 console.info(`Succeeded in stopping enrollIntelligentVoice engine.`); 1264 }).catch((err:BusinessError) => { 1265 console.error(`Failed to stop enrollIntelligentVoice engine, Code:${err.code}, message:${err.message}`); 1266 }); 1267} 1268``` 1269 1270### commit 1271 1272commit(callback: AsyncCallback<void>): void 1273 1274提交注册,使用callback异步回调。 1275 1276**需要权限:** ohos.permission.MANAGE_INTELLIGENT_VOICE 1277 1278**系统能力:** SystemCapability.AI.IntelligentVoice.Core 1279 1280**参数:** 1281 1282| 参数名 | 类型 | 必填 | 说明 | 1283| -------- | -------------------------------- | --- | ------------------------------------------- | 1284| callback | AsyncCallback<void> | 是 | 返回确认注册结果。 | 1285 1286**错误码:** 1287 1288以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[智能语音错误码](errorcode-intelligentVoice.md)。 1289 1290| 错误码ID | 错误信息 | 1291| ------- | --------------------------------------------| 1292| 201 | Permission denied. | 1293| 22700104 | Failed to commit the enrollment. | 1294 1295**示例:** 1296 1297```ts 1298import { BusinessError } from '@kit.BasicServicesKit'; 1299 1300if (enrollIntelligentVoiceEngine != null) { 1301 (enrollIntelligentVoiceEngine as intelligentVoice.EnrollIntelligentVoiceEngine).commit((err: BusinessError) => { 1302 if (err) { 1303 console.error(`Failed to commit enroll, Code:${err.code}, message:${err.message}`); 1304 } else { 1305 console.info(`Succeeded in committing enroll.`); 1306 } 1307 }); 1308} 1309``` 1310 1311### commit 1312 1313commit(): Promise<void> 1314 1315提交注册,使用Promise异步回调。 1316 1317**需要权限:** ohos.permission.MANAGE_INTELLIGENT_VOICE 1318 1319**系统能力:** SystemCapability.AI.IntelligentVoice.Core 1320 1321**返回值:** 1322 1323| 类型 | 说明 | 1324| ----------------------------------------------- | ---------------------------- | 1325| Promise<void> | 无返回结果的Promise对象。 | 1326 1327**错误码:** 1328 1329以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[智能语音错误码](errorcode-intelligentVoice.md)。 1330 1331| 错误码ID | 错误信息 | 1332| ------- | --------------------------------------------| 1333| 201 | Permission denied. | 1334| 22700104 | Failed to commit the enrollment. | 1335 1336**示例:** 1337 1338```ts 1339import { BusinessError } from '@kit.BasicServicesKit'; 1340 1341if (enrollIntelligentVoiceEngine != null) { 1342 (enrollIntelligentVoiceEngine as intelligentVoice.EnrollIntelligentVoiceEngine).commit().then(() => { 1343 console.info(`Succeeded in committing enroll.`); 1344 }).catch((err: BusinessError) => { 1345 console.error(`Failed to commit enroll, Code:${err.code}, message:${err.message}`); 1346 }); 1347} 1348``` 1349 1350### setWakeupHapInfo 1351 1352setWakeupHapInfo(info: WakeupHapInfo, callback: AsyncCallback\<void>): void 1353 1354设置唤醒应用的hap信息,使用callback异步回调。 1355 1356**需要权限:** ohos.permission.MANAGE_INTELLIGENT_VOICE 1357 1358**系统能力:** SystemCapability.AI.IntelligentVoice.Core 1359 1360**参数:** 1361 1362| 参数名 | 类型 | 必填 | 说明 | 1363| -------- | -------------------------------- | --- | ------------------------------------------- | 1364| info | [WakeupHapInfo](#wakeuphapinfo) | 是 | 唤醒hap信息。 | 1365| callback | AsyncCallback\<void\> | 是 | 返回设置唤醒hap信息的结果。 | 1366 1367**错误码:** 1368 1369以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[智能语音错误码](errorcode-intelligentVoice.md)。 1370 1371| 错误码ID | 错误信息 | 1372| ------- | --------------------------------------------| 1373| 201 | Permission denied. | 1374| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.| 1375| 22700102 | Invalid parameter. | 1376 1377**示例:** 1378 1379```ts 1380import { BusinessError } from '@kit.BasicServicesKit'; 1381 1382let info: intelligentVoice.WakeupHapInfo = { 1383 bundleName: 'com.wakeup', 1384 abilityName: 'WakeUpExtAbility', 1385} 1386if (enrollIntelligentVoiceEngine != null) { 1387 (enrollIntelligentVoiceEngine as intelligentVoice.EnrollIntelligentVoiceEngine).setWakeupHapInfo(info, (err: BusinessError) => { 1388 if (err) { 1389 console.error(`Failed to set wakeup hap info, Code:${err.code}, message:${err.message}`); 1390 } else { 1391 console.info(`Succeeded in setting wakeup hap info.`); 1392 } 1393 }); 1394} 1395``` 1396 1397### setWakeupHapInfo 1398 1399setWakeupHapInfo(info: WakeupHapInfo): Promise\<void\> 1400 1401设置唤醒应用的hap信息,使用Promise异步回调。 1402 1403**需要权限:** ohos.permission.MANAGE_INTELLIGENT_VOICE 1404 1405**系统能力:** SystemCapability.AI.IntelligentVoice.Core 1406 1407**返回值:** 1408 1409| 类型 | 说明 | 1410| ----------------------------------------------- | ---------------------------- | 1411| Promise<void> | 无返回结果的Promise对象。 | 1412 1413**错误码:** 1414 1415以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[智能语音错误码](errorcode-intelligentVoice.md)。 1416 1417| 错误码ID | 错误信息 | 1418| ------- | --------------------------------------------| 1419| 201 | Permission denied. | 1420| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.| 1421| 22700102 | Invalid parameter. | 1422 1423**示例:** 1424 1425```ts 1426import { BusinessError } from '@kit.BasicServicesKit'; 1427 1428let info: intelligentVoice.WakeupHapInfo = { 1429 bundleName: 'com.wakeup', 1430 abilityName: 'WakeUpExtAbility', 1431} 1432if (enrollIntelligentVoiceEngine != null) { 1433 (enrollIntelligentVoiceEngine as intelligentVoice.EnrollIntelligentVoiceEngine).setWakeupHapInfo(info).then(() => { 1434 console.info(`Succeeded in setting wakeup hap info.`); 1435 }).catch((err: BusinessError) => { 1436 console.error(`Failed to set wakeup hap info, Code:${err.code}, message:${err.message}`); 1437 }); 1438} 1439``` 1440 1441### setSensibility 1442 1443setSensibility(sensibility: SensibilityType, callback: AsyncCallback\<void\>): void 1444 1445设置唤醒灵敏度,使用callback异步回调。 1446 1447**需要权限:** ohos.permission.MANAGE_INTELLIGENT_VOICE 1448 1449**系统能力:** SystemCapability.AI.IntelligentVoice.Core 1450 1451**参数:** 1452 1453| 参数名 | 类型 | 必填 | 说明 | 1454| -------- | -------------------------------- | --- | ------------------------------------------- | 1455| sensibility | [SensibilityType](#sensibilitytype) | 是 | 灵敏度类型。 | 1456| callback | AsyncCallback\<void\> | 是 | 返回设置灵敏度的结果。 | 1457 1458**错误码:** 1459 1460以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[智能语音错误码](errorcode-intelligentVoice.md)。 1461 1462| 错误码ID | 错误信息 | 1463| ------- | --------------------------------------------| 1464| 201 | Permission denied. | 1465| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.| 1466| 22700102 | Invalid parameter. | 1467 1468**示例:** 1469 1470```ts 1471import { BusinessError } from '@kit.BasicServicesKit'; 1472 1473if (enrollIntelligentVoiceEngine != null) { 1474 (enrollIntelligentVoiceEngine as intelligentVoice.EnrollIntelligentVoiceEngine).setSensibility(intelligentVoice.SensibilityType.LOW_SENSIBILITY, (err: BusinessError) => { 1475 if (err) { 1476 console.error(`Failed to set sensibility, Code:${err.code}, message:${err.message}`); 1477 } else { 1478 console.info(`Succeeded in setting sensibility.`); 1479 } 1480 }); 1481} 1482``` 1483 1484### setSensibility 1485 1486setSensibility(sensibility: SensibilityType): Promise\<void\> 1487 1488设置唤醒灵敏度,使用Promise异步回调。 1489 1490**需要权限:** ohos.permission.MANAGE_INTELLIGENT_VOICE 1491 1492**系统能力:** SystemCapability.AI.IntelligentVoice.Core 1493 1494**参数:** 1495 1496| 参数名 | 类型 | 必填 | 说明 | 1497| -------- | -------------------------------- | --- | ------------------------------------------- | 1498| sensibility | [SensibilityType](#sensibilitytype) | 是 | 灵敏度类型。 | 1499 1500**返回值:** 1501 1502| 类型 | 说明 | 1503| ----------------------------------------------- | ---------------------------- | 1504| Promise<void> | 无返回结果的Promise对象。 | 1505 1506**错误码:** 1507 1508以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[智能语音错误码](errorcode-intelligentVoice.md)。 1509 1510| 错误码ID | 错误信息 | 1511| ------- | --------------------------------------------| 1512| 201 | Permission denied. | 1513| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.| 1514| 22700102 | Invalid parameter. | 1515 1516**示例:** 1517 1518```ts 1519import { BusinessError } from '@kit.BasicServicesKit'; 1520 1521if (enrollIntelligentVoiceEngine != null) { 1522 (enrollIntelligentVoiceEngine as intelligentVoice.EnrollIntelligentVoiceEngine).setSensibility(intelligentVoice.SensibilityType.LOW_SENSIBILITY).then(() => { 1523 console.info(`Succeeded in setting sensibility.`); 1524 }).catch((err: BusinessError) => { 1525 console.error(`Failed to set sensibility, Code:${err.code}, message:${err.message}`); 1526 }); 1527} 1528``` 1529 1530### setParameter 1531 1532setParameter(key: string, value: string, callback: AsyncCallback\<void\>): void 1533 1534设置指定的智能语音参数,使用callback异步回调。 1535 1536**需要权限:** ohos.permission.MANAGE_INTELLIGENT_VOICE 1537 1538**系统能力:** SystemCapability.AI.IntelligentVoice.Core 1539 1540**参数:** 1541 1542| 参数名 | 类型 | 必填 | 说明 | 1543| -------- | -------------------------------- | --- | ------------------------------------------- | 1544| key | string | 是 | 键。 | 1545| value | string | 是 | 值。 | 1546| callback | AsyncCallback\<void\> | 是 | 返回设置智能语音参数的结果。 | 1547 1548**错误码:** 1549 1550以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[智能语音错误码](errorcode-intelligentVoice.md)。 1551 1552| 错误码ID | 错误信息 | 1553| ------- | --------------------------------------------| 1554| 201 | Permission denied. | 1555| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.| 1556| 22700102 | Invalid parameter. | 1557 1558**示例:** 1559 1560```ts 1561import { BusinessError } from '@kit.BasicServicesKit'; 1562 1563if (enrollIntelligentVoiceEngine != null) { 1564 (enrollIntelligentVoiceEngine as intelligentVoice.EnrollIntelligentVoiceEngine).setParameter('scene', '0', (err: BusinessError) => { 1565 if (err) { 1566 console.error(`Failed to set parameter, Code:${err.code}, message:${err.message}`); 1567 } else { 1568 console.info(`Succeeded in setting parameter`); 1569 } 1570 }); 1571} 1572``` 1573 1574### setParameter 1575 1576setParameter(key: string, value: string): Promise\<void\> 1577 1578设置指定的智能语音参数,使用Promise异步回调。 1579 1580**需要权限:** ohos.permission.MANAGE_INTELLIGENT_VOICE 1581 1582**系统能力:** SystemCapability.AI.IntelligentVoice.Core 1583 1584**参数:** 1585 1586| 参数名 | 类型 | 必填 | 说明 | 1587| -------- | -------------------------------- | --- | ------------------------------------------- | 1588| key | string | 是 | 键。 | 1589| value | string | 是 | 值。 | 1590 1591**返回值:** 1592 1593| 类型 | 说明 | 1594| ----------------------------------------------- | ---------------------------- | 1595| Promise<void> | 无返回结果的Promise对象。 | 1596 1597**错误码:** 1598 1599以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[智能语音错误码](errorcode-intelligentVoice.md)。 1600 1601| 错误码ID | 错误信息 | 1602| ------- | --------------------------------------------| 1603| 201 | Permission denied. | 1604| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.| 1605| 22700102 | Invalid parameter. | 1606 1607**示例:** 1608 1609```ts 1610import { BusinessError } from '@kit.BasicServicesKit'; 1611 1612if (enrollIntelligentVoiceEngine != null) { 1613 (enrollIntelligentVoiceEngine as intelligentVoice.EnrollIntelligentVoiceEngine).setParameter('scene', '0').then(() => { 1614 console.info(`Succeeded in setting parameter`); 1615 }).catch((err: BusinessError) => { 1616 console.error(`Failed to set parameter, Code:${err.code}, message:${err.message}`); 1617 }); 1618} 1619``` 1620 1621### getParameter 1622 1623getParameter(key: string, callback: AsyncCallback\<string\>): void 1624 1625获取指定的智能语音参数,使用callback异步回调。 1626 1627**需要权限:** ohos.permission.MANAGE_INTELLIGENT_VOICE 1628 1629**系统能力:** SystemCapability.AI.IntelligentVoice.Core 1630 1631**参数:** 1632 1633| 参数名 | 类型 | 必填 | 说明 | 1634| -------- | -------------------------------- | --- | ------------------------------------------- | 1635| key | string | 是 | 键。 | 1636| callback | AsyncCallback\<string\> | 是 | 返回智能语音参数。 | 1637 1638**错误码:** 1639 1640以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[智能语音错误码](errorcode-intelligentVoice.md)。 1641 1642| 错误码ID | 错误信息 | 1643| ------- | --------------------------------------------| 1644| 201 | Permission denied. | 1645| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.| 1646| 22700102 | Invalid parameter. | 1647 1648**示例:** 1649 1650```ts 1651import { BusinessError } from '@kit.BasicServicesKit'; 1652 1653if (enrollIntelligentVoiceEngine != null) { 1654 (enrollIntelligentVoiceEngine as intelligentVoice.EnrollIntelligentVoiceEngine).getParameter('key', (err: BusinessError, data: string) => { 1655 if (err) { 1656 console.error(`Failed to get parameter, Code:${err.code}, message:${err.message}`); 1657 } else { 1658 let param: string = data; 1659 console.info(`Succeeded in getting parameter, param:${param}`); 1660 } 1661 }); 1662} 1663``` 1664 1665### getParameter 1666 1667getParameter(key: string): Promise\<string\> 1668 1669获取指定的智能语音参数,使用Promise异步回调。 1670 1671**需要权限:** ohos.permission.MANAGE_INTELLIGENT_VOICE 1672 1673**系统能力:** SystemCapability.AI.IntelligentVoice.Core 1674 1675**参数:** 1676 1677| 参数名 | 类型 | 必填 | 说明 | 1678| -------- | -------------------------------- | --- | ------------------------------------------- | 1679| key | string | 是 | 键。 | 1680 1681**返回值:** 1682 1683| 类型 | 说明 | 1684| ----------------------------------------------- | ---------------------------- | 1685| Promise\<string\> | 返回智能语音参数。 | 1686 1687**错误码:** 1688 1689以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[智能语音错误码](errorcode-intelligentVoice.md)。 1690 1691| 错误码ID | 错误信息 | 1692| ------- | --------------------------------------------| 1693| 201 | Permission denied. | 1694| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.| 1695| 22700102 | Invalid parameter. | 1696 1697**示例:** 1698 1699```ts 1700import { BusinessError } from '@kit.BasicServicesKit'; 1701 1702if (enrollIntelligentVoiceEngine != null) { 1703 (enrollIntelligentVoiceEngine as intelligentVoice.EnrollIntelligentVoiceEngine).getParameter('key').then((data: string) => { 1704 let param: string = data; 1705 console.info(`Succeeded in getting parameter, param:${param}`); 1706 }).catch((err: BusinessError) => { 1707 console.error(`Failed to get parameter, Code:${err.code}, message:${err.message}`); 1708 }); 1709} 1710``` 1711 1712### evaluateForResult<sup>12+</sup> 1713 1714evaluateForResult(word: string): Promise\<EvaluationResult\> 1715 1716评估自定义唤醒词是否可用,使用Promise异步回调。 1717 1718**需要权限:** ohos.permission.MANAGE_INTELLIGENT_VOICE 1719 1720**系统能力:** SystemCapability.AI.IntelligentVoice.Core 1721 1722**参数:** 1723 1724| 参数名 | 类型 | 必填 | 说明 | 1725| -------- | -------------------------------- | --- | ------------------------------------------- | 1726| word | string | 是 | 自定义唤醒词。 | 1727 1728**返回值:** 1729 1730| 类型 | 说明 | 1731| ----------------------------------------------- | ---------------------------- | 1732| Promise<[EvaluationResult](#evaluationresult12)> | Promise对象,返回评估结果。 | 1733 1734**错误码:** 1735 1736以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[智能语音错误码](errorcode-intelligentVoice.md)。 1737 1738| 错误码ID | 错误信息 | 1739| ------- | --------------------------------------------| 1740| 201 | Permission denied. | 1741| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.| 1742| 22700107 | System error. | 1743 1744**示例:** 1745 1746```ts 1747import { BusinessError } from '@kit.BasicServicesKit'; 1748 1749if (enrollIntelligentVoiceEngine != null) { 1750 (enrollIntelligentVoiceEngine as intelligentVoice.EnrollIntelligentVoiceEngine).evaluateForResult('word').then( 1751 (data: intelligentVoice.EvaluationResult) => { 1752 let param: intelligentVoice.EvaluationResult = data; 1753 console.info(`Succeeded in evaluating, param:${param}`); 1754 }).catch((err: BusinessError) => { 1755 console.error(`Failed to evaluate, Code:${err.code}, message:${err.message}`); 1756 }); 1757} 1758``` 1759 1760### release 1761 1762release(callback: AsyncCallback<void>): void 1763 1764释放注册智能语音引擎,使用callback异步回调。 1765 1766**需要权限:** ohos.permission.MANAGE_INTELLIGENT_VOICE 1767 1768**系统能力:** SystemCapability.AI.IntelligentVoice.Core 1769 1770**参数:** 1771 1772| 参数名 | 类型 | 必填 | 说明 | 1773| -------- | -------------------------------- | --- | ------------------------------------------- | 1774| callback | AsyncCallback\<void\> | 是 | 返回释放注册引擎的结果。 | 1775 1776**错误码:** 1777 1778以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 1779 1780| 错误码ID | 错误信息 | 1781| ------- | --------------------------------------------| 1782| 201 | Permission denied. | 1783 1784**示例:** 1785 1786```ts 1787import { BusinessError } from '@kit.BasicServicesKit'; 1788 1789if (enrollIntelligentVoiceEngine != null) { 1790 (enrollIntelligentVoiceEngine as intelligentVoice.EnrollIntelligentVoiceEngine).release((err: BusinessError) => { 1791 if (err) { 1792 console.error(`Failed to release enrollIntelligentVoice engine, Code:${err.code}, message:${err.message}`); 1793 } else { 1794 console.info(`Succeeded in releasing enrollIntelligentVoice engine.`); 1795 } 1796 }); 1797} 1798``` 1799 1800### release 1801 1802release(): Promise<void> 1803 1804释放注册智能语音引擎,使用Promise异步回调。 1805 1806**需要权限:** ohos.permission.MANAGE_INTELLIGENT_VOICE 1807 1808**系统能力:** SystemCapability.AI.IntelligentVoice.Core 1809 1810**返回值:** 1811 1812| 类型 | 说明 | 1813| ----------------------------------------------- | ---------------------------- | 1814| Promise<void> | 无返回结果的Promise对象。 | 1815 1816**错误码:** 1817 1818以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 1819 1820| 错误码ID | 错误信息 | 1821| ------- | --------------------------------------------| 1822| 201 | Permission denied. | 1823 1824**示例:** 1825 1826```ts 1827import { BusinessError } from '@kit.BasicServicesKit'; 1828 1829if (enrollIntelligentVoiceEngine != null) { 1830 (enrollIntelligentVoiceEngine as intelligentVoice.EnrollIntelligentVoiceEngine).release().then(() => { 1831 console.info(`Succeeded in releasing enrollIntelligentVoice engine.`); 1832 }).catch((err: BusinessError) => { 1833 console.error(`Failed to release enrollIntelligentVoice engine, Code:${err.code}, message:${err.message}`); 1834 }); 1835} 1836``` 1837 1838## WakeupIntelligentVoiceEngine 1839 1840实现唤醒智能语音引擎,通过[createWakeupIntelligentVoiceEngine()](#intelligentvoicecreatewakeupintelligentvoiceengine)获取唤醒智能语音引擎。 1841 1842### getSupportedRegions 1843 1844getSupportedRegions(callback: AsyncCallback<Array<string>>): void 1845 1846获取支持的区域,使用callback异步回调。 1847 1848**需要权限:** ohos.permission.MANAGE_INTELLIGENT_VOICE 1849 1850**系统能力:** SystemCapability.AI.IntelligentVoice.Core 1851 1852| 参数名 | 类型 | 必填 | 说明 | 1853| -------- | -------------------------------- | --- | ------------------------------------------- | 1854| callback | AsyncCallback<Array<string>> | 是 | 返回支持区域的数组,当前只支持中国,对应取值为'CN'。 | 1855 1856**错误码:** 1857 1858以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 1859 1860| 错误码ID | 错误信息 | 1861| ------- | --------------------------------------------| 1862| 201 | Permission denied. | 1863 1864**示例:** 1865 1866```ts 1867import { BusinessError } from '@kit.BasicServicesKit'; 1868 1869if (wakeupIntelligentVoiceEngine != null) { 1870 (wakeupIntelligentVoiceEngine as intelligentVoice.WakeupIntelligentVoiceEngine).getSupportedRegions((err: BusinessError, data: Array<string>) => { 1871 if (err) { 1872 console.error(`Failed to get supported regions, Code:${err.code}, message:${err.message}`); 1873 } else { 1874 let regions: Array<string> = data; 1875 console.info(`Succeeded in getting supported regions, regions:${regions}.`); 1876 } 1877 }); 1878} 1879``` 1880 1881### getSupportedRegions 1882 1883getSupportedRegions(): Promise<Array<string>> 1884 1885获取支持的区域,使用Promise异步回调。 1886 1887**需要权限:** ohos.permission.MANAGE_INTELLIGENT_VOICE 1888 1889**系统能力:** SystemCapability.AI.IntelligentVoice.Core 1890 1891**返回值:** 1892 1893| 类型 | 说明 | 1894| ----------------------------------------------- | ---------------------------- | 1895| Promise<Array<string>> | 返回支持区域的数组,当前只支持中国,对应取值为'CN'。 | 1896 1897**错误码:** 1898 1899以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 1900 1901| 错误码ID | 错误信息 | 1902| ------- | --------------------------------------------| 1903| 201 | Permission denied. | 1904 1905**示例:** 1906 1907```ts 1908import { BusinessError } from '@kit.BasicServicesKit'; 1909 1910if (wakeupIntelligentVoiceEngine != null) { 1911 (wakeupIntelligentVoiceEngine as intelligentVoice.WakeupIntelligentVoiceEngine).getSupportedRegions().then((data: Array<string>) => { 1912 let regions: Array<string> = data; 1913 console.info(`Succeeded in getting supported regions, regions:${regions}.`); 1914 }).catch((err: BusinessError) => { 1915 console.error(`Failed to get supported regions, Code:${err.code}, message:${err.message}`); 1916 }); 1917} 1918``` 1919 1920### setWakeupHapInfo 1921 1922setWakeupHapInfo(info: WakeupHapInfo, callback: AsyncCallback\<void\>): void 1923 1924设置唤醒应用的hap信息,使用callback异步回调。 1925 1926**需要权限:** ohos.permission.MANAGE_INTELLIGENT_VOICE 1927 1928**系统能力:** SystemCapability.AI.IntelligentVoice.Core 1929 1930**参数:** 1931 1932| 参数名 | 类型 | 必填 | 说明 | 1933| -------- | -------------------------------- | --- | ------------------------------------------- | 1934| info | [WakeupHapInfo](#wakeuphapinfo) | 是 | 唤醒hap信息。 | 1935| callback | AsyncCallback\<void\> | 是 | 返回设置唤醒hap信息的结果。 | 1936 1937**错误码:** 1938 1939以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[智能语音错误码](errorcode-intelligentVoice.md)。 1940 1941| 错误码ID | 错误信息 | 1942| ------- | --------------------------------------------| 1943| 201 | Permission denied. | 1944| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.| 1945| 22700102 | Invalid parameter. | 1946 1947**示例:** 1948 1949```ts 1950import { BusinessError } from '@kit.BasicServicesKit'; 1951 1952let hapInfo: intelligentVoice.WakeupHapInfo = { 1953 bundleName: 'com.wakeup', 1954 abilityName: 'WakeUpExtAbility', 1955} 1956 1957if (wakeupIntelligentVoiceEngine != null) { 1958 (wakeupIntelligentVoiceEngine as intelligentVoice.WakeupIntelligentVoiceEngine).setWakeupHapInfo(hapInfo, (err: BusinessError) => { 1959 if (err) { 1960 console.error(`Failed to set wakeup hap info, Code:${err.code}, message:${err.message}`); 1961 } else { 1962 console.info(`Succeeded in setting wakeup hap info.`); 1963 } 1964 }); 1965} 1966``` 1967 1968### setWakeupHapInfo 1969 1970setWakeupHapInfo(info: WakeupHapInfo): Promise\<void\> 1971 1972设置唤醒应用的hap信息,使用promise异步回调。 1973 1974**需要权限:** ohos.permission.MANAGE_INTELLIGENT_VOICE 1975 1976**系统能力:** SystemCapability.AI.IntelligentVoice.Core 1977 1978**参数:** 1979 1980| 参数名 | 类型 | 必填 | 说明 | 1981| -------- | -------------------------------- | --- | ------------------------------------------- | 1982| info | [WakeupHapInfo](#wakeuphapinfo) | 是 | 唤醒hap信息。 | 1983 1984**返回值:** 1985 1986| 类型 | 说明 | 1987| ----------------------------------------------- | ---------------------------- | 1988| Promise<void> | 无返回结果的Promise对象。 | 1989 1990**错误码:** 1991 1992以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[智能语音错误码](errorcode-intelligentVoice.md)。 1993 1994| 错误码ID | 错误信息 | 1995| ------- | --------------------------------------------| 1996| 201 | Permission denied. | 1997| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.| 1998| 22700102 | Invalid parameter. | 1999 2000**示例:** 2001 2002```ts 2003import { BusinessError } from '@kit.BasicServicesKit'; 2004 2005let hapInfo: intelligentVoice.WakeupHapInfo = { 2006 bundleName: 'com.wakeup', 2007 abilityName: 'WakeUpExtAbility', 2008} 2009if (wakeupIntelligentVoiceEngine != null) { 2010 (wakeupIntelligentVoiceEngine as intelligentVoice.WakeupIntelligentVoiceEngine).setWakeupHapInfo(hapInfo).then(() => { 2011 console.info(`Succeeded in setting wakeup hap info.`); 2012 }).catch((err: BusinessError) => { 2013 console.error(`Failed to set wakeup hap info, Code:${err.code}, message:${err.message}`); 2014 }); 2015} 2016``` 2017 2018### setSensibility 2019 2020setSensibility(sensibility: SensibilityType, callback: AsyncCallback\<void\>): void 2021 2022设置唤醒灵敏度,使用callback异步回调。 2023 2024**需要权限:** ohos.permission.MANAGE_INTELLIGENT_VOICE 2025 2026**系统能力:** SystemCapability.AI.IntelligentVoice.Core 2027 2028**参数:** 2029 2030| 参数名 | 类型 | 必填 | 说明 | 2031| -------- | -------------------------------- | --- | ------------------------------------------- | 2032| sensibility | [SensibilityType](#sensibilitytype) | 是 | 灵敏度类型。 | 2033| callback | AsyncCallback\<void\> | 是 | 返回设置灵敏度的结果。 | 2034 2035**错误码:** 2036 2037以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[智能语音错误码](errorcode-intelligentVoice.md)。 2038 2039| 错误码ID | 错误信息 | 2040| ------- | --------------------------------------------| 2041| 201 | Permission denied. | 2042| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.| 2043| 22700102 | Invalid parameter. | 2044 2045**示例:** 2046 2047```ts 2048import { BusinessError } from '@kit.BasicServicesKit'; 2049 2050if (wakeupIntelligentVoiceEngine != null) { 2051 (wakeupIntelligentVoiceEngine as intelligentVoice.WakeupIntelligentVoiceEngine).setSensibility(intelligentVoice.SensibilityType.LOW_SENSIBILITY, (err: BusinessError) => { 2052 if (err) { 2053 console.error(`Failed to set sensibility, Code:${err.code}, message:${err.message}`); 2054 } else { 2055 console.info(`Succeeded in setting sensibility.`); 2056 } 2057 }); 2058} 2059``` 2060 2061### setSensibility 2062 2063setSensibility(sensibility: SensibilityType): Promise\<void\> 2064 2065设置唤醒灵敏度,使用Promise异步回调。 2066 2067**需要权限:** ohos.permission.MANAGE_INTELLIGENT_VOICE 2068 2069**系统能力:** SystemCapability.AI.IntelligentVoice.Core 2070 2071**参数:** 2072 2073| 参数名 | 类型 | 必填 | 说明 | 2074| -------- | -------------------------------- | --- | ------------------------------------------- | 2075| sensibility | [SensibilityType](#sensibilitytype) | 是 | 灵敏度类型。 | 2076 2077**返回值:** 2078 2079| 类型 | 说明 | 2080| ----------------------------------------------- | ---------------------------- | 2081| Promise<void> | 无返回结果的Promise对象。 | 2082 2083**错误码:** 2084 2085以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[智能语音错误码](errorcode-intelligentVoice.md)。 2086 2087| 错误码ID | 错误信息 | 2088| ------- | --------------------------------------------| 2089| 201 | Permission denied. | 2090| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.| 2091| 22700102 | Invalid parameter. | 2092 2093**示例:** 2094 2095```ts 2096import { BusinessError } from '@kit.BasicServicesKit'; 2097 2098if (wakeupIntelligentVoiceEngine != null) { 2099 (wakeupIntelligentVoiceEngine as intelligentVoice.WakeupIntelligentVoiceEngine).setSensibility(intelligentVoice.SensibilityType.LOW_SENSIBILITY).then(() => { 2100 console.info(`Succeeded in setting sensibility.`); 2101 }).catch((err: BusinessError) => { 2102 console.error(`Failed to set sensibility, Code:${err.code}, message:${err.message}`); 2103 }); 2104} 2105``` 2106 2107### setParameter 2108 2109setParameter(key: string, value: string, callback: AsyncCallback\<void\>): void 2110 2111设置指定的智能语音参数,使用callback异步回调。 2112 2113**需要权限:** ohos.permission.MANAGE_INTELLIGENT_VOICE 2114 2115**系统能力:** SystemCapability.AI.IntelligentVoice.Core 2116 2117**参数:** 2118 2119| 参数名 | 类型 | 必填 | 说明 | 2120| -------- | -------------------------------- | --- | ------------------------------------------- | 2121| key | string | 是 | 键。 | 2122| value | string | 是 | 值。 | 2123| callback | AsyncCallback\<void\> | 是 | 返回设置智能语音参数的结果。 | 2124 2125**错误码:** 2126 2127以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[智能语音错误码](errorcode-intelligentVoice.md)。 2128 2129| 错误码ID | 错误信息 | 2130| ------- | --------------------------------------------| 2131| 201 | Permission denied. | 2132| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.| 2133| 22700102 | Invalid parameter. | 2134 2135**示例:** 2136 2137```ts 2138import { BusinessError } from '@kit.BasicServicesKit'; 2139 2140if (wakeupIntelligentVoiceEngine != null) { 2141 (wakeupIntelligentVoiceEngine as intelligentVoice.WakeupIntelligentVoiceEngine).setParameter('scene', '0', (err: BusinessError) => { 2142 if (err) { 2143 console.error(`Failed to set parameter, Code:${err.code}, message:${err.message}`); 2144 } else { 2145 console.info(`Succeeded in setting parameter`); 2146 } 2147 }); 2148} 2149``` 2150 2151### setParameter 2152 2153setParameter(key: string, value: string): Promise\<void\> 2154 2155设置指定的智能语音参数,使用Promise异步回调。 2156 2157**需要权限:** ohos.permission.MANAGE_INTELLIGENT_VOICE 2158 2159**系统能力:** SystemCapability.AI.IntelligentVoice.Core 2160 2161**参数:** 2162 2163| 参数名 | 类型 | 必填 | 说明 | 2164| -------- | -------------------------------- | --- | ------------------------------------------- | 2165| key | string | 是 | 键。 | 2166| value | string | 是 | 值。 | 2167 2168**返回值:** 2169 2170| 类型 | 说明 | 2171| ----------------------------------------------- | ---------------------------- | 2172| Promise<void> | 无返回结果的Promise对象。 | 2173 2174**错误码:** 2175 2176以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[智能语音错误码](errorcode-intelligentVoice.md)。 2177 2178| 错误码ID | 错误信息 | 2179| ------- | --------------------------------------------| 2180| 201 | Permission denied. | 2181| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.| 2182| 22700102 | Invalid parameter. | 2183 2184**示例:** 2185 2186```ts 2187import { BusinessError } from '@kit.BasicServicesKit'; 2188 2189if (wakeupIntelligentVoiceEngine != null) { 2190 (wakeupIntelligentVoiceEngine as intelligentVoice.WakeupIntelligentVoiceEngine).setParameter('scene', '0').then(() => { 2191 console.info(`Succeeded in setting parameter`); 2192 }).catch((err: BusinessError) => { 2193 console.error(`Failed to set parameter, Code:${err.code}, message:${err.message}`); 2194 }); 2195} 2196``` 2197 2198### getParameter 2199 2200getParameter(key: string, callback: AsyncCallback\<string\>): void 2201 2202获取指定的智能语音参数,使用callback异步回调。 2203 2204**需要权限:** ohos.permission.MANAGE_INTELLIGENT_VOICE 2205 2206**系统能力:** SystemCapability.AI.IntelligentVoice.Core 2207 2208**参数:** 2209 2210| 参数名 | 类型 | 必填 | 说明 | 2211| -------- | -------------------------------- | --- | ------------------------------------------- | 2212| key | string | 是 | 键。 | 2213| callback | AsyncCallback\<string\> | 是 | 返回智能语音参数。 | 2214 2215**错误码:** 2216 2217以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[智能语音错误码](errorcode-intelligentVoice.md)。 2218 2219| 错误码ID | 错误信息 | 2220| ------- | --------------------------------------------| 2221| 201 | Permission denied. | 2222| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.| 2223| 22700102 | Invalid parameter. | 2224 2225**示例:** 2226 2227```ts 2228import { BusinessError } from '@kit.BasicServicesKit'; 2229 2230if (wakeupIntelligentVoiceEngine != null) { 2231 (wakeupIntelligentVoiceEngine as intelligentVoice.WakeupIntelligentVoiceEngine).getParameter('key', (err: BusinessError, data: string) => { 2232 if (err) { 2233 console.error(`Failed to get parameter, Code:${err.code}, message:${err.message}`); 2234 } else { 2235 let param: string = data; 2236 console.info(`Succeeded in getting parameter, param:${param}`); 2237 } 2238 }); 2239} 2240``` 2241 2242### getParameter 2243 2244getParameter(key: string): Promise\<string\> 2245 2246获取指定的智能语音参数,使用Promise异步回调。 2247 2248**需要权限:** ohos.permission.MANAGE_INTELLIGENT_VOICE 2249 2250**系统能力:** SystemCapability.AI.IntelligentVoice.Core 2251 2252**参数:** 2253 2254| 参数名 | 类型 | 必填 | 说明 | 2255| -------- | -------------------------------- | --- | ------------------------------------------- | 2256| key | string | 是 | 键。 | 2257 2258**返回值:** 2259 2260| 类型 | 说明 | 2261| ----------------------------------------------- | ---------------------------- | 2262| Promise\<string\> | 返回智能语音参数。 | 2263 2264**错误码:** 2265 2266以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[智能语音错误码](errorcode-intelligentVoice.md)。 2267 2268| 错误码ID | 错误信息 | 2269| ------- | --------------------------------------------| 2270| 201 | Permission denied. | 2271| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.| 2272| 22700102 | Invalid parameter. | 2273 2274**示例:** 2275 2276```ts 2277import { BusinessError } from '@kit.BasicServicesKit'; 2278 2279if (wakeupIntelligentVoiceEngine != null) { 2280 (wakeupIntelligentVoiceEngine as intelligentVoice.WakeupIntelligentVoiceEngine).getParameter('key').then((data: string) => { 2281 let param: string = data; 2282 console.info(`Succeeded in getting parameter, param:${param}`); 2283 }).catch((err: BusinessError) => { 2284 console.error(`Failed to get parameter, Code:${err.code}, message:${err.message}`); 2285 }); 2286} 2287``` 2288 2289### getPcm<sup>12+</sup> 2290 2291getPcm(): Promise\<ArrayBuffer\> 2292 2293获取脉冲编码调制音频,使用Promise异步回调。 2294 2295**需要权限:** ohos.permission.MANAGE_INTELLIGENT_VOICE 2296 2297**系统能力:** SystemCapability.AI.IntelligentVoice.Core 2298 2299**返回值:** 2300 2301| 类型 | 说明 | 2302| ----------------------------------------------- | ---------------------------- | 2303| Promise\<ArrayBuffer\> | Promise对象,返回脉冲编码调制音频。 | 2304 2305**错误码:** 2306 2307以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[智能语音错误码](errorcode-intelligentVoice.md)。 2308 2309| 错误码ID | 错误信息 | 2310| ------- | --------------------------------------------| 2311| 201 | Permission denied. | 2312| 22700101 | No memory. | 2313| 22700107 | System error. | 2314 2315**示例:** 2316 2317```ts 2318import { BusinessError } from '@kit.BasicServicesKit'; 2319 2320if (wakeupIntelligentVoiceEngine != null) { 2321 (wakeupIntelligentVoiceEngine as intelligentVoice.WakeupIntelligentVoiceEngine).getPcm().then((data: ArrayBuffer) => { 2322 let param: ArrayBuffer = data; 2323 console.info(`Succeeded in getting pcm, param:${param}`); 2324 }).catch((err: BusinessError) => { 2325 console.error(`Failed to get pcm, Code:${err.code}, message:${err.message}`); 2326 }); 2327} 2328``` 2329 2330### startCapturer<sup>12+</sup> 2331 2332startCapturer(channels: number): Promise\<void\> 2333 2334启动捕获器,使用Promise异步回调。 2335 2336**需要权限:** ohos.permission.MANAGE_INTELLIGENT_VOICE 2337 2338**系统能力:** SystemCapability.AI.IntelligentVoice.Core 2339 2340**参数:** 2341 2342| 参数名 | 类型 | 必填 | 说明 | 2343| -------- | -------------------------------- | --- | ------------------------------------------- | 2344| channels | number | 是 | 声道数。 | 2345 2346**返回值:** 2347 2348| 类型 | 说明 | 2349| ----------------------------------------------- | ---------------------------- | 2350| Promise\<void\> | Promise对象,无返回结果。 | 2351 2352**错误码:** 2353 2354以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[智能语音错误码](errorcode-intelligentVoice.md)。 2355 2356| 错误码ID | 错误信息 | 2357| ------- | --------------------------------------------| 2358| 201 | Permission denied. | 2359| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified. 2. Incorrect parameter types.| 2360| 22700102 | Invalid parameter. | 2361| 22700105 | Start capturer failed. | 2362| 22700107 | System error. | 2363 2364**示例:** 2365 2366```ts 2367import { BusinessError } from '@kit.BasicServicesKit'; 2368 2369if (wakeupIntelligentVoiceEngine != null) { 2370 (wakeupIntelligentVoiceEngine as intelligentVoice.WakeupIntelligentVoiceEngine).startCapturer(1).then(() => { 2371 console.info(`Succeeded in starting capturer`); 2372 }).catch((err: BusinessError) => { 2373 console.error(`Failed to start capturer, Code:${err.code}, message:${err.message}`); 2374 }); 2375} 2376``` 2377 2378### read<sup>12+</sup> 2379 2380read(): Promise\<ArrayBuffer\> 2381 2382读取数据,使用Promise异步回调。 2383 2384**需要权限:** ohos.permission.MANAGE_INTELLIGENT_VOICE 2385 2386**系统能力:** SystemCapability.AI.IntelligentVoice.Core 2387 2388**返回值:** 2389 2390| 类型 | 说明 | 2391| ----------------------------------------------- | ---------------------------- | 2392| Promise\<ArrayBuffer\> | Promise对象,返回音频数据结果。 | 2393 2394**错误码:** 2395 2396以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[智能语音错误码](errorcode-intelligentVoice.md)。 2397 2398| 错误码ID | 错误信息 | 2399| ------- | --------------------------------------------| 2400| 201 | Permission denied. | 2401| 22700101 | No memory. | 2402| 22700106 | Read failed. | 2403| 22700107 | System error. | 2404 2405**示例:** 2406 2407```ts 2408import { BusinessError } from '@kit.BasicServicesKit'; 2409 2410if (wakeupIntelligentVoiceEngine != null) { 2411 (wakeupIntelligentVoiceEngine as intelligentVoice.WakeupIntelligentVoiceEngine).read().then((data: ArrayBuffer) => { 2412 let param: ArrayBuffer = data; 2413 console.info(`Succeeded in reading data, param:${param}`); 2414 }).catch((err: BusinessError) => { 2415 console.error(`Failed to read data, Code:${err.code}, message:${err.message}`); 2416 }); 2417} 2418``` 2419 2420### stopCapturer<sup>12+</sup> 2421 2422stopCapturer(): Promise\<void\> 2423 2424停止捕获器,使用Promise异步回调。 2425 2426**需要权限:** ohos.permission.MANAGE_INTELLIGENT_VOICE 2427 2428**系统能力:** SystemCapability.AI.IntelligentVoice.Core 2429 2430**返回值:** 2431 2432| 类型 | 说明 | 2433| ----------------------------------------------- | ---------------------------- | 2434| Promise\<void\> | Promise对象,无返回结果。 | 2435 2436**错误码:** 2437 2438以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[智能语音错误码](errorcode-intelligentVoice.md)。 2439 2440| 错误码ID | 错误信息 | 2441| ------- | --------------------------------------------| 2442| 201 | Permission denied. | 2443| 22700107 | System error. | 2444 2445**示例:** 2446 2447```ts 2448import { BusinessError } from '@kit.BasicServicesKit'; 2449 2450if (wakeupIntelligentVoiceEngine != null) { 2451 (wakeupIntelligentVoiceEngine as intelligentVoice.WakeupIntelligentVoiceEngine).stopCapturer().then(() => { 2452 console.info(`Succeeded in stopping capturer`); 2453 }).catch((err: BusinessError) => { 2454 console.error(`Failed to stop capturer, Code:${err.code}, message:${err.message}`); 2455 }); 2456} 2457``` 2458 2459### release 2460 2461release(callback: AsyncCallback\<void\>): void 2462 2463释放唤醒智能语音引擎,使用callback异步回调。 2464 2465**需要权限:** ohos.permission.MANAGE_INTELLIGENT_VOICE 2466 2467**系统能力:** SystemCapability.AI.IntelligentVoice.Core 2468 2469**参数:** 2470 2471| 参数名 | 类型 | 必填 | 说明 | 2472| -------- | -------------------------------- | --- | ------------------------------------------- | 2473| callback | AsyncCallback\<void\> | 是 | 返回释放唤醒引擎的结果。 | 2474 2475**错误码:** 2476 2477以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 2478 2479| 错误码ID | 错误信息 | 2480| ------- | --------------------------------------------| 2481| 201 | Permission denied. | 2482 2483**示例:** 2484 2485```ts 2486import { BusinessError } from '@kit.BasicServicesKit'; 2487 2488if (wakeupIntelligentVoiceEngine != null) { 2489 (wakeupIntelligentVoiceEngine as intelligentVoice.WakeupIntelligentVoiceEngine).release((err: BusinessError) => { 2490 if (err) { 2491 console.error(`Failed to release wakeupIntelligentVoice engine, Code:${err.code}, message:${err.message}`); 2492 } else { 2493 console.info(`Succeeded in releasing wakeupIntelligentVoice engine.`); 2494 } 2495 }); 2496} 2497``` 2498 2499### release 2500 2501release(): Promise\<void\> 2502 2503释放唤醒智能语音引擎,使用Promise异步回调。 2504 2505**需要权限:** ohos.permission.MANAGE_INTELLIGENT_VOICE 2506 2507**系统能力:** SystemCapability.AI.IntelligentVoice.Core 2508 2509**返回值:** 2510 2511| 类型 | 说明 | 2512| ----------------------------------------------- | ---------------------------- | 2513| Promise<void> | 无返回结果的Promise对象。 | 2514 2515**错误码:** 2516 2517以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 2518 2519| 错误码ID | 错误信息 | 2520| ------- | --------------------------------------------| 2521| 201 | Permission denied. | 2522 2523**示例:** 2524 2525```ts 2526import { BusinessError } from '@kit.BasicServicesKit'; 2527 2528if (wakeupIntelligentVoiceEngine != null) { 2529 (wakeupIntelligentVoiceEngine as intelligentVoice.WakeupIntelligentVoiceEngine).release().then(() => { 2530 console.info(`Succeeded in releasing wakeupIntelligentVoice engine.`); 2531 }).catch((err: BusinessError) => { 2532 console.error(`Failed to release wakeupIntelligentVoice engine, Code:${err.code}, message:${err.message}`); 2533 }); 2534} 2535``` 2536 2537### on 2538 2539on(type: 'wakeupIntelligentVoiceEvent', callback: Callback\<WakeupIntelligentVoiceEngineCallbackInfo\>): void 2540 2541订阅唤醒事件。 2542 2543**需要权限:** ohos.permission.MANAGE_INTELLIGENT_VOICE 2544 2545**系统能力:** SystemCapability.AI.IntelligentVoice.Core 2546 2547**参数:** 2548 2549| 参数名 | 类型 | 必填 | 说明 | 2550| -------- | -------------------------------- | --- | ------------------------------------------- | 2551| type | string | 是 | 唤醒智能语音事件,固定取为'wakeupIntelligentVoiceEvent',表示智能语音唤醒事件。 | 2552| callback | Callback\<[WakeupIntelligentVoiceEngineCallbackInfo](#wakeupintelligentvoiceenginecallbackinfo)\> | 是 | 收到唤醒事件的对应处理。 | 2553 2554**错误码:** 2555 2556以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 2557 2558| 错误码ID | 错误信息 | 2559| ------- | --------------------------------------------| 2560| 201 | Permission denied. | 2561 2562**示例:** 2563 2564```ts 2565if (wakeupIntelligentVoiceEngine != null) { 2566 (wakeupIntelligentVoiceEngine as intelligentVoice.WakeupIntelligentVoiceEngine).on('wakeupIntelligentVoiceEvent', 2567 (info: intelligentVoice.WakeupIntelligentVoiceEngineCallbackInfo) => { 2568 let callbackInfo: intelligentVoice.WakeupIntelligentVoiceEngineCallbackInfo = info; 2569 console.info(`wakeup intelligentvoice event, info:${callbackInfo}`); 2570 }); 2571} 2572``` 2573 2574### off 2575 2576off(type: 'wakeupIntelligentVoiceEvent', callback?: Callback\<WakeupIntelligentVoiceEngineCallbackInfo\>): void; 2577 2578取消订阅唤醒事件。 2579 2580**需要权限:** ohos.permission.MANAGE_INTELLIGENT_VOICE 2581 2582**系统能力:** SystemCapability.AI.IntelligentVoice.Core 2583 2584**参数:** 2585 2586| 参数名 | 类型 | 必填 | 说明 | 2587| -------- | -------------------------------- | --- | ------------------------------------------- | 2588| type |string | 是 | 唤醒智能语音事件,固定取为'wakeupIntelligentVoiceEvent'。 | 2589| callback | Callback\<[WakeupIntelligentVoiceEngineCallbackInfo](#wakeupintelligentvoiceenginecallbackinfo)\> | 否 | 收到唤醒事件的对应处理。无参数,则取消所有的订阅,否则,取消对应的订阅 | 2590 2591**错误码:** 2592 2593以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 2594 2595| 错误码ID | 错误信息 | 2596| ------- | --------------------------------------------| 2597| 201 | Permission denied. | 2598 2599**示例:** 2600 2601```ts 2602if (wakeupIntelligentVoiceEngine != null) { 2603 (wakeupIntelligentVoiceEngine as intelligentVoice.WakeupIntelligentVoiceEngine).off('wakeupIntelligentVoiceEvent'); 2604} 2605``` 2606