本地语音唤醒(iOS V2)

1、概述

    Wakeup 提供单独的离线语音唤醒能力,通过不间断侦测语音,当出现唤醒词的语音时可执行相关事件的技术,具有功效低、唤醒率高的特点。可以设置自定义唤醒词。

2、SDK使用说明

    使用当前功能时,请先授权,否则禁止使用。授权模块使用请参照DUI Lite 2.0 -- 授权模块

3、引擎运行流程图

4、示例代码

 

4.1 初始化

self.wakeupEngine = [AIWakeupEngine shareInstance];

AIWakeupConfig *mWakeupConfig = [[AIWakeupConfig alloc]init];

NSString *wakeupResPath = [[NSBundle mainBundle] pathForResource:@"wakeup_aifar_comm.bin" ofType:nil];

mWakeupConfig.wakeupResource = wakeupResPath;

mWakeupConfig.useCustomFeed = NO;

[self.wakeupEngine initEngineWithConfig:mWakeupConfig delegate:self];

4.2 开始唤醒

AIWakeupIntent *mIntent = [[AIWakeupIntent alloc]init];

mIntent.pinyin = [@[@"ni hao xiao peng", @"ni hao xiao chi", @"ni hao xiao long"] mutableCopy];

mIntent.threshold = [@[@(0.123), @(0.127), @(0.127)] mutableCopy];

[self.wakeupEngine startWithIntent:mIntent];

4.3 停止唤醒

[self.wakeupEngine stop];

4.4 唤醒回调

#pragma mark - WakeupDelegate 代理方法



/**

* 本地唤醒引擎初始化结束后执行

*

* @param status

*            {@link AIConstant#OPT_SUCCESS}:初始化成功;

*            {@link AIConstant#OPT_FAILED}:初始化失败,

*/

- (void)onWakeupInit:(int)status {

 

}





/**

* 发生错误时执行

*

* @param error

*            错误信息

*/

- (void)onWakeupError:(AIError *)error {



}





/**

* 一次唤醒检测完毕后执行

*

* @param recordId recordId

*

* @param confidence

*            唤醒置信度

* @param wakeupWord

*            唤醒词, 如唤醒失败,则返回null

*/

- (void)onWakeup:(NSString *)recordId confidence:(double)confidence wakeupWord:(NSString *)wakeupWord {



}





/**

* 录音机启动时调用

*/

- (void)onWakeupReadyForSpeech {



}





/**

* 录音机数据返回

* @param data 录音机数据

* @param size  数据大小

*/

- (void)onWakeupRawDataReceived:(NSData *)data size:(int)size {



}





/**

* 唤醒引擎结束的回调接口,只会在唤醒后(onWakeup)500ms后被调用

* 只有这个接口被调用后,才能开启下一次的唤醒

* 其他引擎的开启和此接口没关系

*/

- (void)onWakeupEngineStopped {



}

4.5 销毁引擎

[self.wakeupEngine releaseEngine];

self.wakeupEngine = nil;

[AIWakeupEngine deallocInstance];