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