IOS SDK 新加坡

<p><span style="font-size:16px"><strong>1.&nbsp; 概述</strong></span></p> <p>本文档是平安声纹iOS版SDK的用户指南与参考文件,介绍了声纹(说话人识别)功能的类与函数的基本使用。</p> <p>&nbsp;</p> <p><span style="font-size:16px"><strong>2.&nbsp; 下载</strong></span></p> <p>新加坡地域iOS版SDK下载点击<a href="https://pacloud.obs-cn-shanghai.pinganyun.com/sdk%2FSDK_v3.1.2%2FVoiceprint_sg_iOS_SDK_v.1.0.zip?response-content-disposition=attachment%3Bfilename%3DVoiceprint_sg_iOS_SDK_v.1.0.zip" target="_blank">Voiceprint_sg_iOS_SDK_v.1.0</a></p> <p>&nbsp;</p> <p><span style="font-size:16px"><strong>3.&nbsp; 应用场景与业务流程</strong></span></p> <p>平安声纹SDK提供的主要功能有声纹注册与声纹验证。在允许用户进行声纹注册之前,应该先用其他方式验证用户的身份(如用户名/密码登录、手机验证码登录等)。用户完成声纹注册后,将来需要验证用户身份时,即可使用声纹验证代替其他的身份验证方法,使验证更加便利。如果用户的声纹发生了改变,可以进行修改注册。</p> <p>注册声纹时,系统学习用户的声纹,并将声纹与用户身份进行关联。声纹注册成功后,用户才能进行声纹验证,通过匹对说话人的声纹是否与注册用户相关联的声纹相符,从而验证说话人的身份。</p> <table border="1" cellpadding="0" cellspacing="0" style="width:0px"> <tbody> <tr> <td style="vertical-align:top; width:96px"> <p>文本相关</p> </td> <td style="vertical-align:top; width:690px"> <p>在注册时,云端先后提供三组随机数字串,用户分别读出此三组数字串提交语音进行注册。注册成功后,云端提供一组数字串,用户读出这个数字串进行验证。</p> </td> </tr> <tr> <td style="vertical-align:top; width:96px"> <p>文本无关</p> </td> <td style="vertical-align:top; width:690px"> <p>用户说出长语音(不短于20秒)进行注册,注册成功后,说出长语音(不短于10秒)进行验证,语音内容不限。</p> </td> </tr> </tbody> </table> <p>(1) 针对某一组随机数字进行录音的流程</p> <p>1) 在界面上显示本组随机数字;</p> <p>2) 用户发出开始录音指令(如:按下&ldquo;开始录音&rdquo;按钮;按住&ldquo;录音&rdquo;按钮等),SDK开始录音;</p> <p>3) 用户读出随机数字;</p> <p>4) 用户发出停止录音指令(如:按下&ldquo;停止录音&rdquo;按钮;松开&ldquo;录音&rdquo;按钮等),或者SDK根据条件自动停止录音(录音超时等),SDK停止录音;</p> <p>5) SDK判断录音是否符合要求:</p> <p>a)&nbsp; 如符合要求,则录音成功;</p> <p>b)&nbsp; 如不符合要求,则回到2),重新录制本段语音。</p> <p>(2) 声纹注册流程</p> <p>1) SDK从云端获取三组随机数字;</p> <p>2) 针对第一组随机数字进行录音(见2.1.1针对一组随机数字进行录音的流程);</p> <p>3) SDK向云端发起注册请求;</p> <p>4) 将2)3)重复两次操作</p> <p>5) 云端拿到三段语音后,返回注册成功或失败的结果。</p> <p>(3) 声纹验证流程</p> <p>1) SDK从云端获取1组随机数字;</p> <p>2) 针对随机数字进行录音(见2.1.1针对一组随机数字进行录音的流程);</p> <p>3) SDK向云端发起验证请求;</p> <p>4) SDK返回验证通过或不通过的结果。</p> <p>&nbsp;</p> <p><span style="font-size:16px"><strong>4.&nbsp; 预备工作</strong></span></p> <p>(1) 导入SDK</p> <p>将PABLVoice_sg.framework包复制到工程目录下,然后在工程的Build Phases 中添加本frameWork。</p> <p>在需要使用SDK的类中引入相应的头文件:</p> <p>&nbsp;&nbsp;&nbsp; #import &lt;PABLVoice_sg/PABLVoice_sg.h&gt;</p> <p>(2) 配置工程权限</p> <p>在infoPlist中添加录音权限 addRow-&gt;Privacy - Microphone Usage Description。</p> <p>(3) 初始化</p> <p>使用声纹SDK功能前,首先引入头文件#import &lt;PABLVoice_sg/PABLVoice_sg.h&gt;。然后对参数进行初始化。</p> <p>&nbsp;&nbsp;&nbsp; [PABLVoiceUploader_sg setSpeechTextWithAppId:@&quot;您的appId&quot; withScene:@&quot;您的scene&quot; withAppIdKey:@&quot;您的appIdKey&quot; withSceneType:SCENE_RANDOMLETTER withPAAGAppid:@&quot;您的paagAppid&quot; withSecretAccessKey:@&quot;您的accessKey&quot; withPAAGOACAccessKeyId:@&quot;您的PAAGOACAccessKeyId&quot;];</p> <p>参数说明:</p> <p>appId、scene、appIdKey、paagAppid、accesskey、paagoacAccessKeyId此六项参数组成了app唯一标识。</p> <p>&nbsp;</p> <p><span style="font-size:16px"><strong>5.&nbsp; 声纹功能使用说明</strong></span></p> <p>(1) 查询用户注册状况</p> <p>使用以下方法查询用户在声纹平台的注册状况:</p> <p>&nbsp;&nbsp;&nbsp; //userId:注册声纹的用户的用户名</p> <p>&nbsp;&nbsp;&nbsp; -(void)isUserIdRegisteredWithUserId:(NSString *)userId;</p> <p>使用以下回调方法获取注册状况:</p> <p>&nbsp;&nbsp;&nbsp; -(void)didGetUserIdRegisterOrNot:(NSString*)result withCode:(NSString*)code withResultDic:(NSDictionary*)resultDic{</p> <p>&nbsp; &nbsp;&nbsp;</p> <p>&nbsp;&nbsp;&nbsp; }</p> <p>可能的返回值:</p> <table border="1" cellpadding="0" cellspacing="0" style="width:0px"> <tbody> <tr> <td style="vertical-align:top; width:62px"> <p><strong>Code</strong></p> </td> <td style="vertical-align:top; width:130px"> <p><strong>Result</strong></p> </td> </tr> <tr> <td style="vertical-align:top; width:62px"> <p>201</p> </td> <td style="vertical-align:top; width:130px"> <p>用户已注册</p> </td> </tr> <tr> <td style="vertical-align:top; width:62px"> <p>203</p> </td> <td style="vertical-align:top; width:130px"> <p>用户尚未注册</p> </td> </tr> <tr> <td style="vertical-align:top; width:62px"> <p>601</p> </td> <td style="vertical-align:top; width:130px"> <p>用户注册过,但是并未成功</p> </td> </tr> </tbody> </table> <p>&nbsp;</p> <p>(2) 声纹注册</p> <p>进行注册操作前,应先查询用户的注册状况。</p> <p><strong>1) </strong><strong>文本相关模式</strong></p> <p>在随机数字场景下,使用以下的方法从云端请求随机数字:</p> <p>&nbsp;&nbsp;&nbsp; //userId:注册声纹的用户的用户名</p> <p>&nbsp;&nbsp;&nbsp;</p> <p>&nbsp;&nbsp;&nbsp; [[PABLVoiceUploader_sg shareVoiceUploader] getRandomNumberWithUserId:@&quot;userId&quot; withSpeechType:RANDOM_REGISTER];</p> <p>使用以下回调方法获取随机数字内容:</p> <p>&nbsp;&nbsp;&nbsp; -(void)didGetSpeechText:(NSString*)speechText withSpeechKey:(NSString*)speechKey withResultDic:(NSDictionary*)resultDic{</p> <p>&nbsp;&nbsp;&nbsp;</p> <p>&nbsp;&nbsp;&nbsp; Nslog(@&quot;获取密码:%@ %@&quot;, speechText,speechKey);</p> <p>&nbsp;&nbsp;&nbsp;</p> <p>&nbsp;&nbsp;&nbsp; }</p> <p>其中,speechText是需要显示给用户的随机数字内容,speechKey是发起注册请求时需要传回的值。</p> <p>获取到随机数字后,请在应用界面上显示随机数字,并要求用户读出。使用以下方法进行录音操作:</p> <p>&nbsp;&nbsp;&nbsp; [[PABLRecorder_sg sharedSoundRecorder] startRecorder];</p> <p>调用以下方法即可手动停止录音:</p> <p>&nbsp;&nbsp;&nbsp; [[PABLRecorder_sg sharedSoundRecorder] stopRecorder];</p> <p>停止录音后会产生回调。手动停止录音后产生的是:</p> <p>&nbsp;&nbsp;&nbsp; //PABLReocrdQuality 有三种VOICE_QUALIFIED、VOICE_UNQUALIFIED、VOICE_TIMETOOSHORT,只有返回VOICE_QUALIFIED的结果下才能成为合格的录音。不合格的录音会被删除缓存。</p> <p>&nbsp;&nbsp;&nbsp;</p> <p>&nbsp;&nbsp;&nbsp; -(void)recorderStoppedDelegateWithVoiceInfo:(PABLRecordQuality)voiceInfo withData:(NSData *)voiceData{</p> <p>&nbsp;&nbsp;&nbsp;</p> <p>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if (voiceInfo == VOICE_QUALIFIED) {</p> <p>&nbsp;&nbsp;&nbsp;</p> <p>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.resultLabel.text = @&quot;手动停止-录音合格&quot;;</p> <p>&nbsp;&nbsp;&nbsp;</p> <p>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }else if (voiceInfo == VOICE_UNQUALIFIED){</p> <p>&nbsp;&nbsp;&nbsp;</p> <p>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.resultLabel.text = @&quot;手动停止-录音不合格&quot;;</p> <p>&nbsp;&nbsp;&nbsp;</p> <p>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }else if (voiceInfo == VOICE_TIMETOOSHORT){</p> <p>&nbsp;&nbsp;&nbsp;</p> <p>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.resultLabel.text = @&quot;手动停止-录音时间太短了&quot;;</p> <p>&nbsp;&nbsp;&nbsp;</p> <p>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</p> <p>&nbsp;&nbsp;&nbsp; }}</p> <p>如果系统自动停止录音,会产生以下的其中一个回调:</p> <p>&nbsp;&nbsp;&nbsp; -(void)timeoutDelegateWithInfo:(PABLRecordQuality)info withData:(NSData *)voiceData{</p> <p>&nbsp;&nbsp;&nbsp; NSLog(@&quot;超时自动停止-info:&quot;);</p> <p>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if (info == VOICE_QUALIFIED) {</p> <p>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; NSLog(@&quot;超时自动停止了且录音是合格的&quot;);</p> <p>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }else if (info == VOICE_UNQUALIFIED){</p> <p>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; NSLog(@&quot;超时自动停止了且录音是不合格的&quot;);</p> <p>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</p> <p>&nbsp;&nbsp;&nbsp; }</p> <p>完成一段录音后,请进行第一次注册:</p> <p>&nbsp;&nbsp;&nbsp; //userId:请传入当前注册用户的用户名</p> <p>&nbsp;&nbsp;&nbsp; //index:第一段注册请传入@&quot;1&quot;,第二段注册请传@&quot;2&quot;,第三段注册请传:@&quot;3&quot;</p> <p>&nbsp;&nbsp;&nbsp; //speechText:请传获取到的speechText。</p> <p>&nbsp;&nbsp;&nbsp; //speechKey:请传入获取到的speechKey。</p> <p>&nbsp;&nbsp;&nbsp; //type:根据之前查询的用户注册状态,用户从未注册过时传入REGISTER_REGISTER,用户已注册或者注册过未成功请传入REGISTER_MODIFY</p> <p>&nbsp;&nbsp;&nbsp;</p> <p>&nbsp;&nbsp;&nbsp; [[PABLVoiceUploader_sg shareVoiceUploader] registerVoiceWithUserId:self.userId withIndex:index withSpeechText:self.speechText withSpeechKey:self.speechKey withType:REGISTER_REGISTER]</p> <p>注册结果回调方法如下:</p> <p>&nbsp;&nbsp;&nbsp; -(void)didGetRegisterResult:(NSString *)registerResult withCode:(NSString*)code withResultDic:(NSDictionary*)resultDic{</p> <p>&nbsp;&nbsp;&nbsp;</p> <p>&nbsp;&nbsp;&nbsp; NSLog(@&quot;注册结果=%@-%@&quot;,registerResult,code);</p> <p>&nbsp;&nbsp;&nbsp; }</p> <p>可能返回的值如下表:</p> <table border="1" cellpadding="0" cellspacing="0" style="width:0px"> <tbody> <tr> <td style="vertical-align:top; width:77px"> <p><strong>code</strong></p> </td> <td style="vertical-align:top; width:380px"> <p><strong>registerResult</strong></p> </td> </tr> <tr> <td style="vertical-align:top; width:77px"> <p>600</p> </td> <td style="vertical-align:top; width:380px"> <p>注册成功</p> </td> </tr> <tr> <td style="vertical-align:top; width:77px"> <p>601</p> </td> <td style="vertical-align:top; width:380px"> <p>注册失败</p> </td> </tr> <tr> <td style="vertical-align:top; width:77px"> <p>801</p> </td> <td style="vertical-align:top; width:380px"> <p>SpeechText已超时,请重新获取</p> </td> </tr> <tr> <td style="vertical-align:top; width:77px"> <p>1000</p> </td> <td style="vertical-align:top; width:380px"> <p>注册语音非同一人</p> </td> </tr> <tr> <td style="vertical-align:top; width:77px"> <p>1001</p> </td> <td style="vertical-align:top; width:380px"> <p>语音与文字不匹配(录音所读的数字与随机密码不匹配时会返回此结果)</p> </td> </tr> <tr> <td style="vertical-align:top; width:77px"> <p>9999</p> </td> <td style="vertical-align:top; width:380px"> <p>系统异常</p> </td> </tr> <tr> <td style="vertical-align:top; width:77px"> <p>201</p> </td> <td style="vertical-align:top; width:380px"> <p>用户已注册</p> </td> </tr> <tr> <td style="vertical-align:top; width:77px"> <p>204</p> </td> <td style="vertical-align:top; width:380px"> <p>注册修改失败</p> </td> </tr> <tr> <td style="vertical-align:top; width:77px"> <p>302</p> </td> <td style="vertical-align:top; width:380px"> <p>参数异常</p> </td> </tr> <tr> <td style="vertical-align:top; width:77px"> <p>2000</p> </td> <td style="vertical-align:top; width:380px"> <p>本次注册成功,请继续完成后续注册!</p> </td> </tr> <tr> <td style="vertical-align:top; width:77px"> <p>803</p> </td> <td style="vertical-align:top; width:380px"> <p>注册or验证文本变更需通知声纹平台及时更新!</p> </td> </tr> <tr> <td style="vertical-align:top; width:77px"> <p>804</p> </td> <td style="vertical-align:top; width:380px"> <p>注册流程时间过长,需从第一条开始重新注册</p> </td> </tr> <tr> <td style="vertical-align:top; width:77px"> <p>805</p> </td> <td style="vertical-align:top; width:380px"> <p>注册过程中,上一条语音尚未注册成功</p> </td> </tr> </tbody> </table> <p>按照应用场景与业务流程中介绍的流程要求,重复以上步骤,总共实现三次注册,才可完成注册的全部流程且注册成功。</p> <p>&nbsp;</p> <p><strong>2)</strong><strong>文本无关模式</strong></p> <p>按照录音流程进行录音,完成后进行注册:</p> <p>&nbsp;&nbsp;&nbsp; //userId:请传入当前注册用户的用户名</p> <p>&nbsp;&nbsp;&nbsp; //voiceData:传入录音的data</p> <p>&nbsp;&nbsp;&nbsp; //type:根据之前查询的用户注册状态,用户从未注册过时传入REGISTER_REGISTER,用户已注册或者注册过未成功请传入REGISTER_MODIFY</p> <p>&nbsp;&nbsp;&nbsp;</p> <p>&nbsp;&nbsp;&nbsp; [[PABLVoiceUploader_sg shareVoiceUploader] registerLongSpeechWithUserId:self.userId withVoiceData:self.longSpeechData withType:REGISTER_MODIFY];</p> <p>注册结果回调方法如下:</p> <p>&nbsp;&nbsp;&nbsp; -(void)didGetRegisterResult:(NSString *)registerResult withCode:(NSString*)code withResultDic:(NSDictionary*)resultDic{</p> <p>&nbsp;&nbsp;&nbsp;</p> <p>&nbsp;&nbsp;&nbsp; NSLog(@&quot;注册结果=%@-%@&quot;,registerResult,code);</p> <p>&nbsp;&nbsp;&nbsp; }</p> <p>(3) 声纹验证</p> <p><strong>1) </strong><strong>文本相关模式</strong></p> <p>在随机数字场景下,使用以下的方法从云端请求密码:</p> <p>&nbsp;&nbsp;&nbsp; [[PABLVoiceUploader_sg shareVoiceUploader] getSpeechTextWithUserId:@&quot;当前注册用户的用户名&quot; withSpeechType:RANDOM_VERIFY];</p> <p>获取随机数字的回调方法如下:</p> <p>&nbsp;&nbsp;&nbsp; -(void)didGetSpeechText:(NSString *)speechText withSpeechKey:(NSString *)speechKey withResultDic:(NSDictionary*)resultDic{</p> <p>&nbsp;&nbsp;&nbsp;</p> <p>&nbsp;&nbsp;&nbsp; NSLog(@&quot;获取到的验证随机数以及所对应的密码为:%@ %@&quot;, speechText,speechKey);</p> <p>&nbsp;&nbsp;&nbsp;</p> <p>&nbsp;&nbsp;&nbsp; }</p> <p>获取到随机数字后,请在应用界面上显示对应随机数字,并要求用户读出。开始、停止录音方法及回调均与注册时相同。合格录音完成后,调用以下方法提交声纹验证:</p> <p>&nbsp;&nbsp;&nbsp; //userId:请传入当前注册用户的用户名</p> <p>&nbsp;&nbsp;&nbsp; //speechText:请传获取到的speechText</p> <p>&nbsp;&nbsp;&nbsp; //speechKey:请传入获取到的speechKey</p> <p>&nbsp;&nbsp;&nbsp;</p> <p>&nbsp;&nbsp;&nbsp; [[PABLVoiceUploader_sg shareVoiceUploader] verifyVoiceWithUserId:self.userId withSpeechText:self.speechText withSpeechKey:self.speechKey ]</p> <p>验证的回调方法如下:</p> <p>&nbsp;&nbsp; &nbsp;-(void)didGetVerifyResult:(NSString *)verifyResult withCode:(NSString *)code withCompareId:(NSString *)compareId withResultDic:(NSDictionary*)resultDic{</p> <p>&nbsp;&nbsp;&nbsp;</p> <p>&nbsp;&nbsp;&nbsp; NSLog(@&quot;验证结果=%@-%@-%@&quot;,verifyResult,code,compareId);</p> <p>&nbsp;&nbsp;&nbsp; }</p> <p>其中compareId是本次验证交易的确认码,可用于在服务器间相互调用确认验证交易的结果。verifyResult和code可能返回的值如下表:</p> <table border="1" cellpadding="0" cellspacing="0" style="width:0px"> <tbody> <tr> <td style="vertical-align:top; width:76px"> <p><strong>code</strong></p> </td> <td style="vertical-align:top; width:236px"> <p><strong>verifyResult</strong></p> </td> </tr> <tr> <td style="vertical-align:top; width:76px"> <p>603</p> </td> <td style="vertical-align:top; width:236px"> <p>验证成功</p> </td> </tr> <tr> <td style="vertical-align:top; width:76px"> <p>604</p> </td> <td style="vertical-align:top; width:236px"> <p>验证失败</p> </td> </tr> <tr> <td style="vertical-align:top; width:76px"> <p>801</p> </td> <td style="vertical-align:top; width:236px"> <p>SpeechText已超时,请重新获取</p> </td> </tr> <tr> <td style="vertical-align:top; width:76px"> <p>1001</p> </td> <td style="vertical-align:top; width:236px"> <p>语音与文字不匹配</p> </td> </tr> <tr> <td style="vertical-align:top; width:76px"> <p>9999</p> </td> <td style="vertical-align:top; width:236px"> <p>系统异常</p> </td> </tr> <tr> <td style="vertical-align:top; width:76px"> <p>203</p> </td> <td style="vertical-align:top; width:236px"> <p>用户尚未注册</p> </td> </tr> <tr> <td style="vertical-align:top; width:76px"> <p>302</p> </td> <td style="vertical-align:top; width:236px"> <p>参数异常</p> </td> </tr> <tr> <td style="vertical-align:top; width:76px"> <p>202</p> </td> <td style="vertical-align:top; width:236px"> <p>用户存在,状态异常</p> </td> </tr> <tr> <td style="vertical-align:top; width:76px"> <p>803</p> </td> <td style="vertical-align:top; width:236px"> <p>注册or验证文本变更需通知声纹平台及时更新!</p> </td> </tr> </tbody> </table> <p><strong>2) </strong><strong>文本无关模式</strong></p> <p>按照录音流程进行录音,完成后进行验证:</p> <p>&nbsp;&nbsp;&nbsp; //userId:请传入当前注册用户的用户名</p> <p>&nbsp;&nbsp;&nbsp; //voiceData:传入录音的data</p> <p>&nbsp;&nbsp;&nbsp;</p> <p>&nbsp;&nbsp;&nbsp; [[PABLVoiceUploader_sg shareVoiceUploader] verifyLongSpeechWithUserId:self.userId withVoiceData:self.longSpeechData];</p> <p>验证结果回调方法如下:</p> <p>&nbsp;&nbsp;&nbsp; -(void)didGetVerifyResult:(NSString*)verifyResult withCode:(NSString*)code withCompareId:(NSString*)compareId withResultDic:(NSDictionary*)resultDic{</p> <p>&nbsp;&nbsp;&nbsp;</p> <p>&nbsp;&nbsp;&nbsp; NSLog(@&quot;验证结果=%@-%@&quot;,registerResult,code);</p> <p>&nbsp;&nbsp;&nbsp; }</p> <p>&nbsp;</p> <p><span style="font-size:16px"><strong>6.&nbsp; 声纹功能参考文档</strong></span></p> <p>(1) PABLRecorder</p> <p>声纹服务的核心服务类,客户端程序通过调用该类的start,stop方法来打开或关闭语音采集。(其中音量大小的返回频率为屏幕刷新频率,通过通知方式传值,传值类型为NSNumber类型,通知名为:#define PABLRECORDER_NOTIFICATION_DECIBLE_NAME @&ldquo;pablRecorderNotiDeciName&rdquo;。详情请参考demo)</p> <p>1)&nbsp;&nbsp; 代理</p> <p>使用此类时,需要声明代理[PABLRecorder_sg sharedSoundRecorder].pablDelegate = self ;</p> <p>此类所有的delegate均包含在此pablDelegate中,无需每个方法各自声明。</p> <p>a)&nbsp;&nbsp;&nbsp;&nbsp; <strong>@property(nonatomic,weak)id&lt;PABLDelegate&gt;pablDelegate</strong></p> <p>包括了本类各种方法的回调方法。本节列出所有回调方法,每个方法具体的作用和返回值见其相关方法的描述。</p> <p>&nbsp;&nbsp;&nbsp; -(void)isNoisyDelegate:(BOOL)isNoisy;</p> <p>&nbsp;&nbsp;&nbsp; -(void)noMicroPhoneAuthority;</p> <p>&nbsp;&nbsp;&nbsp; -(void)timeoutDelegateWithInfo:(PABLRecordQuality)info;</p> <p>&nbsp;&nbsp;&nbsp; -(void)recorderStoppedDelegateWithVoiceInfo:(PABLRecordQuality)voiceInfo;</p> <p>2)&nbsp;&nbsp; 属性</p> <p>a)&nbsp;&nbsp;&nbsp;&nbsp; <strong>@property(nonatomic,assign)float timeOutPeriod</strong></p> <p>设置最长录音时间(默认为6s)</p> <p>b)&nbsp;&nbsp;&nbsp;&nbsp; <strong>@property(nonatomic,assign)float noisyTestPeriod</strong></p> <p>设置默认的噪音检测时长(默认为4s)</p> <p>c)&nbsp;&nbsp;&nbsp;&nbsp; <strong>@property(nonatomic,assign)float noisyDecibleStandard</strong></p> <p>设置噪音检测的临界值(默认为25)</p> <p>3)&nbsp;&nbsp; 方法</p> <p>a)&nbsp;&nbsp;&nbsp;&nbsp; <strong>- (void)startRecorder</strong></p> <p>开始录音。</p> <p>b)&nbsp;&nbsp;&nbsp;&nbsp; <strong>- (void)stopRecorder</strong></p> <p>停止录音。</p> <p>录音停止后会产生以下两个回调中的其中一个。使用录音类时,以下两个方法都必须实现。</p> <p>&nbsp;&nbsp;&nbsp; -(void)timeoutDelegateWithInfo:(PABLRecordQuality)info withData:(NSData *)voiceData{</p> <p>&nbsp;&nbsp;&nbsp;</p> <p>&nbsp;&nbsp;&nbsp; NSLog(@&quot;超时自动停止-info:&quot;);</p> <p>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if (info == VOICE_QUALIFIED) {</p> <p>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; NSLog(@&quot;超时自动停止了且录音是合格的&quot;);</p> <p>&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }else if (info == VOICE_UNQUALIFIED){</p> <p>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; NSLog(@&quot;超时自动停止了且录音是不合格的&quot;);</p> <p>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</p> <p>&nbsp;&nbsp;&nbsp; }</p> <p>&nbsp;&nbsp;&nbsp;</p> <p>&nbsp;&nbsp;&nbsp; -(void)recorderStoppedDelegateWithVoiceInfo:(PABLRecordQuality)voiceInfo withData:(NSData *)voiceData{</p> <p>&nbsp;&nbsp;&nbsp;</p> <p>&nbsp;&nbsp;&nbsp; if (voiceInfo == VOICE_QUALIFIED) {</p> <p>&nbsp;&nbsp;&nbsp; NSLog(@&quot;手动停止-录音合格&quot;);</p> <p>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }else if (voiceInfo == VOICE_UNQUALIFIED){</p> <p>&nbsp;&nbsp;&nbsp; &nbsp;NSLog(@&quot;手动停止-录音不合格&quot;);</p> <p>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }else if (voiceInfo == VOICE_TIMETOOSHORT){</p> <p>&nbsp;&nbsp;&nbsp; &nbsp;NSLog(@&quot;手动停止-录音时间太短为不合格&quot;);</p> <p>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</p> <p>&nbsp;&nbsp;&nbsp; }</p> <p>c)&nbsp;&nbsp;&nbsp;&nbsp; <strong>-(void)startRecorderToTestNoisy</strong></p> <p>噪音检测,可用于在录音之前确定环境是否足够安静。若噪音检测不通过,则环境不适合进行声纹注册或验证操作。</p> <p>开始噪音检测后无需调用方法停止,到达noisyTestPeriod后会自动停止。</p> <p>回调方法如下:</p> <p>&nbsp;&nbsp;&nbsp; (void)isNoisyDelegate:(BOOL)isNoisy{</p> <p>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; If(isNoisy==YES){</p> <p>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; NSLog(@&quot;有噪音&quot;);</p> <p>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; }else{</p> <p>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; NSLog(@&quot;没有噪音&quot;);</p> <p>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; }</p> <p>&nbsp;&nbsp;&nbsp; }</p> <p>(2) PABLVoiceUploader</p> <p>声纹服务的核心服务类,客户端程序通过调用该类的register, verify等方法来进行声纹的注册和验证,以及其它网络请求。</p> <p>&nbsp;</p> <p>1)&nbsp;&nbsp; 代理</p> <p>使用此类时,需要声明代理[PABLVoiceUploader_sg shareVoiceUploader].uploaderDelegate = self ;</p> <p>a)&nbsp;&nbsp;&nbsp;&nbsp; <strong>@property(nonatomic,weak)id&lt;PABLUploaderDelegate&gt;uploaderDelegate</strong></p> <p>包括了本类各种方法的回调方法。本节列出所有回调方法,每个方法具体的作用和返回值见其相关方法的描述。</p> <p>&nbsp;&nbsp;&nbsp; -(void)didGetSpeechText:(NSString*)speechText withSpeechKey:(NSString*)speechKey withResultDic:(NSDictionary*)resultDic;</p> <p>&nbsp;&nbsp;&nbsp; -(void)didGetRegisterResult:(NSString*)registerResult withCode:(NSString*)code withResultDic:(NSDictionary*)resultDic;</p> <p>&nbsp;&nbsp;&nbsp; -(void)didGetVerifyResult:(NSString*)verifyResult withCode:(NSString*)code withCompareId:(NSString*)compareId withResultDic:(NSDictionary*)resultDic;</p> <p>&nbsp;&nbsp;&nbsp; -(void)didGetUserIdRegisterOrNot:(NSString*)result withCode:(NSString*)code withResultDic:(NSDictionary*)resultDic;</p> <p>&nbsp;&nbsp;&nbsp; -(void)uploaderError:(NSString*)error;</p> <p>&nbsp;&nbsp;&nbsp; -(void)paramError:(NSString*)errorinfo;</p> <p>2)&nbsp;&nbsp; 方法</p> <p>a)&nbsp;&nbsp;&nbsp;&nbsp; <strong>通用的网络请求错误回调</strong></p> <p>使用以下方法时均有可能生成这两个回调。</p> <p>网络请求错误:</p> <p>&nbsp;&nbsp;&nbsp; -(void)uploaderError:(NSError*)error{</p> <p>&nbsp;&nbsp;&nbsp;</p> <p>&nbsp;&nbsp;&nbsp; NSLog(@&quot;错误信息:%@&quot;,error);</p> <p>&nbsp;&nbsp;&nbsp; }</p> <p>参数错误:</p> <p>&nbsp;&nbsp;&nbsp; -(void)paramError:(NSString*)errorinfo{</p> <p>&nbsp;&nbsp;&nbsp;</p> <p>&nbsp;&nbsp;&nbsp; NSLog(@&quot;参数错误信息:%@&quot;,errorInfo);</p> <p>&nbsp;&nbsp;&nbsp; }</p> <p>&nbsp;</p> <p>b)&nbsp;&nbsp;&nbsp;&nbsp; <strong>-(void)isUserIdRegisteredWithUserId:(NSString *)userId</strong></p> <p>检测用户是否已注册。</p> <p>参数:</p> <p>userId: 请传入当前注册用户的用户名。</p> <p>回调方法如下:</p> <p>&nbsp;&nbsp;&nbsp; -(void)didGetUserIdRegisterOrNot:(NSString*)result withCode:(NSString*)code withResultDic:(NSDictionary*)resultDic{</p> <p>&nbsp;&nbsp;&nbsp;</p> <p>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; NSLog(@&quot;用户名是否已注册的返回结果:%@- code=%@&quot;,result,code);</p> <p>&nbsp;&nbsp;&nbsp; }</p> <p>回调可能的返回值:</p> <table border="1" cellpadding="0" cellspacing="0" style="width:0px"> <tbody> <tr> <td style="vertical-align:top; width:67px"> <p><strong>Code</strong></p> </td> <td style="vertical-align:top; width:125px"> <p><strong>Result</strong></p> </td> </tr> <tr> <td style="vertical-align:top; width:67px"> <p>201</p> </td> <td style="vertical-align:top; width:125px"> <p>用户已注册</p> </td> </tr> <tr> <td style="vertical-align:top; width:67px"> <p>203</p> </td> <td style="vertical-align:top; width:125px"> <p>用户尚未注册</p> </td> </tr> <tr> <td style="vertical-align:top; width:67px"> <p>601</p> </td> <td style="vertical-align:top; width:125px"> <p>用户注册过,但是并未成功</p> </td> </tr> </tbody> </table> <p>&nbsp;</p> <p>c)&nbsp;&nbsp;&nbsp;&nbsp; <strong>-(void)getSpeechTextWithUserId:(NSString*)userId with-SpeechType:(PABLRandomNumType)speechType</strong></p> <p>获取密码,供用户阅读。</p> <p>参数:</p> <p>userId:请传入当前注册用户的用户名。</p> <p>speechType:获取注册用的密码时传入RANDOM_REGISTER,获取验证用的密码时传入RANDOM_VERIFY。</p> <p>回调方法:</p> <p>&nbsp;&nbsp;&nbsp; -(void)didGetSpeechText:(NSString*)speechText withSpeech-Key:(NSString*)speechKey withResultDic:(NSDictionary*)resultDic withResultDic:(NSDictionary*)resultDic{</p> <p>&nbsp;&nbsp;&nbsp;</p> <p>&nbsp;&nbsp;&nbsp; NSLog(@&quot;获取到的随机数为%@&quot;,resulte);</p> <p>&nbsp;&nbsp;&nbsp; }</p> <p>&nbsp;</p> <p>d)&nbsp;&nbsp;&nbsp;&nbsp; <strong>-(void)registerVoiceWithUserId:(NSString*)userId withIndex:(NSString*)index withSpeechText:(NSString*)speechText withSpeechKey:(NSString*)speechKey withType:(PABLRegisterType)type</strong></p> <p>进行注册操作。</p> <p>参数:</p> <p>type:用户为第一次注册请传入REGISTER_REGISTER,修改注册信息请传入REGISTER_MODIFY.</p> <p>userId:请传入当前注册用户的用户名</p> <p>index:第一段注册请传@&quot;1&quot;;第二段注册请传@&quot;2&quot;;第三段注册请传@&quot;3&quot;。注意该参数为字符串。</p> <p>speechText:请传人当前注册所读的对应文本或对应数字。</p> <p>speechKey:请传入当前注册文本所对应的speechKey(仅随机数字模式需传此字段)。</p> <p>type:注册请传REGISTER_REGISTER;修改注册请传REGISTER_MODIFY。</p> <p>回调方法如下:</p> <p>&nbsp;&nbsp;&nbsp; -(void)didGetRegisterResult:(NSString*)registerResult with-Code:(NSString*)code{</p> <p>&nbsp;&nbsp;&nbsp;</p> <p>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; NSLog(@&quot;注册结果=%@-%@&quot;,registerResult,code);</p> <p>&nbsp;&nbsp;&nbsp; }</p> <p>可能的返回值如下:</p> <table border="1" cellpadding="0" cellspacing="0" style="width:0px"> <thead> <tr> <td style="vertical-align:top; width:78px"> <p><strong>code</strong></p> </td> <td style="vertical-align:top; width:234px"> <p><strong>registerResult</strong></p> </td> </tr> </thead> <tbody> <tr> <td style="vertical-align:top; width:78px"> <p>600</p> </td> <td style="vertical-align:top; width:234px"> <p>注册成功</p> </td> </tr> <tr> <td style="vertical-align:top; width:78px"> <p>601</p> </td> <td style="vertical-align:top; width:234px"> <p>注册失败</p> </td> </tr> <tr> <td style="vertical-align:top; width:78px"> <p>801</p> </td> <td style="vertical-align:top; width:234px"> <p>SpeechText已超时,请重新获取</p> </td> </tr> <tr> <td style="vertical-align:top; width:78px"> <p>1000</p> </td> <td style="vertical-align:top; width:234px"> <p>注册语音非同一人</p> </td> </tr> <tr> <td style="vertical-align:top; width:78px"> <p>1001</p> </td> <td style="vertical-align:top; width:234px"> <p>语音与文字不匹配</p> </td> </tr> <tr> <td style="vertical-align:top; width:78px"> <p>9999</p> </td> <td style="vertical-align:top; width:234px"> <p>系统异常</p> </td> </tr> <tr> <td style="vertical-align:top; width:78px"> <p>201</p> </td> <td style="vertical-align:top; width:234px"> <p>用户已注册</p> </td> </tr> <tr> <td style="vertical-align:top; width:78px"> <p>204</p> </td> <td style="vertical-align:top; width:234px"> <p>注册修改失败</p> </td> </tr> <tr> <td style="vertical-align:top; width:78px"> <p>302</p> </td> <td style="vertical-align:top; width:234px"> <p>参数异常</p> </td> </tr> <tr> <td style="vertical-align:top; width:78px"> <p>803</p> </td> <td style="vertical-align:top; width:234px"> <p>注册or验证文本变更需通知声纹平台及时更新!</p> </td> </tr> <tr> <td style="vertical-align:top; width:78px"> <p>2000</p> </td> <td style="vertical-align:top; width:234px"> <p>本次注册成功,请继续完成后续注册!</p> </td> </tr> <tr> <td style="vertical-align:top; width:78px"> <p>804</p> </td> <td style="vertical-align:top; width:234px"> <p>注册流程时间过长,需从第一条开始重新注册</p> </td> </tr> <tr> <td style="vertical-align:top; width:78px"> <p>805</p> </td> <td style="vertical-align:top; width:234px"> <p>注册过程中,上一条语音尚未注册成功</p> </td> </tr> </tbody> </table> <p>&nbsp;</p> <p>e)&nbsp;&nbsp;&nbsp;&nbsp; <strong>-(void)verifyVoiceWithUserId:(NSString*)userId withSpeechText:(NSString*)speechText withSpeechKey:(NSString*)speechKey</strong></p> <p>提交声纹验证。</p> <p>参数:</p> <p>userId:请传入当前注册用户的用户名</p> <p>speechText:请传人当前验证所读的对应数字</p> <p>speechKey:请传入当前注册文本所对应的speechKey(仅随机数字模式需传此字段)</p> <p>回调方法如下:</p> <p>&nbsp;&nbsp;&nbsp; -(void)didGetVerifyResult:(NSString*)verifyResult withCode:(NSString*)code withCompareId:(NSString*)compareId withResultDic:(NSDictionary*)resultDic{</p> <p>&nbsp;&nbsp;&nbsp;</p> <p>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; NSLog(@&ldquo;登录结果:%@-%@-%@&rdquo;,verifyResult,code,compareId);</p> <p>&nbsp;&nbsp;&nbsp; }</p> <p>回调可能的返回数值如下表:</p> <table border="1" cellpadding="0" cellspacing="0" style="width:0px"> <tbody> <tr> <td style="vertical-align:top; width:91px"> <p>Code</p> </td> <td style="vertical-align:top; width:222px"> <p>verifyResult</p> </td> </tr> <tr> <td style="vertical-align:top; width:91px"> <p>603</p> </td> <td style="vertical-align:top; width:222px"> <p>验证成功</p> </td> </tr> <tr> <td style="vertical-align:top; width:91px"> <p>604</p> </td> <td style="vertical-align:top; width:222px"> <p>验证失败</p> </td> </tr> <tr> <td style="vertical-align:top; width:91px"> <p>801</p> </td> <td style="vertical-align:top; width:222px"> <p>SpeechText已超时,请重新获取</p> </td> </tr> <tr> <td style="vertical-align:top; width:91px"> <p>1001</p> </td> <td style="vertical-align:top; width:222px"> <p>语音与文字不匹配</p> </td> </tr> <tr> <td style="vertical-align:top; width:91px"> <p>9999</p> </td> <td style="vertical-align:top; width:222px"> <p>系统异常</p> </td> </tr> <tr> <td style="vertical-align:top; width:91px"> <p>203</p> </td> <td style="vertical-align:top; width:222px"> <p>用户尚未注册</p> </td> </tr> <tr> <td style="vertical-align:top; width:91px"> <p>302</p> </td> <td style="vertical-align:top; width:222px"> <p>参数异常</p> </td> </tr> <tr> <td style="vertical-align:top; width:91px"> <p>803</p> </td> <td style="vertical-align:top; width:222px"> <p>注册or验证文本变更需通知声纹平台及时更新!</p> </td> </tr> <tr> <td style="vertical-align:top; width:91px"> <p>202</p> </td> <td style="vertical-align:top; width:222px"> <p>用户存在,状态异常</p> </td> </tr> </tbody> </table> <p>f)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <strong>-(void)registerLongSpeechWithUserId:(NSString*)userId withVoiceData:(NSData*)voiceData withType:(PABLRegisterType)type;</strong></p> <p>文本无关注册</p> <p>参数:</p> <p>userId:请传入当前注册用户的用户名</p> <p>voiceData:请传人当前用户进行注册的语音</p> <p>回调方法如下:</p> <p>&nbsp;&nbsp;&nbsp; -(void)didGetRegisterResult:(NSString*)registerResult with-Code:(NSString*)code withResultDic:(NSDictionary*)resultDic{</p> <p>&nbsp;&nbsp;&nbsp;</p> <p>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; NSLog(@&quot;注册结果=%@-%@&quot;,registerResult,code);</p> <p>&nbsp;&nbsp;&nbsp; }</p> <p>可能的返回值如下:</p> <table border="1" cellpadding="0" cellspacing="0" style="width:0px"> <thead> <tr> <td style="vertical-align:top; width:52px"> <p><strong>code</strong></p> </td> <td style="vertical-align:top; width:85px"> <p><strong>registerResult</strong></p> </td> </tr> </thead> <tbody> <tr> <td style="vertical-align:top; width:52px"> <p>600</p> </td> <td style="vertical-align:top; width:85px"> <p>注册成功</p> </td> </tr> <tr> <td style="vertical-align:top; width:52px"> <p>601</p> </td> <td style="vertical-align:top; width:85px"> <p>注册失败</p> </td> </tr> <tr> <td style="vertical-align:top; width:52px"> <p>9999</p> </td> <td style="vertical-align:top; width:85px"> <p>系统异常</p> </td> </tr> <tr> <td style="vertical-align:top; width:52px"> <p>201</p> </td> <td style="vertical-align:top; width:85px"> <p>用户已注册</p> </td> </tr> <tr> <td style="vertical-align:top; width:52px"> <p>204</p> </td> <td style="vertical-align:top; width:85px"> <p>注册修改失败</p> </td> </tr> <tr> <td style="vertical-align:top; width:52px"> <p>302</p> </td> <td style="vertical-align:top; width:85px"> <p>参数异常</p> </td> </tr> <tr> <td style="width:52px"> <p>0100</p> </td> <td style="width:85px"> <p>语音有效帧数不够</p> </td> </tr> <tr> <td style="width:52px"> <p>0011</p> </td> <td style="width:85px"> <p>语音vad能量低</p> </td> </tr> </tbody> </table> <p>&nbsp;</p> <p>g)&nbsp;&nbsp;&nbsp;&nbsp; <strong>-(void)verifyLongSpeechWithUserId:(NSString*)userId withVoiceData:(NSData*)voiceData;</strong></p> <p>文本无关验证</p> <p>参数:</p> <p>userId:请传入当前注册用户的用户名</p> <p>voiceData:请传人当前用户进行验证的语音</p> <p>回调方法如下:</p> <p>&nbsp;&nbsp;&nbsp; -(void)didGetVerifyResult:(NSString*)verifyResult withCode:(NSString*)code withCompareId:(NSString*)compareId withResultDic:(NSDictionary*)resultDic{</p> <p>&nbsp;&nbsp;&nbsp;</p> <p>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; NSLog(@&ldquo;登录结果:%@-%@-%@&rdquo;,verifyResult,code,compareId);</p> <p>&nbsp;&nbsp;&nbsp; }</p> <p>回调可能的返回数值如下表:</p> <table border="1" cellpadding="0" cellspacing="0" style="width:0px"> <tbody> <tr> <td style="vertical-align:top; width:76px"> <p>Code</p> </td> <td style="vertical-align:top; width:237px"> <p>verifyResult</p> </td> </tr> <tr> <td style="vertical-align:top; width:76px"> <p>603</p> </td> <td style="vertical-align:top; width:237px"> <p>验证成功</p> </td> </tr> <tr> <td style="vertical-align:top; width:76px"> <p>604</p> </td> <td style="vertical-align:top; width:237px"> <p>验证失败</p> </td> </tr> <tr> <td style="width:76px"> <p>0100</p> </td> <td style="width:237px"> <p>语音有效帧数不够</p> </td> </tr> <tr> <td style="width:76px"> <p>0011</p> </td> <td style="width:237px"> <p>语音vad能量低</p> </td> </tr> <tr> <td style="vertical-align:top; width:76px"> <p>9999</p> </td> <td style="vertical-align:top; width:237px"> <p>系统异常</p> </td> </tr> <tr> <td style="vertical-align:top; width:76px"> <p>203</p> </td> <td style="vertical-align:top; width:237px"> <p>用户尚未注册</p> </td> </tr> <tr> <td style="vertical-align:top; width:76px"> <p>302</p> </td> <td style="vertical-align:top; width:237px"> <p>参数异常</p> </td> </tr> <tr> <td style="vertical-align:top; width:76px"> <p>803</p> </td> <td style="vertical-align:top; width:237px"> <p>注册or验证文本变更需通知声纹平台及时更新!</p> </td> </tr> <tr> <td style="vertical-align:top; width:76px"> <p>202</p> </td> <td style="vertical-align:top; width:237px"> <p>用户存在,状态异常</p> </td> </tr> </tbody> </table> <p>&nbsp;</p> <p>&nbsp;</p>
以上内容是否解决了您的问题?
请补全提交信息!
咨询·建议

电话咨询 - 7x24 小时

400-151-8800

邮件咨询

cloud@pingan.com

在线客服

7x24 小时,急速解答

工单支持

解决云产品相关技术问题