TAIOralEvaluation.h 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. //
  2. // TAIOralEvaluation.h
  3. // TAISDK
  4. //
  5. // Created by kennethmiao on 2018/12/25.
  6. // Copyright © 2018年 kennethmiao. All rights reserved.
  7. //
  8. #import <Foundation/Foundation.h>
  9. #import "TAICommonParam.h"
  10. #import "TAIError.h"
  11. typedef NS_ENUM(NSInteger, TAIOralEvaluationWorkMode)
  12. {
  13. //流式传输
  14. TAIOralEvaluationWorkMode_Stream = 0,
  15. //一次性传输
  16. TAIOralEvaluationWorkMode_Once = 1,
  17. };
  18. typedef NS_ENUM(NSInteger, TAIOralEvaluationTextMode)
  19. {
  20. //普通文本
  21. TAIOralEvaluationTextMode_Noraml = 0,
  22. //音素结构文本
  23. TAIOralEvaluationTextMode_Phoneme = 1,
  24. //音素注册模式
  25. TAIOralEvaluationTextMode_Phoneme_Register = 2,
  26. };
  27. typedef NS_ENUM(NSInteger, TAIOralEvaluationEvalMode)
  28. {
  29. //单词模式
  30. TAIOralEvaluationEvalMode_Word = 0,
  31. //句子模式
  32. TAIOralEvaluationEvalMode_Sentence = 1,
  33. //段落模式
  34. TAIOralEvaluationEvalMode_Paragraph = 2,
  35. //自由模式
  36. TAIOralEvaluationEvalMode_Free = 3,
  37. //单词纠错模式
  38. TAIOralEvaluationEvalMode_Word_Fix = 4,
  39. };
  40. typedef NS_ENUM(NSInteger, TAIOralEvaluationFileType)
  41. {
  42. //pcm
  43. TAIOralEvaluationFileType_Raw = 1,
  44. //wav
  45. TAIOralEvaluationFileType_Wav = 2,
  46. //mp3
  47. TAIOralEvaluationFileType_Mp3 = 3,
  48. };
  49. typedef NS_ENUM(NSInteger, TAIOralEvaluationStorageMode)
  50. {
  51. //关闭存储
  52. TAIOralEvaluationStorageMode_Disable = 0,
  53. //开启存储
  54. TAIOralEvaluationStorageMode_Enable = 1,
  55. //永久存储(请提工单备案)
  56. TAIOralEvaluationStorageMode_Permanent = 2,
  57. //自定义存储(请提工单备案)
  58. TAIOralEvaluationStorageMode_Custom = 3,
  59. };
  60. typedef NS_ENUM(NSInteger, TAIOralEvaluationServerType)
  61. {
  62. //英文
  63. TAIOralEvaluationServerType_English = 0,
  64. //中文
  65. TAIOralEvaluationServerType_Chinese = 1,
  66. };
  67. @interface TAIOralEvaluationParam : TAICommonParam
  68. //业务应用id(默认为default)
  69. @property (nonatomic, strong) NSString *soeAppId;
  70. //唯一标识一次评测
  71. @property (nonatomic, strong) NSString *sessionId;
  72. //传输模式
  73. @property (nonatomic, assign) TAIOralEvaluationWorkMode workMode;
  74. //评估模式
  75. @property (nonatomic, assign) TAIOralEvaluationEvalMode evalMode;
  76. //数据类型(内部录制仅支持mp3)
  77. @property (nonatomic, assign) TAIOralEvaluationFileType fileType;
  78. //音频存储
  79. @property (nonatomic, assign) TAIOralEvaluationStorageMode storageMode;
  80. //语言类型
  81. @property (nonatomic, assign) TAIOralEvaluationServerType serverType;
  82. //文本模式
  83. @property (nonatomic, assign) TAIOralEvaluationTextMode textMode;
  84. //苛刻指数[1.0-4.0]
  85. @property (nonatomic, assign) float scoreCoeff;
  86. //被评估的文本
  87. @property (nonatomic, strong) NSString *refText;
  88. //输出断句中间结果
  89. @property (nonatomic, assign) BOOL sentenceInfoEnabled;
  90. @end
  91. @interface TAIOralEvaluationPhoneInfo : NSObject
  92. //当前音节语音起始时间点,单位为ms
  93. @property (nonatomic, assign) int beginTime;
  94. //当前音节语音终止时间点,单位为ms
  95. @property (nonatomic, assign) int endTime;
  96. //音节发音准确度,取值范围[-1, 100],当取-1时指完全不匹配
  97. @property (nonatomic, assign) float pronAccuracy;
  98. //当前音节是否检测为重音
  99. @property (nonatomic, assign) BOOL detectedStress;
  100. //当前音节
  101. @property (nonatomic, strong) NSString *phone;
  102. //当前音节是否应为重音
  103. @property (nonatomic, assign) BOOL stress;
  104. //参考音素,在单词诊断模式下,代表标准音素
  105. @property (nonatomic, strong) NSString *referencePhone;
  106. @end
  107. @interface TAIOralEvaluationWord : NSObject
  108. //当前单词语音起始时间点,单位为ms
  109. @property (nonatomic, assign) int beginTime;
  110. //当前单词语音终止时间点,单位为ms
  111. @property (nonatomic, assign) int endTime;
  112. //单词发音准确度,取值范围[-1, 100],当取-1时指完全不匹配
  113. @property (nonatomic, assign) float pronAccuracy;
  114. //单词发音流利度,取值范围[0, 1]
  115. @property (nonatomic, assign) float pronFluency;
  116. //当前词
  117. @property (nonatomic, strong) NSString *word;
  118. //当前词与输入语句的匹配情况,0:匹配单词、1:新增单词、2:缺少单词
  119. @property (nonatomic, assign) int matchTag;
  120. //音节评估详情
  121. @property (nonatomic, strong) NSArray<TAIOralEvaluationPhoneInfo *> *phoneInfos;
  122. //参考词
  123. @property (nonatomic, strong) NSString *referenceWord;
  124. @end
  125. @interface TAIOralEvaluationSentenceInfo : NSObject
  126. //句子序号,在段落、自由说模式下有效,表示断句序号,最后的综合结果的为-1.
  127. @property (nonatomic, assign) int sentenceId;
  128. //详细发音评估结果
  129. @property (nonatomic, strong) NSArray<TAIOralEvaluationWord *> *words;
  130. //发音精准度,取值范围[-1, 100],当取-1时指完全不匹配,当为句子模式时,是所有已识别单词准确度的加权平均值,在reftext中但未识别出来的词不计入分数中
  131. @property (nonatomic, assign) float pronAccuracy;
  132. //发音流利度,取值范围[0, 1],当为词模式时,取值无意义;当为流式模式且请求中IsEnd未置1时,取值无意义
  133. @property (nonatomic, assign) float pronFluency;
  134. //发音完整度,取值范围[0, 1],当为词模式时,取值无意义;当为流式模式且请求中IsEnd未置1时,取值无意义
  135. @property (nonatomic, assign) float pronCompletion;
  136. //建议评分,取值范围[0,100],评分方式为建议评分 = 准确度(pronAccuracyfloat) 完整度(pronCompletionfloat)(2 - 完整度(pronCompletionfloat)),如若评分策略不符合请参考Words数组中的详细分数自定义评分逻辑
  137. @property (nonatomic, assign) float suggestedScore;
  138. @end
  139. @interface TAIOralEvaluationRet : NSObject
  140. //唯一标识一次评测
  141. @property (nonatomic, strong) NSString *sessionId;
  142. //单词发音准确度,取值范围[-1, 100],当取-1时指完全不匹配
  143. @property (nonatomic, assign) float pronAccuracy;
  144. //单词发音流利度,取值范围[0, 1]
  145. @property (nonatomic, assign) float pronFluency;
  146. //发音完整度,取值范围[0, 1],当为词模式时,取值无意义
  147. @property (nonatomic, assign) float pronCompletion;
  148. //保存语音音频文件的下载地址(TAIOralEvaluationStorageMode_Enable有效)
  149. @property (nonatomic, strong) NSString *audioUrl;
  150. //详细发音评估结果
  151. @property (nonatomic, strong) NSArray<TAIOralEvaluationWord *> *words;
  152. //建议评分,取值范围[0,100]
  153. //评分方式为建议评分 = 准确度(PronAccuracyfloat)× 完整度(PronCompletionfloat)×(2 - 完整度(PronCompletionfloat))
  154. //如若评分策略不符合请参考Words数组中的详细分数自定义评分逻辑。
  155. @property (nonatomic, assign) float suggestedScore;
  156. //断句中间结果
  157. @property (nonatomic, strong) NSArray<TAIOralEvaluationSentenceInfo*> *sentenceInfoSet;
  158. @end
  159. @interface TAIOralEvaluationData : NSObject
  160. //数据seq,从1开始
  161. @property (nonatomic, assign) NSInteger seqId;
  162. //属否是最后分片数据
  163. @property (nonatomic, assign) BOOL bEnd;
  164. //音频数据
  165. @property (nonatomic, strong) NSData *audio;
  166. @end
  167. @interface TAIRecorderParam : NSObject
  168. //是否开启分片,默认YES
  169. @property (nonatomic, assign) BOOL fragEnable;
  170. //分片大小,默认1024,建议为1024的整数倍,范围【1k-10k】
  171. @property (nonatomic, assign) NSInteger fragSize;
  172. //是否开启静音检测,默认NO
  173. @property (nonatomic, assign) BOOL vadEnable;
  174. //静音检测时间间隔,单位【ms】
  175. @property (nonatomic, assign) NSInteger vadInterval;
  176. @end
  177. @class TAIOralEvaluation;
  178. @protocol TAIOralEvaluationDelegate <NSObject>
  179. /**
  180. * 评估结果回调
  181. * @param oralEvaluation 评测对象
  182. * @param data 音频数据
  183. * @param result 评估结果(最后一个分片返回,其他分片为nil)
  184. * @param error 错误信息
  185. */
  186. - (void)oralEvaluation:(TAIOralEvaluation *)oralEvaluation
  187. onEvaluateData:(TAIOralEvaluationData *)data
  188. result:(TAIOralEvaluationRet *)result
  189. error:(TAIError *)error;
  190. /**
  191. * 静音检测回调
  192. * @param oralEvaluation 评测对象
  193. * @brief 检测到静音内部不会停止录制,业务层可以根据此回调主动停止录制或提示用户
  194. */
  195. - (void)onEndOfSpeechInOralEvaluation:(TAIOralEvaluation *)oralEvaluation;
  196. /**
  197. * 音量分贝变化
  198. * @param oralEvaluation 评测对象
  199. * @param volume 分贝大小
  200. * @brief volume范围【0-120】
  201. */
  202. - (void)oralEvaluation:(TAIOralEvaluation *)oralEvaluation onVolumeChanged:(NSInteger)volume;
  203. @end
  204. typedef void (^TAIOralEvaluationCallback)(TAIError *error);
  205. @interface TAIOralEvaluation : NSObject
  206. /**
  207. * 录制数据回调
  208. */
  209. @property (nonatomic, weak) id<TAIOralEvaluationDelegate> delegate;
  210. /**
  211. * 开始录制和评测
  212. * @param param 参数(内部录制仅支持mp3)
  213. * @param callback 回调
  214. */
  215. - (void)startRecordAndEvaluation:(TAIOralEvaluationParam *)param callback:(TAIOralEvaluationCallback)callback;
  216. /**
  217. * 结束录制和评测
  218. * @param callback 回调
  219. */
  220. - (void)stopRecordAndEvaluation:(TAIOralEvaluationCallback)callback;
  221. /**
  222. * 属否正在录制
  223. * @return BOOL 是否录制
  224. */
  225. - (BOOL)isRecording;
  226. /**
  227. * 设置分片大小,建议为1024的整数倍,范围【1k-10k】,默认为1024*1
  228. * @param size 分片大小
  229. */
  230. - (void)setFragSize:(NSInteger)size DEPRECATED_MSG_ATTRIBUTE("Please usee setRecordParam:");
  231. /**
  232. * 设置录制参数
  233. * @param param 录制参数
  234. */
  235. - (void)setRecorderParam:(TAIRecorderParam *)param;
  236. /**
  237. * 口语评测(外部录制)
  238. * @param param 参数
  239. * @param data 音频数据(三种格式目前仅支持16k采样率16bit编码单声道,如有不一致可能导致评估不准确或失败)
  240. * @param callback 回调
  241. */
  242. - (void)oralEvaluation:(TAIOralEvaluationParam *)param data:(TAIOralEvaluationData *)data callback:(TAIOralEvaluationCallback)callback;
  243. /**
  244. * 获取签名所需字符串
  245. * @param timestamp 时间戳
  246. * @return NSString 签名
  247. */
  248. - (NSString *)getStringToSign:(NSInteger)timestamp;
  249. @end