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