1# @ohos.ai.intelligentVoice (智能语音)(系统接口) 2 3智能语音主要提供了语音注册及语音唤醒相关功能。 4 5该模块提供以下智能语音相关的常用功能: 6 7- [IntelligentVoiceManager](#intelligentvoicemanager):智能语音管理类,明确当前智能语音提供的相关功能,当前支持语音注册、语音唤醒。在进行智能语音相关开发前,需先调用[getIntelligentVoiceManager()](#intelligentvoicegetintelligentvoicemanager)确认当前支持智能语音的相关功能,再进行语音注册和语音唤醒的相关开发。 8- [EnrollIntelligentVoiceEngine](#enrollintelligentvoiceengine):实现语音注册。开发者需要先进行智能语音的注册,然后才能进行唤醒。 9- [WakeupIntelligentVoiceEngine](#wakeupintelligentvoiceengine):实现语音唤醒。开发者需要先进行智能语音的注册,然后才能进行唤醒。 10 11> **说明:** 12> 13> - 本模块首批接口从API version 10开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 14> 15> - 本模块接口为系统接口。 16> 17> - @ohos.ai.intelligentVoice归属的Kit已由'MindSpore Lite Kit'变更为'Basic Services Kit',请开发者使用新模块名'@kit.BasicServicesKit'完成模块导入。如果使用'@kit.MindSporeLiteKit'导入,将无法使用本模块的接口。 18 19## 导入模块 20```ts 21import { intelligentVoice } from '@kit.BasicServicesKit'; 22``` 23 24## intelligentVoice.getIntelligentVoiceManager 25 26getIntelligentVoiceManager(): IntelligentVoiceManager 27 28获取智能语音管理类。 29 30**需要权限:** ohos.permission.MANAGE_INTELLIGENT_VOICE 31 32**系统能力:** SystemCapability.AI.IntelligentVoice.Core 33 34**返回值:** 35 36| 类型 | 说明 | 37| ----------------------------- | ------------ | 38| [IntelligentVoiceManager](#intelligentvoicemanager) | 智能语音管理类。 | 39 40**错误码:** 41 42以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[智能语音错误码](errorcode-intelligentVoice.md)。 43 44| 错误码ID | 错误信息 | 45| ------- | --------------------------------------------| 46| 201 | Permission denied. | 47| 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 | 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| Promise<void> | 无返回结果的Promise对象。 | 1438 1439**错误码:** 1440 1441以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[智能语音错误码](errorcode-intelligentVoice.md)。 1442 1443| 错误码ID | 错误信息 | 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**示例:** 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 1472设置唤醒灵敏度,使用callback异步回调。 1473 1474**需要权限:** ohos.permission.MANAGE_INTELLIGENT_VOICE 1475 1476**系统能力:** SystemCapability.AI.IntelligentVoice.Core 1477 1478**参数:** 1479 1480| 参数名 | 类型 | 必填 | 说明 | 1481| -------- | -------------------------------- | --- | ------------------------------------------- | 1482| sensibility | [SensibilityType](#sensibilitytype) | 是 | 灵敏度类型。 | 1483| callback | AsyncCallback\<void\> | 是 | 返回设置灵敏度的结果。 | 1484 1485**错误码:** 1486 1487以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[智能语音错误码](errorcode-intelligentVoice.md)。 1488 1489| 错误码ID | 错误信息 | 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**示例:** 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 1516设置唤醒灵敏度,使用Promise异步回调。 1517 1518**需要权限:** ohos.permission.MANAGE_INTELLIGENT_VOICE 1519 1520**系统能力:** SystemCapability.AI.IntelligentVoice.Core 1521 1522**参数:** 1523 1524| 参数名 | 类型 | 必填 | 说明 | 1525| -------- | -------------------------------- | --- | ------------------------------------------- | 1526| sensibility | [SensibilityType](#sensibilitytype) | 是 | 灵敏度类型。 | 1527 1528**返回值:** 1529 1530| 类型 | 说明 | 1531| ----------------------------------------------- | ---------------------------- | 1532| Promise<void> | 无返回结果的Promise对象。 | 1533 1534**错误码:** 1535 1536以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[智能语音错误码](errorcode-intelligentVoice.md)。 1537 1538| 错误码ID | 错误信息 | 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**示例:** 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 1563设置指定的智能语音参数,使用callback异步回调。 1564 1565**需要权限:** ohos.permission.MANAGE_INTELLIGENT_VOICE 1566 1567**系统能力:** SystemCapability.AI.IntelligentVoice.Core 1568 1569**参数:** 1570 1571| 参数名 | 类型 | 必填 | 说明 | 1572| -------- | -------------------------------- | --- | ------------------------------------------- | 1573| key | string | 是 | 键。 | 1574| value | string | 是 | 值。 | 1575| callback | AsyncCallback\<void\> | 是 | 返回设置智能语音参数的结果。 | 1576 1577**错误码:** 1578 1579以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[智能语音错误码](errorcode-intelligentVoice.md)。 1580 1581| 错误码ID | 错误信息 | 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**示例:** 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 1608设置指定的智能语音参数,使用Promise异步回调。 1609 1610**需要权限:** ohos.permission.MANAGE_INTELLIGENT_VOICE 1611 1612**系统能力:** SystemCapability.AI.IntelligentVoice.Core 1613 1614**参数:** 1615 1616| 参数名 | 类型 | 必填 | 说明 | 1617| -------- | -------------------------------- | --- | ------------------------------------------- | 1618| key | string | 是 | 键。 | 1619| value | string | 是 | 值。 | 1620 1621**返回值:** 1622 1623| 类型 | 说明 | 1624| ----------------------------------------------- | ---------------------------- | 1625| Promise<void> | 无返回结果的Promise对象。 | 1626 1627**错误码:** 1628 1629以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[智能语音错误码](errorcode-intelligentVoice.md)。 1630 1631| 错误码ID | 错误信息 | 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**示例:** 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 1656获取指定的智能语音参数,使用callback异步回调。 1657 1658**需要权限:** ohos.permission.MANAGE_INTELLIGENT_VOICE 1659 1660**系统能力:** SystemCapability.AI.IntelligentVoice.Core 1661 1662**参数:** 1663 1664| 参数名 | 类型 | 必填 | 说明 | 1665| -------- | -------------------------------- | --- | ------------------------------------------- | 1666| key | string | 是 | 键。 | 1667| callback | AsyncCallback\<string\> | 是 | 返回智能语音参数。 | 1668 1669**错误码:** 1670 1671以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[智能语音错误码](errorcode-intelligentVoice.md)。 1672 1673| 错误码ID | 错误信息 | 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**示例:** 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 1701获取指定的智能语音参数,使用Promise异步回调。 1702 1703**需要权限:** ohos.permission.MANAGE_INTELLIGENT_VOICE 1704 1705**系统能力:** SystemCapability.AI.IntelligentVoice.Core 1706 1707**参数:** 1708 1709| 参数名 | 类型 | 必填 | 说明 | 1710| -------- | -------------------------------- | --- | ------------------------------------------- | 1711| key | string | 是 | 键。 | 1712 1713**返回值:** 1714 1715| 类型 | 说明 | 1716| ----------------------------------------------- | ---------------------------- | 1717| Promise\<string\> | 返回智能语音参数。 | 1718 1719**错误码:** 1720 1721以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[智能语音错误码](errorcode-intelligentVoice.md)。 1722 1723| 错误码ID | 错误信息 | 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**示例:** 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 1749评估自定义唤醒词是否可用,使用Promise异步回调。 1750 1751**需要权限:** ohos.permission.MANAGE_INTELLIGENT_VOICE 1752 1753**系统能力:** SystemCapability.AI.IntelligentVoice.Core 1754 1755**参数:** 1756 1757| 参数名 | 类型 | 必填 | 说明 | 1758| -------- | -------------------------------- | --- | ------------------------------------------- | 1759| word | string | 是 | 自定义唤醒词。 | 1760 1761**返回值:** 1762 1763| 类型 | 说明 | 1764| ----------------------------------------------- | ---------------------------- | 1765| Promise<[EvaluationResult](#evaluationresult12)> | Promise对象,返回评估结果。 | 1766 1767**错误码:** 1768 1769以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[智能语音错误码](errorcode-intelligentVoice.md)。 1770 1771| 错误码ID | 错误信息 | 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**示例:** 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 1798释放注册智能语音引擎,使用callback异步回调。 1799 1800**需要权限:** ohos.permission.MANAGE_INTELLIGENT_VOICE 1801 1802**系统能力:** SystemCapability.AI.IntelligentVoice.Core 1803 1804**参数:** 1805 1806| 参数名 | 类型 | 必填 | 说明 | 1807| -------- | -------------------------------- | --- | ------------------------------------------- | 1808| callback | AsyncCallback\<void\> | 是 | 返回释放注册引擎的结果。 | 1809 1810**错误码:** 1811 1812以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 1813 1814| 错误码ID | 错误信息 | 1815| ------- | --------------------------------------------| 1816| 201 | Permission denied. | 1817| 202 | Not system application. | 1818 1819**示例:** 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 1839释放注册智能语音引擎,使用Promise异步回调。 1840 1841**需要权限:** ohos.permission.MANAGE_INTELLIGENT_VOICE 1842 1843**系统能力:** SystemCapability.AI.IntelligentVoice.Core 1844 1845**返回值:** 1846 1847| 类型 | 说明 | 1848| ----------------------------------------------- | ---------------------------- | 1849| Promise<void> | 无返回结果的Promise对象。 | 1850 1851**错误码:** 1852 1853以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 1854 1855| 错误码ID | 错误信息 | 1856| ------- | --------------------------------------------| 1857| 201 | Permission denied. | 1858| 202 | Not system application. | 1859 1860**示例:** 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 1876实现唤醒智能语音引擎,通过[createWakeupIntelligentVoiceEngine()](#intelligentvoicecreatewakeupintelligentvoiceengine)获取唤醒智能语音引擎。 1877 1878### getSupportedRegions 1879 1880getSupportedRegions(callback: AsyncCallback<Array<string>>): void 1881 1882获取支持的区域,使用callback异步回调。 1883 1884**需要权限:** ohos.permission.MANAGE_INTELLIGENT_VOICE 1885 1886**系统能力:** SystemCapability.AI.IntelligentVoice.Core 1887 1888| 参数名 | 类型 | 必填 | 说明 | 1889| -------- | -------------------------------- | --- | ------------------------------------------- | 1890| callback | AsyncCallback<Array<string>> | 是 | 返回支持区域的数组,当前只支持中国,对应取值为'CN'。 | 1891 1892**错误码:** 1893 1894以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 1895 1896| 错误码ID | 错误信息 | 1897| ------- | --------------------------------------------| 1898| 201 | Permission denied. | 1899| 202 | Not system application. | 1900 1901**示例:** 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 1922获取支持的区域,使用Promise异步回调。 1923 1924**需要权限:** ohos.permission.MANAGE_INTELLIGENT_VOICE 1925 1926**系统能力:** SystemCapability.AI.IntelligentVoice.Core 1927 1928**返回值:** 1929 1930| 类型 | 说明 | 1931| ----------------------------------------------- | ---------------------------- | 1932| Promise<Array<string>> | 返回支持区域的数组,当前只支持中国,对应取值为'CN'。 | 1933 1934**错误码:** 1935 1936以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 1937 1938| 错误码ID | 错误信息 | 1939| ------- | --------------------------------------------| 1940| 201 | Permission denied. | 1941| 202 | Not system application. | 1942 1943**示例:** 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 1962设置唤醒应用的hap信息,使用callback异步回调。 1963 1964**需要权限:** ohos.permission.MANAGE_INTELLIGENT_VOICE 1965 1966**系统能力:** SystemCapability.AI.IntelligentVoice.Core 1967 1968**参数:** 1969 1970| 参数名 | 类型 | 必填 | 说明 | 1971| -------- | -------------------------------- | --- | ------------------------------------------- | 1972| info | [WakeupHapInfo](#wakeuphapinfo) | 是 | 唤醒hap信息。 | 1973| callback | AsyncCallback\<void\> | 是 | 返回设置唤醒hap信息的结果。 | 1974 1975**错误码:** 1976 1977以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[智能语音错误码](errorcode-intelligentVoice.md)。 1978 1979| 错误码ID | 错误信息 | 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**示例:** 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 2011设置唤醒应用的hap信息,使用promise异步回调。 2012 2013**需要权限:** ohos.permission.MANAGE_INTELLIGENT_VOICE 2014 2015**系统能力:** SystemCapability.AI.IntelligentVoice.Core 2016 2017**参数:** 2018 2019| 参数名 | 类型 | 必填 | 说明 | 2020| -------- | -------------------------------- | --- | ------------------------------------------- | 2021| info | [WakeupHapInfo](#wakeuphapinfo) | 是 | 唤醒hap信息。 | 2022 2023**返回值:** 2024 2025| 类型 | 说明 | 2026| ----------------------------------------------- | ---------------------------- | 2027| Promise<void> | 无返回结果的Promise对象。 | 2028 2029**错误码:** 2030 2031以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[智能语音错误码](errorcode-intelligentVoice.md)。 2032 2033| 错误码ID | 错误信息 | 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**示例:** 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 2062设置唤醒灵敏度,使用callback异步回调。 2063 2064**需要权限:** ohos.permission.MANAGE_INTELLIGENT_VOICE 2065 2066**系统能力:** SystemCapability.AI.IntelligentVoice.Core 2067 2068**参数:** 2069 2070| 参数名 | 类型 | 必填 | 说明 | 2071| -------- | -------------------------------- | --- | ------------------------------------------- | 2072| sensibility | [SensibilityType](#sensibilitytype) | 是 | 灵敏度类型。 | 2073| callback | AsyncCallback\<void\> | 是 | 返回设置灵敏度的结果。 | 2074 2075**错误码:** 2076 2077以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[智能语音错误码](errorcode-intelligentVoice.md)。 2078 2079| 错误码ID | 错误信息 | 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**示例:** 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 2106设置唤醒灵敏度,使用Promise异步回调。 2107 2108**需要权限:** ohos.permission.MANAGE_INTELLIGENT_VOICE 2109 2110**系统能力:** SystemCapability.AI.IntelligentVoice.Core 2111 2112**参数:** 2113 2114| 参数名 | 类型 | 必填 | 说明 | 2115| -------- | -------------------------------- | --- | ------------------------------------------- | 2116| sensibility | [SensibilityType](#sensibilitytype) | 是 | 灵敏度类型。 | 2117 2118**返回值:** 2119 2120| 类型 | 说明 | 2121| ----------------------------------------------- | ---------------------------- | 2122| Promise<void> | 无返回结果的Promise对象。 | 2123 2124**错误码:** 2125 2126以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[智能语音错误码](errorcode-intelligentVoice.md)。 2127 2128| 错误码ID | 错误信息 | 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**示例:** 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 2153设置指定的智能语音参数,使用callback异步回调。 2154 2155**需要权限:** ohos.permission.MANAGE_INTELLIGENT_VOICE 2156 2157**系统能力:** SystemCapability.AI.IntelligentVoice.Core 2158 2159**参数:** 2160 2161| 参数名 | 类型 | 必填 | 说明 | 2162| -------- | -------------------------------- | --- | ------------------------------------------- | 2163| key | string | 是 | 键。 | 2164| value | string | 是 | 值。 | 2165| callback | AsyncCallback\<void\> | 是 | 返回设置智能语音参数的结果。 | 2166 2167**错误码:** 2168 2169以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[智能语音错误码](errorcode-intelligentVoice.md)。 2170 2171| 错误码ID | 错误信息 | 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**示例:** 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 2198设置指定的智能语音参数,使用Promise异步回调。 2199 2200**需要权限:** ohos.permission.MANAGE_INTELLIGENT_VOICE 2201 2202**系统能力:** SystemCapability.AI.IntelligentVoice.Core 2203 2204**参数:** 2205 2206| 参数名 | 类型 | 必填 | 说明 | 2207| -------- | -------------------------------- | --- | ------------------------------------------- | 2208| key | string | 是 | 键。 | 2209| value | string | 是 | 值。 | 2210 2211**返回值:** 2212 2213| 类型 | 说明 | 2214| ----------------------------------------------- | ---------------------------- | 2215| Promise<void> | 无返回结果的Promise对象。 | 2216 2217**错误码:** 2218 2219以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[智能语音错误码](errorcode-intelligentVoice.md)。 2220 2221| 错误码ID | 错误信息 | 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**示例:** 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 2246获取指定的智能语音参数,使用callback异步回调。 2247 2248**需要权限:** ohos.permission.MANAGE_INTELLIGENT_VOICE 2249 2250**系统能力:** SystemCapability.AI.IntelligentVoice.Core 2251 2252**参数:** 2253 2254| 参数名 | 类型 | 必填 | 说明 | 2255| -------- | -------------------------------- | --- | ------------------------------------------- | 2256| key | string | 是 | 键。 | 2257| callback | AsyncCallback\<string\> | 是 | 返回智能语音参数。 | 2258 2259**错误码:** 2260 2261以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[智能语音错误码](errorcode-intelligentVoice.md)。 2262 2263| 错误码ID | 错误信息 | 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**示例:** 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 2291获取指定的智能语音参数,使用Promise异步回调。 2292 2293**需要权限:** ohos.permission.MANAGE_INTELLIGENT_VOICE 2294 2295**系统能力:** SystemCapability.AI.IntelligentVoice.Core 2296 2297**参数:** 2298 2299| 参数名 | 类型 | 必填 | 说明 | 2300| -------- | -------------------------------- | --- | ------------------------------------------- | 2301| key | string | 是 | 键。 | 2302 2303**返回值:** 2304 2305| 类型 | 说明 | 2306| ----------------------------------------------- | ---------------------------- | 2307| Promise\<string\> | 返回智能语音参数。 | 2308 2309**错误码:** 2310 2311以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[智能语音错误码](errorcode-intelligentVoice.md)。 2312 2313| 错误码ID | 错误信息 | 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**示例:** 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 2339获取脉冲编码调制音频,使用Promise异步回调。 2340 2341**需要权限:** ohos.permission.MANAGE_INTELLIGENT_VOICE 2342 2343**系统能力:** SystemCapability.AI.IntelligentVoice.Core 2344 2345**返回值:** 2346 2347| 类型 | 说明 | 2348| ----------------------------------------------- | ---------------------------- | 2349| Promise\<ArrayBuffer\> | Promise对象,返回脉冲编码调制音频。 | 2350 2351**错误码:** 2352 2353以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[智能语音错误码](errorcode-intelligentVoice.md)。 2354 2355| 错误码ID | 错误信息 | 2356| ------- | --------------------------------------------| 2357| 201 | Permission denied. | 2358| 202 | Not system application. | 2359| 22700101 | No memory. | 2360| 22700107 | System error. | 2361 2362**示例:** 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 2381启动捕获器,使用Promise异步回调。 2382 2383**需要权限:** ohos.permission.MANAGE_INTELLIGENT_VOICE 2384 2385**系统能力:** SystemCapability.AI.IntelligentVoice.Core 2386 2387**参数:** 2388 2389| 参数名 | 类型 | 必填 | 说明 | 2390| -------- | -------------------------------- | --- | ------------------------------------------- | 2391| channels | number | 是 | 声道数。 | 2392 2393**返回值:** 2394 2395| 类型 | 说明 | 2396| ----------------------------------------------- | ---------------------------- | 2397| Promise\<void\> | Promise对象,无返回结果。 | 2398 2399**错误码:** 2400 2401以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[智能语音错误码](errorcode-intelligentVoice.md)。 2402 2403| 错误码ID | 错误信息 | 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**示例:** 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 2430读取数据,使用Promise异步回调。 2431 2432**需要权限:** ohos.permission.MANAGE_INTELLIGENT_VOICE 2433 2434**系统能力:** SystemCapability.AI.IntelligentVoice.Core 2435 2436**返回值:** 2437 2438| 类型 | 说明 | 2439| ----------------------------------------------- | ---------------------------- | 2440| Promise\<ArrayBuffer\> | Promise对象,返回音频数据结果。 | 2441 2442**错误码:** 2443 2444以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[智能语音错误码](errorcode-intelligentVoice.md)。 2445 2446| 错误码ID | 错误信息 | 2447| ------- | --------------------------------------------| 2448| 201 | Permission denied. | 2449| 202 | Not system application. | 2450| 22700101 | No memory. | 2451| 22700106 | Read failed. | 2452| 22700107 | System error. | 2453 2454**示例:** 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 2473停止捕获器,使用Promise异步回调。 2474 2475**需要权限:** ohos.permission.MANAGE_INTELLIGENT_VOICE 2476 2477**系统能力:** SystemCapability.AI.IntelligentVoice.Core 2478 2479**返回值:** 2480 2481| 类型 | 说明 | 2482| ----------------------------------------------- | ---------------------------- | 2483| Promise\<void\> | Promise对象,无返回结果。 | 2484 2485**错误码:** 2486 2487以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[智能语音错误码](errorcode-intelligentVoice.md)。 2488 2489| 错误码ID | 错误信息 | 2490| ------- | --------------------------------------------| 2491| 201 | Permission denied. | 2492| 202 | Not system application. | 2493| 22700107 | System error. | 2494 2495**示例:** 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 2513释放唤醒智能语音引擎,使用callback异步回调。 2514 2515**需要权限:** ohos.permission.MANAGE_INTELLIGENT_VOICE 2516 2517**系统能力:** SystemCapability.AI.IntelligentVoice.Core 2518 2519**参数:** 2520 2521| 参数名 | 类型 | 必填 | 说明 | 2522| -------- | -------------------------------- | --- | ------------------------------------------- | 2523| callback | AsyncCallback\<void\> | 是 | 返回释放唤醒引擎的结果。 | 2524 2525**错误码:** 2526 2527以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 2528 2529| 错误码ID | 错误信息 | 2530| ------- | --------------------------------------------| 2531| 201 | Permission denied. | 2532| 202 | Not system application. | 2533 2534**示例:** 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 2554释放唤醒智能语音引擎,使用Promise异步回调。 2555 2556**需要权限:** ohos.permission.MANAGE_INTELLIGENT_VOICE 2557 2558**系统能力:** SystemCapability.AI.IntelligentVoice.Core 2559 2560**返回值:** 2561 2562| 类型 | 说明 | 2563| ----------------------------------------------- | ---------------------------- | 2564| Promise<void> | 无返回结果的Promise对象。 | 2565 2566**错误码:** 2567 2568以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 2569 2570| 错误码ID | 错误信息 | 2571| ------- | --------------------------------------------| 2572| 201 | Permission denied. | 2573| 202 | Not system application. | 2574 2575**示例:** 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 2593订阅唤醒事件。 2594 2595**需要权限:** ohos.permission.MANAGE_INTELLIGENT_VOICE 2596 2597**系统能力:** SystemCapability.AI.IntelligentVoice.Core 2598 2599**参数:** 2600 2601| 参数名 | 类型 | 必填 | 说明 | 2602| -------- | -------------------------------- | --- | ------------------------------------------- | 2603| type | string | 是 | 唤醒智能语音事件,固定取为'wakeupIntelligentVoiceEvent',表示智能语音唤醒事件。 | 2604| callback | Callback\<[WakeupIntelligentVoiceEngineCallbackInfo](#wakeupintelligentvoiceenginecallbackinfo)\> | 是 | 收到唤醒事件的对应处理。 | 2605 2606**错误码:** 2607 2608以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 2609 2610| 错误码ID | 错误信息 | 2611| ------- | --------------------------------------------| 2612| 201 | Permission denied. | 2613| 202 | Not system application. | 2614 2615**示例:** 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 2631取消订阅唤醒事件。 2632 2633**需要权限:** ohos.permission.MANAGE_INTELLIGENT_VOICE 2634 2635**系统能力:** SystemCapability.AI.IntelligentVoice.Core 2636 2637**参数:** 2638 2639| 参数名 | 类型 | 必填 | 说明 | 2640| -------- | -------------------------------- | --- | ------------------------------------------- | 2641| type |string | 是 | 唤醒智能语音事件,固定取为'wakeupIntelligentVoiceEvent'。 | 2642| callback | Callback\<[WakeupIntelligentVoiceEngineCallbackInfo](#wakeupintelligentvoiceenginecallbackinfo)\> | 否 | 收到唤醒事件的对应处理。无参数,则取消所有的订阅,否则,取消对应的订阅 | 2643 2644**错误码:** 2645 2646以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。 2647 2648| 错误码ID | 错误信息 | 2649| ------- | --------------------------------------------| 2650| 201 | Permission denied. | 2651| 202 | Not system application. | 2652 2653**示例:** 2654 2655```ts 2656if (wakeupIntelligentVoiceEngine != null) { 2657 (wakeupIntelligentVoiceEngine as intelligentVoice.WakeupIntelligentVoiceEngine).off('wakeupIntelligentVoiceEvent'); 2658} 2659``` 2660