iOS SDK开发文档
快速接入
1、SDK说明
口语测评SDK主要有三大类“SSOralEvaluatingConfig.h”,“SSOralEvaluatingManager.h”和“SSOralEvaluatingManagerConfig.h”。
“SSOralEvaluatingConfig.h” 用于配置开始评测所需的参数
“SSOralEvaluatingManager.h” 生成管理引擎对象
”SSOralEvaluatingManagerConfig.h” 用于配置初始化引擎对象的参数
2、引入方式
2.1 pod导入(推荐)
a) 指定Master仓库和Pod仓库:
source 'https://github.com/CocoaPods/Specs.git'
source 'https://pt.singsound.com:10081/singsound-public/SingSoundSDKCocoaPodRepo.git'b) 2.2 添加依赖:
pod 'SingSoundSDK'
// 注:如果在pod install的过程中遇到Couldn’t determine repo type for URL的错误,请先手动添加源:
pod repo add SingSoundSDKCocoaPodRepo https://pt.singsound.com:10081/singsound-public/SingSoundSDKCocoaPodRepo.git
// 然后再执行install命令
pod install2.2 手动导入
将“SingSound.framework”,“SingSound.Bundle”和”libssound.a”拖入工程(注:记得选“copy item if need”)然后去Build Phases下“Link Binary With Libraries”下有“SingSound.framework”和“Copy Bundle Resources”下有“SingSound.Bundle”。
导入必要的库“libz.1.1.3tbd”,“libz.1.tbd”
2.3 在工程中添加必要的权限
麦克风权限
在项目的info.plist 文件中增加“NSMicrophoneUsageDescription”以添加麦克风访问权限。
3、快速测评流程
3.1 完整调用代码示例
注册评测 & 鉴权获取
建议在AppDelegate.m文件注册
//注册评测
SSOralEvaluatingManagerConfig *managerConfig = [[SSOralEvaluatingManagerConfig alloc]init];
NSString *path = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject] stringByAppendingPathComponent:@"error"];
managerConfig.logPath = path;
managerConfig.logLevel = @4;
#warning 填写
managerConfig.appKey = @"xxx";
managerConfig.secretKey = @"xxx";
managerConfig.isOutputLog = YES;
managerConfig.allowDynamicService = YES;
NSLog(@"version = %@",[SSOralEvaluatingManager version]);
[SSOralEvaluatingManager registerEvaluatingManagerConfig:managerConfig];
// user id请保持在注册、鉴权请求和评测的时候使用同一个user id
[[SSOralEvaluatingManager shareManager] registerEvaluatingType:OralEvaluatingTypeLine userId:@"guest"];鉴权代码:
// 这个方法主要是获取 warrant_id 和 expire_at,客户的研发同学可以根据服务端的要求自己写请求,
// 然后是[[SSOralEvaluatingManager shareManager] setAuthInfoWithWarrantId:warrantId AuthTimeout:expire_at];
#warning 需要配置地址
// 设置请求 URL
NSURL *url = [NSURL URLWithString:@""];
// 创建 NSMutableURLRequest 对象
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
request.HTTPMethod = @"POST";
// 设置请求体
NSString *bodyString = @"user_id=guset&app_id=xxx";
NSData *bodyData = [bodyString dataUsingEncoding:NSUTF8StringEncoding];
request.HTTPBody = bodyData;
// 创建 NSURLSession
NSURLSession *session = [NSURLSession sharedSession];
// 创建数据任务
NSURLSessionDataTask *task = [session dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
if (error) {
NSLog(@"Error occurred: %@", error);
return;
}
if (data) {
NSError *jsonError;
id jsonObject = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:&jsonError];
if (jsonError) {
NSLog(@"Error parsing JSON: %@", jsonError);
NSString *responseString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSLog(@"Response String: %@", responseString);
} else {
NSLog(@"JSON Object: %@", jsonObject);
if ([jsonObject isKindOfClass:[NSDictionary class]]) {
NSLog(@"%@",jsonObject);
NSDictionary * dict = (NSDictionary *)jsonObject;
if ([dict[@"code"] integerValue]==0) {
if (dict[@"data"] && dict[@"data"][@"warrant_id"]) {
NSString * warrantId = [NSString stringWithFormat:@"%@",dict[@"data"][@"warrant_id"]];
NSString * expire_at = [NSString stringWithFormat:@"%@",dict[@"data"][@"expire_at"]];
[[SSOralEvaluatingManager shareManager] setAuthInfoWithWarrantId:warrantId AuthTimeout:expire_at];
}
}
}
}
} else {
NSLog(@"Data was nil");
}
}];
// 启动任务
[task resume];开始评测
//请确保SSOralEvaluatingManager的当前代理是自己
[SSOralEvaluatingManager shareManager].delegate = self;
//初始化参数
SSOralEvaluatingConfig *config = [[SSOralEvaluatingConfig alloc]init];
config.oralContent = @"hello";
config.oralType = OralTypeWord;
//开始评测
[[SSOralEvaluatingManager shareManager] startEvaluateOralWithConfig:config];结束评测
[[SSOralEvaluatingManager shareManager] stopEvaluate];查看结果
- (void)oralEvaluatingDidEndWithResult:(NSString *)result isLast:(BOOL)isLast {
//评测结果回调
NSLog(@"result:%@",result);
}
- (void)oralEvaluatingDidEndError:(NSError *)error {
//评测错误回调
NSLog(@"error:%@",error);
}
- (void)oralEvaluatingDidVADFrontTimeOut {
NSLog(@"前置超时");
//建议取消
[[SSOralEvaluatingManager shareManager] cancelEvaluate];
}
- (void)oralEvaluatingDidVADBackTimeOut {
NSLog(@"后置超时");
}完整调用文件
可参考demo的开发
AppDelegate.m
#import "AppDelegate.h"
#import "RootViewController.h"
#import <AVFoundation/AVFoundation.h>
#import "OnlineEvaluatingHomepageViewController.h"
#import "MockData.h"
@interface AppDelegate ()
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
[self registerEngine];
[self getWarrntId];
self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
OnlineEvaluatingHomepageViewController *controller = [[OnlineEvaluatingHomepageViewController alloc]init];
self.window.rootViewController = [[UINavigationController alloc] initWithRootViewController:controller];
[self.window makeKeyAndVisible];
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"bottom-backg_23"] forBarMetrics:UIBarMetricsDefault];
[[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
[[UINavigationBar appearance] setTitleTextAttributes:@{
NSForegroundColorAttributeName : [UIColor whiteColor]}];
AVAudioSession *session = [AVAudioSession sharedInstance];
[session setCategory:AVAudioSessionCategoryPlayback error:NULL];
[session setActive:YES error:NULL];
// Override point for customization after application launch.
return YES;
}
- (void)getWarrntId {
// 这个方法主要是获取 warrant_id 和 expire_at,客户的研发同学可以根据服务端的要求自己写请求,
// 然后是[[SSOralEvaluatingManager shareManager] setAuthInfoWithWarrantId:warrantId AuthTimeout:expire_at];
// 设置请求体
if ([kAppKey isEqual: @""] || [kUserId isEqual: @""] || [kAuthUrl isEqual: @""]) {
return;
}
#warning 需要配置地址
// 设置请求 URL
NSURL *url = [NSURL URLWithString:kAuthUrl];
// 创建 NSMutableURLRequest 对象
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
request.HTTPMethod = @"POST";
#warning 需要配置userId 和 appId
NSString *bodyString = [NSString stringWithFormat:@"user_id=%@&app_id=%@",kUserId,kSecretKey];
NSData *bodyData = [bodyString dataUsingEncoding:NSUTF8StringEncoding];
request.HTTPBody = bodyData;
// 创建 NSURLSession
NSURLSession *session = [NSURLSession sharedSession];
// 创建数据任务
NSURLSessionDataTask *task = [session dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
if (error) {
NSLog(@"Error occurred: %@", error);
return;
}
if (data) {
NSError *jsonError;
id jsonObject = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:&jsonError];
if (jsonError) {
NSLog(@"Error parsing JSON: %@", jsonError);
NSString *responseString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSLog(@"Response String: %@", responseString);
} else {
NSLog(@"JSON Object: %@", jsonObject);
if ([jsonObject isKindOfClass:[NSDictionary class]]) {
NSLog(@"%@",jsonObject);
NSDictionary * dict = (NSDictionary *)jsonObject;
if ([dict[@"code"] integerValue]==0) {
if (dict[@"data"] && dict[@"data"][@"warrant_id"]) {
NSString * warrantId = [NSString stringWithFormat:@"%@",dict[@"data"][@"warrant_id"]];
NSString * expire_at = [NSString stringWithFormat:@"%@",dict[@"data"][@"expire_at"]];
[[SSOralEvaluatingManager shareManager] setAuthInfoWithWarrantId:warrantId AuthTimeout:expire_at];
}
}
}
}
} else {
NSLog(@"Data was nil");
}
}];
// 启动任务
[task resume];
}
-(void)registerEngine
{
//注册评测
SSOralEvaluatingManagerConfig *managerConfig = [[SSOralEvaluatingManagerConfig alloc]init];
NSString *path = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject] stringByAppendingPathComponent:@"error"];
managerConfig.logPath = path;
managerConfig.logLevel = @4;
if ([kAppKey isEqual: @""]) {
return;
}
#warning 填写MockData
managerConfig.appKey = kAppKey;
managerConfig.secretKey = kSecretKey;
managerConfig.isOutputLog = YES;
managerConfig.allowDynamicService = YES;
NSLog(@"version = %@",[SSOralEvaluatingManager version]);
[SSOralEvaluatingManager registerEvaluatingManagerConfig:managerConfig];
// user id请保持在注册、鉴权请求和评测的时候使用同一个user id
[[SSOralEvaluatingManager shareManager] registerEvaluatingType:OralEvaluatingTypeLine userId:@"guest"];
}
- (void)applicationWillResignActive:(UIApplication *)application {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
}
- (void)applicationDidEnterBackground:(UIApplication *)application {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}
- (void)applicationWillEnterForeground:(UIApplication *)application {
// Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
}
- (void)applicationDidBecomeActive:(UIApplication *)application {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}
- (void)applicationWillTerminate:(UIApplication *)application {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}
@end
MockData.h
#ifndef MockData_h
#define MockData_h
#import <Foundation/Foundation.h>
#define kUserId @"guest"
#define kAppKey @""
#define kSecretKey @""
#define kAuthUrl @""
@interface MockData : NSObject
@property (nonatomic, copy, nullable) NSString *appKey; // appKey
@property (nonatomic, copy, nullable) NSString *secretKey; // sk
@property (nonatomic, copy, nullable) NSString *userId; // userId
@property (nonatomic, copy, nullable) NSString *authUrl; // userId
@end
#endif /* MockData_h */
VC.m
#import "PchaVC.h"
#import <AVFoundation/AVFoundation.h>
#import "CustomButton.h"
#import "MBProgressHUD.h"
@interface PchaVC ()<SSOralEvaluatingManagerDelegate>
@property (nonatomic, strong) UIButton *startButton;
@property (nonatomic, strong) UIButton *playButton;
@property (nonatomic, strong) UIImageView *animalView;
@property (nonatomic, strong) SSOralEvaluatingConfig *config;
@property (nonatomic, strong) AVAudioPlayer *player;
@property (nonatomic, strong) NSString * currentRecordId;
@property (nonatomic, strong) UIScrollView * scrollView;
@property (nonatomic, strong) UIView * topView;
@property (nonatomic, strong) UIView * bottomView;
@property (nonatomic, strong) UILabel * ansLabel;
@property (nonatomic, strong) AVSpeechSynthesizer * synthesizer;
@end
@implementation PchaVC
-(void)dealloc{
NSLog(@"~~~~~~~~~~~~~~%@ dealloac",self);
}
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor hexString:@"e4e4e4"];
_config = [[SSOralEvaluatingConfig alloc]init];
_config.userId = @"123";
_config.mixedType = MixedTypeOnline;
[self loadSubviews];
[self setNav];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
if (self.isFinished) {
[self playVoiceWithText:self.waiter];
}else{
[self playVoiceWithText:self.model.question];
}
});
// Do any additional setup after loading the view.
}
-(void)playVoiceWithText:(NSString *)string{
self.synthesizer = [[AVSpeechSynthesizer alloc] init];
AVSpeechUtterance *utterance = [AVSpeechUtterance speechUtteranceWithString:string];
AVSpeechSynthesisVoice *voiceType = [AVSpeechSynthesisVoice voiceWithLanguage:@"en-US"];
utterance.voice = voiceType;
//设置语速
utterance.rate *= 0.9;
//设置音量
utterance.volume = 0.8;
[self.synthesizer speakUtterance:utterance];
}
-(void)stopVoice{
if (self.synthesizer.isSpeaking) {
[self.synthesizer stopSpeakingAtBoundary:AVSpeechBoundaryImmediate];
}
}
-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
[SSOralEvaluatingManager shareManager].delegate = self;
}
-(void)loadSubviews{
self.scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 64, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height-64-95)];
self.scrollView.backgroundColor = [UIColor clearColor];
[self.view addSubview:self.scrollView];
self.topView = [[UIView alloc]initWithFrame:CGRectMake(10, 25, self.scrollView.width-20, 200)];
self.topView.backgroundColor = [UIColor whiteColor];
self.topView.layer.masksToBounds = YES;
self.topView.layer.cornerRadius = 5;
[self.scrollView addSubview:self.topView];
UILabel * qLabel = [[UILabel alloc]init];
qLabel.font = [UIFont systemFontOfSize:14];
qLabel.numberOfLines = 0;
qLabel.textColor = [UIColor blackColor];
qLabel.frame = CGRectMake(25, 40, self.topView.width-40, 48);
qLabel.adjustsFontSizeToFitWidth=YES;
[self.topView addSubview:qLabel];
if (self.isFinished) {
qLabel.y = 70;
qLabel.text = [NSString stringWithFormat:@"Waiter:%@",self.waiter];
return;
}else{
qLabel.text = [NSString stringWithFormat:@"Waiter:%@",self.model.question];
}
// UILabel * Guest = [[UILabel alloc]init];
// Guest.text = @"Guest:";
// Guest.font = [UIFont systemFontOfSize:15];
// Guest.textColor = [UIColor blackColor];
// Guest.frame = CGRectMake(25, CGRectGetMaxY(qLabel.frame), 60, 44);
// [self.topView addSubview:Guest];
_ansLabel = [[UILabel alloc]init];
_ansLabel.text = @"Guest:_________________________";
_ansLabel.adjustsFontSizeToFitWidth=YES;
_ansLabel.font = qLabel.font;
_ansLabel.textColor = [UIColor blackColor];
_ansLabel.frame = CGRectMake(25, CGRectGetMaxY(qLabel.frame), self.topView.width-40-25, 44);
[self.topView addSubview:_ansLabel];
UILabel * tipsLabel = [[UILabel alloc]init];
tipsLabel.text = [NSString stringWithFormat:@"tips:%@",[self.model.tips componentsJoinedByString:@","]];
tipsLabel.font = qLabel.font;
tipsLabel.textColor = [UIColor blackColor];
tipsLabel.numberOfLines = 2;
tipsLabel.frame = CGRectMake(25, CGRectGetMaxY(_ansLabel.frame), self.topView.width-40, 44);
[self.topView addSubview:tipsLabel];
self.bottomView = [[UIView alloc]initWithFrame:CGRectMake(10, CGRectGetMaxY(self.topView.frame), self.scrollView.width-20, 250)];
self.bottomView.backgroundColor = [UIColor clearColor];
[self.scrollView addSubview:self.bottomView];
self.scrollView.contentSize = CGSizeMake(self.view.width, CGRectGetMaxY(self.bottomView.frame)+20);
_startButton = [self buttonWithTitle:@"长按跟读" imageName:@"_04"];
[_startButton addTarget:self action:@selector(startOral) forControlEvents:UIControlEventTouchDown];
[_startButton addTarget:self action:@selector(stopOral) forControlEvents:UIControlEventTouchUpInside | UIControlEventTouchUpOutside];
[self.view addSubview:_startButton];
_playButton = [self buttonWithTitle:@"我的录音" imageName:@"10"];
[_playButton addTarget:self action:@selector(playRecore) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:_playButton];
UIButton * _popButton = [self buttonWithTitle:@"点击后退" imageName:@"ic_pop_btn"];
[_popButton addTarget:self action:@selector(popAction) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:_popButton];
NSInteger count = 3;
CGFloat btnWidth = 60;
CGFloat btnHeight = 80;
CGFloat btn_Y = self.view.frame.size.height-90;
CGFloat spaceWidth = (self.view.frame.size.width-count*btnWidth)/(count+1);
_startButton.frame = CGRectMake(0, btn_Y, btnWidth, btnHeight);
_playButton.frame = CGRectMake(0, btn_Y, btnWidth, btnHeight);
_popButton.frame = CGRectMake(0, btn_Y, btnWidth, btnHeight);
_startButton.x = 2*spaceWidth+ btnWidth;
_playButton.x = 3*spaceWidth + 2*btnWidth;
_popButton.x = spaceWidth;
NSMutableArray *images = [NSMutableArray array];
for (int i = 1; i< 15 ; i++) {
NSString *name = [NSString stringWithFormat:@"record_animate_%02d",i];
UIImage *image = [UIImage imageNamed:name];
if (image) {
[images addObject:image];
}
}
_animalView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 50, 74)];
[_animalView setAnimationImages:images];
[_animalView setAnimationDuration:0.0];
[self.view addSubview:_animalView];
_animalView.center = CGPointMake(self.view.center.x, self.view.center.y+50);
}
- (UIButton *)buttonWithTitle:(NSString *)title imageName:(NSString *)imageName{
UIButton *button = [CustomButton new];
NSAttributedString *attr = [[NSAttributedString alloc]initWithString:title attributes:@{NSFontAttributeName : [UIFont systemFontOfSize:14],
NSForegroundColorAttributeName : [UIColor hexString:@"3d3d3d"]}];
[button setAttributedTitle:attr forState:UIControlStateNormal];
[button setImage:[UIImage imageNamed:imageName] forState:UIControlStateNormal];
[button setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
return button;
}
-(void)setResultViewWithDict:(NSDictionary *)result andTips:(NSString *)tips{
for(UIView * view in self.bottomView.subviews){
[view removeFromSuperview];
}
UILabel * titleLbl = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, self.bottomView.width, 60)];
titleLbl.textColor = [UIColor blackColor];
titleLbl.text = @"评分结果";
titleLbl.font = [UIFont systemFontOfSize:18];
titleLbl.textAlignment = NSTextAlignmentCenter;
[self.bottomView addSubview:titleLbl];
UIImageView *scoreBack = [[UIImageView alloc]initWithFrame:CGRectMake(self.bottomView.width/2-35, CGRectGetMaxY(titleLbl.frame), 70, 70)];
scoreBack.image = [UIImage imageNamed:[self getPicFromScore:[NSString stringWithFormat:@"%@",result[@"overall"]]]];
[self.bottomView addSubview:scoreBack];
UILabel *scoreLb = [[UILabel alloc]initWithFrame:scoreBack.frame];
scoreLb.text = [NSString stringWithFormat:@"%@",result[@"overall"]];
scoreLb.textColor = [self getScoreColorFromScore:[NSString stringWithFormat:@"%@",result[@"overall"]]];
scoreLb.textAlignment = NSTextAlignmentCenter;
scoreLb.font = [UIFont systemFontOfSize:20];
[self.bottomView addSubview:scoreLb];
scoreLb.hidden = YES;
titleLbl.hidden = YES;
scoreBack.hidden = YES;
UILabel *totalLb = [[UILabel alloc]initWithFrame:CGRectMake(0, scoreBack.frame.origin.y+scoreBack.frame.size.height+5, self.bottomView.frame.size.width, 30)];
totalLb.textAlignment = NSTextAlignmentCenter;
totalLb.text = tips;
[self.bottomView addSubview:totalLb];
}
//开始动画
- (void)startAnimation {
_animalView.hidden = NO;
[_animalView startAnimating];
}
//结束动画
- (void)stopAnimation {
[self.animalView stopAnimating];
self.animalView.hidden = YES;
}
//结束评测
- (void)stopOral {
[self stopAnimation];
[[Untilities evaluatingManager] stopEvaluate];
}
//播放录音
- (void)playRecore {
[self stopVoice];
NSString * path = [SSOralEvaluatingManager recordPathWithTokenId:self.currentRecordId];
[self playAudioWithPath:path];
}
-(void)popAction{
[self stopVoice];
[self.navigationController popViewControllerAnimated:YES];
}
-(void)playAudioWithPath:(NSString *)path{
if (path==nil) {
return;
}
AVAudioSession *session = [AVAudioSession sharedInstance];
[session setCategory:AVAudioSessionCategoryPlayback error:NULL];
// [session setActive:YES error:NULL];
self.player = [[AVAudioPlayer alloc]initWithContentsOfURL:[NSURL URLWithString:path] error:nil];
self.player.volume = 1;
[self.player prepareToPlay];
[self.player play];
}
//开始评测
-(void)startOral{
[self startAnimation];
[self stopVoice];
self.config.oralType = OralTypeEnglishPcha;
NSMutableArray *answerArray = [NSMutableArray array];
for(NSString * text in self.model.answers){
SSOralEvaluatingAnswer *answer = [[SSOralEvaluatingAnswer alloc]init];
answer.rank = 100;
answer.answer = text;
[answerArray addObject:answer];
}
self.config.answerArray = answerArray;
self.config.initiativeSetAudio = YES;
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayAndRecord withOptions:AVAudioSessionCategoryOptionMixWithOthers|AVAudioSessionCategoryOptionAllowBluetooth|AVAudioSessionCategoryOptionDefaultToSpeaker error:NULL];
[[Untilities evaluatingManager] startEvaluateOralWithConfig:self.config];
}
#pragma mark - OralEvaluatingManagerDelegate
-(void)oralEvaluatingDidStart{
}
- (void)oralEvaluatingReturnRecordId: (NSString *)recordId{
self.currentRecordId = recordId;
}
- (void)oralEvaluatingDidEndWithResult:(NSDictionary *)result isLast:(BOOL)isLast {
[MBProgressHUD hideHUDForView:self.view animated:YES];
NSLog(@"%@",result);
NSInteger index = [result[@"result"][@"index"] integerValue];
BOOL allowNext = YES;
NSString * tips = @"哇!";
if (index==0) {
tips = @"啥也没听见,请重新跟读";
allowNext = NO;
[self playVoiceWithText:self.model.sorry];
}else {
if (index<=self.model.keywords.count) {
NSString * keywords = [self.model.keywords objectAtIndex:(index-1)];
NSArray * details = (NSArray *)result[@"result"][@"details"];
NSInteger score = 0;
for(NSString * word in [keywords componentsSeparatedByString:@" "]){
for(NSDictionary * item in details){
NSString * string = [NSString stringWithFormat:@"%@",item[@"char"]];
if ([string containsString:word]) {
score += [item[@"score"] integerValue];
break;
}
}
}
score = score/[keywords componentsSeparatedByString:@" "].count;
NSInteger totleScore = [result[@"result"][@"overall"] integerValue];
if (totleScore>=60&&totleScore<80) {
if (score==0) {
tips = @"哎呀,没有听到关键词!";
[self playVoiceWithText:self.model.sorry];
allowNext = NO;
}else if (score >0&&score<60){
tips = @"有点听不清关键词哦!";
[self playVoiceWithText:@"Sorry, I didn't catch what you said. Please say it again"];
allowNext = NO;
}else if (score >=60&&score<90){
tips = @"不错!不错!继续努力";
allowNext = YES;
}else{
tips = @"说的很好呦!";
allowNext = YES;
}
}else if (totleScore>=80&&totleScore<=100){
if (score<60) {
tips = @"有点听不清关键词哦!";
[self playVoiceWithText:@"Sorry, I didn't catch what you said. Please say it again"];
allowNext = NO;
}else if (score >=60&&score<90){
tips = @"不错!不错!继续努力";
allowNext = YES;
}else if (score >=90&&score<100){
tips = @"说的很好呦!";
allowNext = YES;
}else{
allowNext = YES;
tips = @"哇!太棒啦!";
}
}
else{
allowNext = NO;
if (score==0) {
tips = @"哎呀,没有听到关键词!";
[self playVoiceWithText:self.model.sorry];
}else if (score >0&&score<60){
tips = @"有点听不清关键词哦!";
[self playVoiceWithText:@"Sorry, I didn't catch what you said. Please say it again"];
}else{
tips = @"整体分数有点低哦!加油!";
}
}
}
}
[self setResultViewWithDict:(NSDictionary*)result[@"result"] andTips:tips];
if (allowNext) {
_ansLabel.text = [NSString stringWithFormat:@"Guest:%@",[self.model.tips objectAtIndex:(index-1)]];
if (self.model.level+1!=LEVEL_FOUR) {
PchaLevelModel * model = [[PchaLevelModel alloc]initModelWithLevel:self.model.level+1 category:index];
model.respond = [NSString stringWithFormat:@"%@",[self.model.tips objectAtIndex:(index-1)]];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
PchaVC * vc = [[PchaVC alloc]init];
vc.model = model;
[self.navigationController pushViewController:vc animated:YES];
});
}else{
if (index<=self.model.keywords.count&&index>0){
NSString * keywords = self.model.keywords[index-1];
NSString * waiter = @"";
if ([self.model.respond containsString:@"tea"]) {
waiter = [NSString stringWithFormat:@"Ok. A cup of %@ %@. Please wait at your seat. ",keywords,self.model.respond];
NSLog(@"Ok. A cup of %@ %@. Please wait at your seat. ",keywords,self.model.respond);
}else{
waiter = [NSString stringWithFormat:@"Ok. A glass of %@ %@. Please wait at your seat. ",keywords,self.model.respond];
NSLog(@"Ok. A glass of %@ %@. Please wait at your seat. ",keywords,self.model.respond);
}
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
PchaVC * vc = [[PchaVC alloc]init];
vc.isFinished = YES;
vc.waiter = waiter;
[self.navigationController pushViewController:vc animated:YES];
});
}
}
}
}
-(void)oralEvaluatingRealTimeCallBack:(NSDictionary *)result{
}
- (void)oralEvaluatingDidEndError:(NSError *)error {
[MBProgressHUD hideHUDForView:self.view animated:YES];
NSLog(@">>>>>>>>>%@",error);
[[Untilities evaluatingManager] cancelEvaluate];
}
/**
VAD(前置时间)超时回调
*/
- (void)oralEvaluatingDidVADFrontTimeOut{
NSLog(@"----------------前置 超时-------------------");
}
/**
VAD(后置时间)超时回调
*/
- (void)oralEvaluatingDidVADBackTimeOut{
NSLog(@"----------------后置 超时-------------------");
}
-(void)setNav{
UIView *navView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 64)];
navView.backgroundColor = [UIColor colorWithRed:16.0/255.0 green:40.0/255.0 blue:91.0/255.0 alpha:1];
[self.view addSubview:navView];
UILabel *titleLb = [[UILabel alloc]initWithFrame:CGRectMake(45, 27, self.view.frame.size.width-90, 30)];
titleLb .text = self.title;
titleLb .textAlignment = NSTextAlignmentCenter;
titleLb .textColor = [UIColor whiteColor];
titleLb.text = @"智能对话";
titleLb .font = [UIFont systemFontOfSize:18];
[navView addSubview:titleLb ];
UIButton *leftButton = [UIButton buttonWithType:UIButtonTypeCustom];
leftButton.frame = CGRectMake(0, 19.5, 45, 45);
[leftButton setImage:[UIImage imageNamed:@"back_03"] forState:(UIControlStateNormal)];
leftButton.imageView.contentMode = UIViewContentModeScaleAspectFit;
[leftButton addTarget:self action:@selector(backAction) forControlEvents:UIControlEventTouchUpInside];
[navView addSubview:leftButton];
}
-(UIColor *)getScoreColorFromScore:(NSString *)score
{
if (score.integerValue<60) {
return [UIColor hexString:@"e70101" ];
}else if (score.integerValue >=85)
{
return [UIColor hexString:@"07ab07" ];
}else
{
return [UIColor hexString:@"333333" ];
}
}
-(NSString *)getPicFromScore:(NSString *) score
{
if (score.integerValue<60) {
return @"60-" ;
}else if (score.integerValue >=60&&score.integerValue<85)
{
return @"60-85" ;
}else
{
return @"85+";
}
}
-(void)backAction{
[self stopVoice];
[self.navigationController popToRootViewControllerAnimated:YES];
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
@end
3.2 配置动态评测地址
说明:使用 SingSound.framework v1.2.0(查看framework的info.plist或者 打印version方法查看)以上的版本,可无需集成”ServiceManager.h”,SDK内部已具有动态获取测评地址功能
1、首先项目中导入阿里云HTTPDNS SDK ,参考文档 iOS SDK接入 ,只导入即可,注册和调用是通过ServiceManager.h 来完成的。 2、导入 ServiceManager.h 和 ServiceManager.m。
3、#import “ServiceManager.h”,程序启动调用注册方法
[[ServiceManager shareManager]registerHTTPDNS];
4、调用获取评测地址方法,需要填入appKey,示例代码:
[[ServiceManager shareManager]getServiceAddressWithAppkey:\@"t146"
callback:\^(NSString \*serviceAddress) {
NSLog(\@"获取到的地址%\@",serviceAddress);
}];5、拿到serviceAddress之后,初始化引擎,填入到引擎里的服务器地址。示例代码:
SSOralEvaluatingManagerConfig \*config = [[SSOralEvaluatingManagerConfig
alloc]init];
[config setValue:serviceAddress forKey:\@"service"];异常处理 因评测服务器异常产生错误时,会调用
- (void)oralEvaluatingDidEndError:(NSError *)error
当error.code为 16385,16386 ,16387,16388,16389 时,可以用ServiceManager 里的方法重新获取可用的评测地址,并拿着这个地址重新注册引擎,需要等待引擎初始化成功回调后,再进行下一次评测。
注册引擎方法参考本文档1.3的内容
详细文档说明
SSOralEvaluatingManagerConfig
1 appkey
@property (nonatomic, copy) NSString *appKey;
参数
参数 | 描述 |
appKey | appkey |
2 设置secretKey
@property (nonatomic, copy) NSString *secretKey;
参数
参数 | 描述 |
secretKey | secretKey |
3 设置服务器超时时间
@property (nonatomic, assign) NSTimeInterval serverTimeout;
参数
参数 | 描述 |
serverTimeout | 服务器超时时间 默认 60s |
4 设置开启关闭vad
@property (nonatomic, assign) BOOL vad;
参数
参数 | 描述 |
vad | 开启关闭vad 默认 NO |
5 设置前置超时时间
@property (nonatomic, assign) NSTimeInterval frontTime;
参数
参数 | 描述 |
frontTime | 前置超时时间,多少时间没有检测到声音,就报前置超时回调 |
6 设置后置超时时间
@property (nonatomic, assign) NSTimeInterval backTime;
参数
参数 | 描述 |
backTime | 后置超时时间,检测到声音后,过了多少时间没有再次检测到声音,就自动停止测评 |
7 设置离线评测资源(单词或句子)
@property (nonatomic,assign) NSInteger offLineSource;
参数
参数 | 描述 |
offLineSource | 离线资源类型 |
0表示英文资源 1表示只中文资源 2中文和英文 默认0英文 |
8 设置log信息路径
@property (nonatomic, strong) NSString *logPath;
参数
参数 | 描述 |
logPath | 本地路径 |
9 设置log信息级别
@property (nonatomic, strong) NSNumber *logLevel
参数
参数 | 描述 |
logLevel | log信息级别,可传@1 ,@2 ,@3 ,@4 默认是@3 |
10 设置连接超时时间
@property (nonatomic, assign) NSTimeInterval connectTimeout;
参数
参数 | 描述 |
connectTimeout | 连接超时时间 默认 20s |
11 是否打印log
@property (nonatomic, assign) BOOL isOutputLog;
参数
参数 | 描述 |
isOutputLog | 是否打印log,并在本地记录报错日志(日志路径 \~/Documents/SSError) |
12 配置协议头
@property (nonatomic, copy) NSString *protocolHeader;
参数
参数 | 描述 |
protocolHeader | 在线测评支持的协议 默认 wss |
13 配置端口号
@property (nonatomic, copy) NSString *portNumber;
参数
参数 | 描述 |
portNumber | 在线测评支持的端口号 默认无 |
14 动态服务器配置
@property (nonatomic,assign)BOOL allowDynamicService;
参数
参数 | 描述 |
allowDynamicService | 允许使用动态服务器配置,设为YES时,无需手动配置服务器地址,将会自动从服务器获取可用地址。 |
15 开启异步测评
@property (nonatomic,assign)BOOL enableAsync;
参数
参数 | 描述 |
enableAsync | 设置为YES后,开启异步测评。 默认不开启此字段 |
16 配置离线资源路径
@property (nonatomic, copy) NSString *resourcePath;
参数
参数 | 描述 |
resourcePath | 离线资源解压全路径,默认 [NSBundle mainBundle] 的 SingSound.Bundle 里面 |
SSOralEvaluatingManager
1 设置代理 函数 @property (nonatomic, weak) id\<SSOralEvaluatingManagerDelegate> delegate;
参数
参数 | 描述 |
delegate | 代理 |
2 单利返回对象 函数 +(instancetype)shareManager;
3 返回版本号 函数 +(NSString *)version;
4 注册初始化参数 函数
(void)registerEvaluatingManagerConfig:(SSOralEvaluatingManagerConfig *)config;
参数
参数 | 描述 |
config | 初始化参数(详细配置参考SSOralEvaluatingManagerConfig) |
5 注册全局评测模式 函数 -(void)registerEvaluatingType:(OralEvaluatingType)type
参数
参数 | 描述 |
type | 评测模式(OralEvaluatingTypeOffLine:离线,OralEvaluatingTypeLine :在线,OralEvaluatingTypeMixed:混合) |
(初始化对象) 函数
(instancetype)initWithManagerConfig:(SSOralEvaluatingManagerConfig *)config type:(OralEvaluatingType)type;
参数 | 描述 |
type | 评测模式(OralEvaluatingTypeOffLine:离线,OralEvaluatingTypeLine :在线,OralEvaluatingTypeMixed:混合) |
config | 初始化参数(详细配置参考SSOralEvaluatingManagerConfig) |
6 开始评测 函数 -(void)startEvaluateOralWithConfig:(OralEvaluatingConfig *)config;
参数
参数 | 描述 |
config | 评测配置 |
7 开始评测 函数 -(void)startEvaluateOralWithConfig:(SSOralEvaluatingConfig )config storeWavPath:(NSString )storeWavPath;
参数
参数 | 描述 |
config | 评测配置 |
storeWavPath | 音频存储路径 |
8 开始评测(本地音频文件评测,音频格式可选(wav,mp3等),需要将音频格式设置的参数信息跟评测参数同步。) 函数 -(void)startEvaluateOralWithWavPath:(NSString )wavPath config:(OralEvaluatingConfig )config;
参数
参数 | 描述 |
wavPath | 本地音频文件地址 |
config | 评测配置 |
9 停止评测,返回结果 函数 -(void)stopEvaluate;
10 取消评测 函数 -(void)cancelEvaluate;
11 清除所有录音文件 注:只针对调用startEvaluateOralWithConfig:(SSOralEvaluatingConfig *)config 函数 +(BOOL)clearAllRecord;
12 返回录音文件地址 注:只针对调用startEvaluateOralWithConfig:(SSOralEvaluatingConfig )config 函数 +(NSString )recordPathWithTokenId:(NSString *)tokenId;
参数
参数 | 描述 |
tokenId | 结果的tokenId |
13 评测引擎释放 函数 -(void)engineDealloc;
14 开始评测—不开启录音,需要外部传输音频数据
-(void)startNoAudioStreamEvaluateOralWithConfig:(SSOralEvaluatingConfig *)config;
参数 | 描述 |
config | 评测配置 |
15 传输音频数据(NSData类型)给测评服务器
-(void)feedAudioToEvaluateWithData:(NSData *)data;
参数 | 描述 |
data | 音频数据 |
16 配置授权ID和过期时间
-(void)setAuthInfoWithWarrantId:(NSString )warrant_id AuthTimeout:(NSString )timeout;
参数 | 描述 |
warrant_id | 授权id |
timeout | 过期时间戳 |
SSOralEvaluatingConfig
1 设置音频格式
@property (nonatomic, strong) NSString *audioType;
参数 | 描述 |
audioType | 音频格式(默认wav) |
2 设置音频格式-采样率
@property (nonatomic, assign) NSInteger sampleRate;
参数 | 描述 |
sampleRate | 采样率(默认16000) |
3 设置音频格式-声道
@property (nonatomic, assign) NSInteger channel;
参数 | 描述 |
channel | 声道数量(默认1,单声道) |
4 设置音频格式-采样字节数
@property (nonatomic, assign) NSInteger sampleBytes;
参数 | 描述 |
sampleBytes | 采样字节数(默认2) |
5 设置题型
@property (nonatomic, assign) OralType oralType;
参数 | 描述 |
oralType | 口语评测题型(详见题型介绍) |
6 评测模式
@property (nonatomic, assign) MixedType mixedType;
参数 | 描述 |
mixedType | 评测模式(默认混合模式,有网用在线模式,无网用离线模式) |
7 设置评测文本内容
@property (nonatomic, copy) NSString *oralContent;
参数 | 描述 |
oralContent | 口语评测内容 |
8 设置分值
@property (nonatomic, assign) NSUInteger rank;
参数 | 描述 |
rank | 口语评测分值 (默认100) |
9 是否开启边读边评,实时返回数据
@property (nonatomic, assign) BOOL openFeed;
参数 | 描述 |
openFeed | 开启边读边评,实时返回数据,目前支持 句子、段落类型 |
10 是否开启比较音频数据(目前仅支持 OralTypeSentence(英文句子))
@property (nonatomic, assign) BOOL openCompareAudio;
参数 | 描述 |
openCompareAudio | 开启比较音频数据,开启后会在评测完成的结果里返回和标准音频对比数据 |
11 设置标准音频地址 与openCompareAudio 关联
@property (nonatomic, copy) NSString * stdAudioUrl;
参数 | 描述 |
stdAudioUrl | 标准音频地址—-上线前需要给平台提前报备标准音频的基本信息。基本信息包括:音频文本,音频url |
12 设置用户id
@property (nonatomic, copy) NSString *userId;
参数 | 描述 |
userId | 用户ID |
13 设置评分精度
@property (nonatomic, assign) EvaluatingPrecision precision;
参数 | 描述 |
precision | 口语评测精度(可选0.1, 0.5,1) |
14 设置答案
@property (nonatomic, strong) NSArray\<__kindof SSOralEvaluatingAnswer *> *answerArray;
参数 | 描述 |
answerArray | 答案数组 (非必选) 中文有限分支识别评测,必须填写这个字段 |
15 评分松紧度,范围0.8\~1.5,数值越小,打分越严厉和typeThres不能同时传 函数 @property (nonatomic, assign) CGFloat rateScale;
参数 | 描述 |
rateScale | 评分松紧度 |
16 评分松紧度,可传 1,2,3,4。1 表示严格,2 表示宽松,3 表示非常严 格,4 非常宽松。和rateScale不能同时传 函数 @property (nonatomic, assign) NSUInteger typeThres;
参数 | 描述 |
typeThres | 评分松紧度 |
17 句子评测中是否输出每个单词的音标分 @property (nonatomic, assign) BOOL isOutputPhonogramForSentence;
参数 | 描述 |
isOutputPhonogramForSentence | 句子评测中是否输出每个单词的音标分 |
18 重传机制类型 @property (nonatomic, assign) NSInteger enableRetry;
参数 | 描述 |
enableRetry | 0是默认值,不重传;1表示重传,出现这类异常时,等待测评时间很短,重传不会影响用户体验 2表示重传,出现这类异常时,等待测评的时间很长,重传可能会导致用户等待很久。(2包含1重传的情况) |
19 指定单词的发音 @property (nonatomic, copy) NSDictionary *phonesDic;
参数 | 描述 |
phonesDic | 指定单词的发音 例如:{“conversion”:”b uh k”,”hello”:”b uh k”},只支持单词评测。 |
20 此字段 用于英文扩展选择题 @property (nonatomic, assign) NSUInteger pronScale;
参数 | 描述 |
pronScale | 此字段 用于英文扩展选择题 只能设置 0 和 1 (非必选 default:0) |
21 关键字数组(非必选) @property (nonatomic, strong) NSArray\<__kindof NSString *> *keywordArray;
参数 | 描述 |
keywordArray | 关键字数组(非必选 ) |
22 要点数组(非必选) @property (nonatomic, strong) NSArray\<__kindof NSString *> *pointsArray;
参数 | 描述 |
pointsArray | 要点数组(非必选) |
23 错误答案数组(非必选) @property (nonatomic, strong) NSArray\<__kindof NSString *> *wrongWordArray;
参数 | 描述 |
wrongWordArray | 错误答案数组(非必选) OralTypePche扩展选择 必选 |
24 问题 (非必选) @property (nonatomic, strong) NSString *question;
参数 | 描述 |
question | 问题 (非必选) |
25 录音文本(非必选) @property (nonatomic, strong) NSString *recorderContent;
参数 | 描述 |
recorderContent | 录音文本(非必选) |
26 开启音素检错 @property (nonatomic, assign) BOOL checkPhones;
参数 | 描述 |
checkPhones | 英文单词,英文句子 是否开启音素检错 |
27 评测音节信息 @property (nonatomic,assign)BOOL isSyllable;
参数 | 描述 |
isSyllable | 评测音节信息,只支持单词评测,YES/1表示使用此功能,默认NO不使用 |
28 学段 (非必填) @property (nonatomic,assign) NSInteger grade;
参数 | 描述 |
grade | 学段 1表示初中 2表示高中 非必填 |
29 录音回调时间间隔 @property (nonatomic,assign) int recordTimeinterval;
参数 | 描述 |
recordTimeinterval | 录音回调时间间隔 int类型 单位毫秒 |
30 是否由外部设置AVAudioSession category @property (nonatomic,assign) BOOL initiativeSetAudio;
参数 | 描述 |
initiativeSetAudio | 默认 NO 在sdk内部设置, YES由外部设置AVAudioSession category category 只能设置 AVAudioSessionCategoryPlayAndRecord 或者 AVAudioSessionCategoryRecord 如果设置为YES , 必须在( startEvaluateOralWithConfig:)开始测评方法 触发之前设置AVAudioSession category |
31 本地音频评测feed间隔 @property (nonatomic,assign) NSTimeInterval feedTime;
参数 | 描述 |
feedTime | 本地音频评测feed间隔 单位秒 默认0.01s |
32 本地音频评测,分片数据大小 @property (nonatomic,assign) NSInteger feedSize;
参数 | 描述 |
feedSize | 本地音频评测,分片数据大小 默认 3200 |
33 是否开启vad功能 @property (nonatomic,assign) BOOL vadEnable;
参数 | 描述 |
vadEnable | 是否开启vad,如果在初始化时配置了vad功能,默认开启vad |
SSOralEvaluatingConfig
1 设置音频格式
@property (nonatomic, strong) NSString *audioType;
参数 | 描述 |
audioType | 音频格式(默认wav) |
2 设置音频格式-采样率
@property (nonatomic, assign) NSInteger sampleRate;
参数 | 描述 |
sampleRate | 采样率(默认16000) |
3 设置音频格式-声道
@property (nonatomic, assign) NSInteger channel;
参数 | 描述 |
channel | 声道数量(默认1,单声道) |
4 设置音频格式-采样字节数
@property (nonatomic, assign) NSInteger sampleBytes;
参数 | 描述 |
sampleBytes | 采样字节数(默认2) |
5 设置题型
@property (nonatomic, assign) OralType oralType;
参数 | 描述 |
oralType | 口语评测题型(详见题型介绍) |
6 评测模式
@property (nonatomic, assign) MixedType mixedType;
参数 | 描述 |
mixedType | 评测模式(默认混合模式,有网用在线模式,无网用离线模式) |
7 设置评测文本内容
@property (nonatomic, copy) NSString *oralContent;
参数 | 描述 |
oralContent | 口语评测内容 |
8 设置分值
@property (nonatomic, assign) NSUInteger rank;
参数 | 描述 |
rank | 口语评测分值 (默认100) |
9 是否开启边读边评,实时返回数据
@property (nonatomic, assign) BOOL openFeed;
参数 | 描述 |
openFeed | 开启边读边评,实时返回数据,目前支持 句子、段落类型 |
10 是否开启比较音频数据(目前仅支持 OralTypeSentence(英文句子))
@property (nonatomic, assign) BOOL openCompareAudio;
参数 | 描述 |
openCompareAudio | 开启比较音频数据,开启后会在评测完成的结果里返回和标准音频对比数据 |
11 设置标准音频地址 与openCompareAudio 关联
@property (nonatomic, copy) NSString * stdAudioUrl;
参数 | 描述 |
stdAudioUrl | 标准音频地址—-上线前需要给平台提前报备标准音频的基本信息。基本信息包括:音频文本,音频url |
12 设置用户id
@property (nonatomic, copy) NSString *userId;
参数 | 描述 |
userId | 用户ID |
13 设置评分精度
@property (nonatomic, assign) EvaluatingPrecision precision;
参数 | 描述 |
precision | 口语评测精度(可选0.1, 0.5,1) |
14 设置答案
@property (nonatomic, strong) NSArray\<__kindof SSOralEvaluatingAnswer *> *answerArray;
参数 | 描述 |
answerArray | 答案数组 (非必选) 中文有限分支识别评测,必须填写这个字段 |
15 评分松紧度,范围0.8\~1.5,数值越小,打分越严厉和typeThres不能同时传 函数 @property (nonatomic, assign) CGFloat rateScale;
参数 | 描述 |
rateScale | 评分松紧度 |
16 评分松紧度,可传 1,2,3,4。1 表示严格,2 表示宽松,3 表示非常严 格,4 非常宽松。和rateScale不能同时传 函数 @property (nonatomic, assign) NSUInteger typeThres;
参数 | 描述 |
typeThres | 评分松紧度 |
17 句子评测中是否输出每个单词的音标分 @property (nonatomic, assign) BOOL isOutputPhonogramForSentence;
参数 | 描述 |
isOutputPhonogramForSentence | 句子评测中是否输出每个单词的音标分 |
18 重传机制类型 @property (nonatomic, assign) NSInteger enableRetry;
参数 | 描述 |
enableRetry | 0是默认值,不重传;1表示重传,出现这类异常时,等待测评时间很短,重传不会影响用户体验 2表示重传,出现这类异常时,等待测评的时间很长,重传可能会导致用户等待很久。(2包含1重传的情况) |
19 指定单词的发音 @property (nonatomic, copy) NSDictionary *phonesDic;
参数 | 描述 |
phonesDic | 指定单词的发音 例如:{“conversion”:”b uh k”,”hello”:”b uh k”},只支持单词评测。 |
20 此字段 用于英文扩展选择题 @property (nonatomic, assign) NSUInteger pronScale;
参数 | 描述 |
pronScale | 此字段 用于英文扩展选择题 只能设置 0 和 1 (非必选 default:0) |
21 关键字数组(非必选) @property (nonatomic, strong) NSArray\<__kindof NSString *> *keywordArray;
参数 | 描述 |
keywordArray | 关键字数组(非必选 ) |
22 要点数组(非必选) @property (nonatomic, strong) NSArray\<__kindof NSString *> *pointsArray;
参数 | 描述 |
pointsArray | 要点数组(非必选) |
23 错误答案数组(非必选) @property (nonatomic, strong) NSArray\<__kindof NSString *> *wrongWordArray;
参数 | 描述 |
wrongWordArray | 错误答案数组(非必选) OralTypePche扩展选择 必选 |
24 问题 (非必选) @property (nonatomic, strong) NSString *question;
参数 | 描述 |
question | 问题 (非必选) |
25 录音文本(非必选) @property (nonatomic, strong) NSString *recorderContent;
参数 | 描述 |
recorderContent | 录音文本(非必选) |
26 开启音素检错 @property (nonatomic, assign) BOOL checkPhones;
参数 | 描述 |
checkPhones | 英文单词,英文句子 是否开启音素检错 |
27 评测音节信息 @property (nonatomic,assign)BOOL isSyllable;
参数 | 描述 |
isSyllable | 评测音节信息,只支持单词评测,YES/1表示使用此功能,默认NO不使用 |
28 学段 (非必填) @property (nonatomic,assign) NSInteger grade;
参数 | 描述 |
grade | 学段 1表示初中 2表示高中 非必填 |
29 录音回调时间间隔 @property (nonatomic,assign) int recordTimeinterval;
参数 | 描述 |
recordTimeinterval | 录音回调时间间隔 int类型 单位毫秒 |
30 是否由外部设置AVAudioSession category @property (nonatomic,assign) BOOL initiativeSetAudio;
参数 | 描述 |
initiativeSetAudio | 默认 NO 在sdk内部设置, YES由外部设置AVAudioSession category category 只能设置 AVAudioSessionCategoryPlayAndRecord 或者 AVAudioSessionCategoryRecord 如果设置为YES , 必须在( startEvaluateOralWithConfig:)开始测评方法 触发之前设置AVAudioSession category |
31 本地音频评测feed间隔 @property (nonatomic,assign) NSTimeInterval feedTime;
参数 | 描述 |
feedTime | 本地音频评测feed间隔 单位秒 默认0.01s |
32 本地音频评测,分片数据大小 @property (nonatomic,assign) NSInteger feedSize;
参数 | 描述 |
feedSize | 本地音频评测,分片数据大小 默认 3200 |
33 是否开启vad功能 @property (nonatomic,assign) BOOL vadEnable;
参数 | 描述 |
vadEnable | 是否开启vad,如果在初始化时配置了vad功能,默认开启vad |
SSOralEvaluatingManagerDelegate
1 引擎初始化成功 函数 -(void)oralEvaluatingInitSuccess;
2 评测开始 函数 -(void)oralEvaluatingDidStart;
3 评测停止 函数 -(void)oralEvaluatingDidStop;
4 评测成功回调 函数 -(void)oralEvaluatingDidEndWithResult: (NSDictionary *)result isLast:(BOOL)isLast;
参数
参数 | 描述 |
result | 结果字典 |
isLast | 是否是最后一个(保留参数,暂时无用) |
5 评测失败回调 函数 -(void)oralEvaluatingDidEndError: (NSError *)error;
参数
参数 | 描述 |
error | 报错信息 |
6 录音数据回调 函数 -(void)oralEvaluatingRecordingBuffer: (NSData *)recordingData;
参数
参数 | 描述 |
recordingData | 录音数据 |
7 录音音量大小回调 函数 -(void)oralEvaluatingDidUpdateVolume: (int)volume;
参数
参数 | 描述 |
volume | 录音音量大小 |
8 VAD(前置时间)超时回调 函数 -(void)oralEvaluatingDidVADFrontTimeOut;
9 VAD(后置时间)超时回调 函数 -(void)oralEvaluatingDidVADBackTimeOut;
10 录音即将超时(只支持在线模式,单词20s,句子40s) 函数 -(void)oralEvaluatingDidRecorderWillTimeOut;
11 边读边评—-实时回调 函数 -(void)oralEvaluatingRealTimeCallBack:(NSDictionary *)result;
参数 | 描述 |
result | 结果字典 |
12 授权ID需要更新回调 -(void)onWarrantIdNeedUpdate;
13 评测成功回调 (等同上述编号4 回调) 函数 -(void)oralEvaluatingDidEndWithResult: (NSDictionary*)result RequestId:(NSString*)request_id;
参数
参数 | 描述 |
result | 结果字典 |
request_id | 对应本次测评唯一标志信息 |
14 评测失败回调 (等同上述编号5 回调) 函数 -(void)oralEvaluatingDidEndError: (NSError *)error RequestId:(NSString *)request_id;
参数
参数 | 描述 |
error | 报错信息 |
request_id | 对应本次测评唯一标志信息 |