iOS SDK接入(旧)
该技术服务已迁移至思必驰开放平台,本文档于2020年8月25日停止更新。最新版请查看:https://cloud.aispeech.com/docs/lfasr_iOS
一、功能介绍
录音文件转写,是将已经录制好的音频文件, 通过识别服务,将长段音频数据(5小时以内)转写成文本数据,可用于采访录音转写、音频数据录入、会议记录总结等场景,支持:
- 可用于基于协议开发的:轻量级嵌入式设备;
- 支持pcm,wav, ogg(speex), ogg_opus, mp3格式的音频文件转写;
- 有效任务12个小时内出转写结果;
- 对于大音频文件可以进行分片上传;
- 支持自定义热词和敏感词配置、语言模型自训练功能,请联系商务或项目经理进行定制。
整个识别过程是非实时的,音频文件上传成功后进入等待队列,转写成功后用户可以获取转写结果。返回转写结果时间受排队队列、音频时长因素影响,如转写耗时比平时长,耐心等待即可。
二、调用限制
集成实时长语音转写SDK时,需要注意以下内容:
内容
|
说明
|
---|---|
字符编码 | UTF-8 |
语言种类 | 中文普通话 |
服务鉴权 | 长语音服务使用需要进行授权,详见:服务授权 |
音频属性 | 采样率16k、位长16bits、单声道 |
数据发送 |
post形式上传本地文件或提供http形式可下载的链接 |
音频时长/大小 | 5小时以内,且不超过500M |
音频格式 | pcm,wav, ogg(speex), ogg_opus, mp3 |
并发路数 | 默认5路并发,即可以同时转写5个音频文件 |
转写结果保存时长 | 7天 |
服务开通 | 调用长语音服务需要先购买时长, 您可以领取免费时长资源或购买付费资源包 |
三、集成流程
1、产品创建与授权
产品创建
产品授权
授权详见:基础技术iOS授权说明
2、SDK集成准备
下载SDK
请前往:这里是下载页面的链接, 下载最新版本的SDK。
SDK准备
集成SDK前,需要有:
libDUILiteAuth.a 及头文件
libDUILite_ios_LASR.a 及头文件
3、集成SDK
SDK包说明
libs ------------------- 库文件
sample --------------- demo
SDK集成流程
SDK集成整体流程如下图:
SDK导入
- 建立工程
- 将头文件和 libDUILiteAuth.a,libDUILite_ios_LASR.a库导入工程
- 添加依赖库
使用cocoapod 导入使用到的第三方库(或直接下载导入源码到工程中):
pod 'Reachability', '~> 3.2'
pod 'AFNetworking', '~> 3.2.1'
pod 'FMDB', '2.7.2'
四、SDK 使用说明
到目前为止,离线转写最大支撑5H之内的音频转写, WAV文件在500M左右。
音频文件的识别主要有4个主要步骤:
- 上传音频文件
- 创建离线转写任务
- 查询进度,0-100,达到100说明文件识别完成。服务器需要的识别时间从几分钟到几十分钟不等,视音频文件时间长度而定,如需人工服务还需更长时间。
- 识别完成后可以查询结果
4.1 初始化
[AICloudLASREngine shareInstance];
4.2 上传音频文件
//上传音频文件
[[AICloudLASREngine shareInstance] uploadAudioFile:uploadPath andAudioParam:self.audioParam Progress:^(float progress) {
__strong typeof(weakSelf) strongSelf = weakSelf;
strongSelf.textView.text = [NSString stringWithFormat:@"上传中。。。 %f",progress];
} Success:^(NSDictionary * _Nonnull succeedInfo, NSString * _Nonnull audioId) {
__strong typeof(weakSelf) strongSelf = weakSelf;
strongSelf.audioId = audioId;
strongSelf.textView.text = @"上传成功";
} Failure:^(NSDictionary * _Nonnull errorInfo) {
__strong typeof(weakSelf) strongSelf = weakSelf;
strongSelf.textView.text = @"上传失败";
}];
注:同一时间只允许上传一个文件
4.3 恢复上传
[[AICloudLASREngine shareInstance] uploadResumeWithAudioPath:uploadPath Progress:^(float progress) {
__strong typeof(weakSelf) strongSelf = weakSelf;
strongSelf.textView.text = [NSString stringWithFormat:@"上传中。。。 %f",progress];
} Success:^(NSDictionary * _Nonnull succeedInfo,NSString *audioId) {
__strong typeof(weakSelf) strongSelf = weakSelf;
strongSelf.audioId = audioId;
strongSelf.textView.text = @"上传成功";
} Failure:^(NSDictionary * _Nonnull errorInfo) {
__strong typeof(weakSelf) strongSelf = weakSelf;
strongSelf.textView.text = @"上传失败";
}];
4.4 取消上传
[[AICloudLASREngine shareInstance] cancelUploadFile];
4.5 创建离线转写任务
//创建离线转写任务
AICloudLASRTaskParam *taskParam = [[AICloudLASRTaskParam alloc] init];
//非http形式
taskParam.audioParam = [[AICloudLASRAudioParam alloc] init];
taskParam.audioParam.audioType = @"wav";
taskParam.audioId = self.audioId;//由4.2上传音频文件成功得到audioId
//http形式
taskParam.audioParam = [[AICloudLASRAudioParam alloc] init];
taskParam.audioParam.audioType = @"mp3";
taskParam.isHttp = YES;
taskParam.httpString = @"http://xxxxx.mp3";
taskParam.file_len = 1048576;
[[AICloudLASREngine shareInstance] createTaskWithTaskParam:taskParam Success:^(NSDictionary * _Nonnull succeedInfo) {
self.taskId = [[succeedInfo objectForKey:@"data"] objectForKey:@"task_id"];
self.textView.text = @"创建成功";
} Failure:^(NSDictionary * _Nonnull errorInfo) {
if (errorInfo) {
NSLog(@"errorInfo = %@",errorInfo);
}
self.textView.text = @"创建失败";
}];
4.6 查询转写进度
[[AICloudLASREngine shareInstance] queryTaskProcessWithTaskId:self.taskId Success:^(NSDictionary * _Nonnull succeedInfo) {
NSLog(@"succeedInfo = %@",succeedInfo);
self.textView.text = [NSString stringWithFormat:@"当前进度为:%@",[[succeedInfo objectForKey:@"data"] objectForKey:@"progress"]];
} Failure:^(NSDictionary * _Nonnull errorInfo) {
if (errorInfo) {
NSLog(@"errorInfo = %@",errorInfo);
}
self.textView.text = @"查询失败";
}];
4.7 查询转写结果(当进度查询process值为100时)
[[AICloudLASREngine shareInstance] queryTaskResultWithTaskId:self.taskId Success:^(NSDictionary * _Nonnull succeedInfo) {
NSLog(@"succeedInfo = %@",succeedInfo);
NSArray *resultArr = [succeedInfo objectForKey:@"result"];
NSString *resultString = @"";
for (NSDictionary *dic in resultArr) {
resultString = [resultString stringByAppendingString:[dic objectForKey:@"onebest"]];
}
self.textView.text = resultString;
} Failure:^(NSDictionary * _Nonnull errorInfo) {
if (errorInfo) {
NSLog(@"errorInfo = %@",errorInfo);
self.textView.text = @"查询结果失败";
}
}];
五、SDK 错误码说明
授权时可能遇见的错误码,参考 基础技术授权说明 3.3
识别时可能遇到的错误码,参考 在线语音识别 3.5