UNPKG

@mt-utils/xunfei-lat

Version:

讯飞LAT 语音转文本

358 lines (357 loc) 9.15 kB
/** * 平台系统配置 */ interface SystemConfig { /** * 在平台申请的密钥信息 */ readonly API_SECRET: string; /** * 在平台申请的APPID信息 */ readonly APPID: string; /** * 在平台申请的API_KEY信息 */ readonly API_KEY: string; } /** * 公共参数接口 */ interface CommonParams { /** * 在平台申请的APPID信息 */ app_id: string; } /** * 识别接口的业务参数 */ interface LatRequestParams { /** * 语种 * - 'zh_cn': 中文(支持简单的英文识别) * - 'en_us': 英文 * - 其他小语种参数值需在控制台添加试用或购买后显示 */ language: 'zh_cn' | 'en_us'; /** * 应用领域 * - 'iat': 日常用语 * - 'medical': 医疗 * - 'gov-seat-assistant': 政务坐席助手 * - 'seat-assistant': 金融坐席助手 * - 'gov-ansys': 政务语音分析 * - 'gov-nav': 政务语音导航 * - 'fin-nav': 金融语音导航 * - 'fin-ansys': 金融语音分析 */ domain: 'iat' | 'medical' | 'gov-seat-assistant' | 'seat-assistant' | 'gov-ansys' | 'gov-nav' | 'fin-nav' | 'fin-ansys'; /** * 方言,当前仅在language为中文时,支持方言选择。 * - 'mandarin': 中文普通话、其他语种 * - 其他方言参数值需在控制台添加试用或购买后显示 */ accent: 'mandarin'; /** * 用于设置后端点检测的静默时间,单位是毫秒。 * 默认2000(小语种除外,小语种不设置该参数默认为未开启VAD)。 */ vad_eos?: number; /** * 动态修正(仅中文普通话支持) * - 'wpgs': 开启流式结果返回功能 */ dwa?: 'wpgs'; /** * 领域个性化参数(仅中文支持) * - 'game': 游戏 * - 'health': 健康 * - 'shopping': 购物 * - 'trip': 旅行 */ pd?: 'game' | 'health' | 'shopping' | 'trip'; /** * 是否开启标点符号添加(仅中文支持) * - 1: 开启(默认值) * - 0: 关闭 */ ptt?: 0 | 1; /** * 字体(仅中文支持) * - 'zh-cn': 简体中文(默认值) * - 'zh-hk': 繁体香港 */ rlang?: 'zh-cn' | 'zh-hk'; /** * 返回子句结果对应的起始和结束的端点帧偏移值。 * - 0: 关闭(默认值) * - 1: 开启 */ vinfo?: 0 | 1; /** * 数字格式规则为阿拉伯数字格式(中文普通话和日语支持) * - 0: 关闭 * - 1: 开启(默认值) */ nunum?: 0 | 1; /** * speex音频帧长,仅在speex音频时使用 * - 1: 当speex编码为标准开源speex编码时必须指定 * - 2: 当speex编码为讯飞定制speex编码时不要设置 */ speex_size?: number; /** * 获取在发音相似时的句子多侯选结果。 * 取值范围[1,5],设置多候选会影响性能,响应时间延迟200ms左右。 */ nbest?: number; /** * 获取在发音相似时的词语多侯选结果。 * 取值范围[1,5],设置多候选会影响性能,响应时间延迟200ms左右。 */ wbest?: number; } /** * 节流参数 */ interface SectionDelayParams { /** * 是否自动控制结束 */ readonly autoControl: boolean; /** * 第一次延迟时间 */ readonly initialDelay?: number; /** * 后续延迟时间 */ readonly subsequentDelay?: number; /** * 识别为内容空是否继续延迟识别 */ readonly isKeepRecognizingOnEmpty?: boolean; } declare enum DataParamsStatusEnum { /** * 音频数据开始,开始标识 */ START = 0, /** * 音频数据中,中间数据 */ CONTINUE = 1, /** * 音频数据结束,结束标识 */ END = 2 } /** * 数据流参数 */ interface DataParams { /** * 音频数据的位置 */ status: DataParamsStatusEnum; /** * 音频的采样率支持16k和8k * - '16k音频': 'audio/L16;rate=16000' * - '8k音频': 'audio/L16;rate=8000' */ format: 'audio/L16;rate=16000' | 'audio/L16;rate=8000'; /** * 音频数据格式 * - 'raw': 原生音频(支持单声道的pcm) * - 'speex': speex压缩后的音频(8k) * - 'speex-wb': speex压缩后的音频(16k) * - 'lame': mp3格式(仅中文普通话和英文支持,方言及小语种暂不支持) */ encoding: 'raw' | 'speex' | 'speex-wb' | 'lame'; /** * 音频内容,采用base64编码 */ audio: string; } /** * 请求参数 */ interface RequestParams { common: CommonParams; business: LatRequestParams; data: DataParams; } /** * 对外暴露的事件名称 */ type PublicCustomEventName = 'appCreate' | 'appActive' | 'appStart' | 'appFinish' | 'appResultText' | 'appResponseText'; /** * 内部使用的事件名称 */ type PrivateCustomEventName = /** * 录音输出音频数据 */ '_recordActuatorFinish' /** * 音频数据转换器 */ | '_processorAudioFinish' /** * 音频数据切割器 */ | '_splitAudioFinish' /** * 发送请求 */ | '_latRequestFinish' | '_latRequestOpen' /** * 响应文本 */ | '_appResponseText' | '_appResultText' /** * 整个应用 */ | '_appFinish' | '_appStart' | '_operateFinish'; /** * 发送消息给worker */ interface SendWorkerMessage<T = any> { readonly type: 'send'; readonly data?: T; } /** * 接收来自worker的消息 */ interface ReplyWorkerMessage<T = any> { readonly type: 'success'; readonly data: T; } /** * 带uid的worker消息 */ interface ParallelHandlerSendWorkerMessage<T = any> extends SendWorkerMessage<T> { readonly uuid: string; } /** * 带uid的worker回复消息 */ interface ParallelHandlerReplyWorkerMessage<T = any> extends ReplyWorkerMessage<T> { readonly uuid: string; } type CustomEventCallback = (data?: any) => void; declare enum SystemStatus { /** * 空闲状态 */ OFFLINE = "offline", /** * 执行中 */ EXECUTE = "execute" } /** * 识别结果 */ interface LatResponse { /** * API调用的状态码 */ code: number; /** * API调用的返回消息 */ message: string; /** * 会话ID */ sid: string; /** * API调用的数据部分 */ data: { /** * 识别结果 */ result: { /** * 识别结果的开始时间(单位:帧,1帧=10ms) */ bg: number; /** * 识别结果的结束时间(单位:帧,1帧=10ms) */ ed: number; /** * 是否是最后一个结果 */ ls: boolean; /** * 结果序列号 */ sn: number; /** * 动态修正字段,'apd'表示追加,'rpl'表示替换 */ pgs?: 'apd' | 'rpl'; /** * 替换范围,表示需要替换的识别结果的序号范围 */ rg?: number[]; /** * 端点帧偏移值信息 */ vad?: { /** * 端点帧偏移值结果数组 */ ws: Array<{ /** * 起始的端点帧偏移值(单位:帧,1帧=10ms) */ bg: number; /** * 结束的端点帧偏移值(单位:帧,1帧=10ms) */ ed: number; /** * 无需关心的值 */ eg: number; }>; }; /** * 识别结果数组 */ ws: Array<{ /** * 识别结果的开始时间(单位:帧,1帧=10ms) */ bg: number; /** * 识别结果的候选词数组 */ cw: Array<{ /** * 候选词的得分 */ sc: number; /** * 识别出的词 */ w: string; }>; }>; }; /** * 识别结果是否结束标识: * 0:识别的第一块结果 * 1:识别中间结果 * 2:识别最后一块结果 */ status: 0 | 1 | 2; }; } export { DataParamsStatusEnum, SystemStatus }; export type { LatRequestParams, SectionDelayParams, DataParams, CommonParams, RequestParams, SystemConfig, PublicCustomEventName, PrivateCustomEventName, SendWorkerMessage, ReplyWorkerMessage, ParallelHandlerSendWorkerMessage, ParallelHandlerReplyWorkerMessage, LatResponse, CustomEventCallback };