跳到主要内容

接口概述

接口说明

初始化接口

init(Context context, IdrCallback.ICommon iCommon)

context: 上下文 iCommon:通用回调,返回错误码

开启语音识别

startAsr(IdrCallback.IAsr iAsr)

iAsr:语音识别回调,见回调说明

停止语音识别

stopAsr(IdrCallback.ICommon iCommon)

iCommon:通用回调,返回错误码

通用文字识别

recognizeGenText(OcrParam ocrParam, IdrCallback.IOcr iOcr)

ocrParam:文字识别参数,url或file二选一,两者都传优先url

字段类型说明
urlString图片的完整链接地址
fileFile本地图片对象

iOcr:文字识别回调,见回调说明

语音播报

startTTS(String text, IdrCallback.ITts iTts)

text:需要播报的文本内容,限制300字符内 iTts:短语音播报回调,见回调说明

停止语音播报

stopTTS(IdrCallback.ICommon iCommon)

iCommon:通用回调,返回错误码

新建AI会话

newAISession()

询问AI

askAI(String question, String nid, double latitude, double longitude, IdrCallback.IAssistant iAssistant)

question:想咨询的问题 nid:用户id,用于关联账号信息 latitude:当前位置纬度 longitude:当前位置经度 iAssistant:AI结果回调,见回调说明

中断询问AI

abortAI()

身份证二要素验证

verifyID(String certName, String certNo, IdrCallback.ICommon iCommon)

certName:身份证真实姓名 certNo:身份证号 iCommon:通用回调,0表示验证通过,非0不通过

人脸验证

verifyFace(Context context, String certName, String certNo, IdrCallback.ICommon iCommon)

context: 当前上下文 certName:身份证真实姓名 certNo:身份证号 iCommon:通用回调,0表示验证通过,非0不通过

回调说明

语音识别回调

void onFinalResult(String text) 最终结果只回调一次 void onPartialResult(String text) 中间片段结果会多次回调,用于展示和容错 void onRecState(@MoConstant.AcState int state) 录音机当前状态

文字识别回调

void onResult(String json) 重点关注content字段,其他字段选择性处理

字段类型说明
contentstring识别出图片的文字块汇总。
prism_wordsInfolist文字块信息。
    angleint文字块的角度。
    heightint文字块的高度(需考虑文字块的角度)
    widthint文字块的宽度(需考虑文字块的角度)
    poslist文字块的外矩形四个点的坐标按顺时针排列(左上、右上、右下、左下)。
    wordstring文字块的文字内容。
prism_wnumint识别的文字块的数量,prism_wordsInfo 数组的大小。
heightint算法矫正图片后的高度。
widthint算法矫正图片后的宽度。
orgHeightint原图的高度。
orgWidthint原图的宽度。

AI结果回调

void onAnswerFlow(String msg) msg是AI回复的文本流的一部分,会持续返回多次指直到结束。
void onFinish(int error) 单次回答结束,参考sdk错误码说明 void onPlayState(@MoConstant.PlayState int playState) 流式文本播放状态

短语音播报回调

void onPlayState(@MoConstant.PlayState int playState) 播报状态

常量说明

常量描述
AC_STATE_OPENAudioRecord开始录音
AC_STATE_PAUSEAudioRecord暂停录音
AC_STATE_CLOSEAudioRecord录音结束
AP_STATE_PLAYINGAudioPlayer正在播放
AP_STATE_PLAY_FINISHAudioPlayer播放完成

错误码参考

阿里错误码

https://help.aliyun.com/zh/isi/developer-reference/overview-4?spm=a2c4g.11186623.help-menu-30413.d_3_0_1_1_0.373b21b4u8xu4R&scm=20140722.H_173528._.OR_help-T_cn~zh-V_1#567d163059scn

SDK错误码

错误码描述
NO_ERR成功无异常
ERR_INVALID_PARAM参数异常,请检查参数
ERR_WRONG_RESULT结果为空或解析异常
ERR_SOCKET_ABORT消息通道异常中断
ERR_TOO_OFTEN请求太频繁
ERR_MSG_TIME_OUT通道消息超时
ERR_HTTP_UNREACHABLE请求不可达,检查一下网络
ERR_ALI_EMPTY_PARAM参数不能为空
ERR_ALI_INVALID_PARAM参数非法
ERR_ALI_AUTH_BROKEN认证未完成
ERR_ALI_FAIL_TOO_MANY刷脸失败次数过多
ERR_ALI_AUTH_NOT_EXIST身份认证记录不存在
ERR_ALI_SYSALI内部错误