Server 接入(旧)

一 功能介绍

录音文件转写,是将已经录制好的录音文件, 通过识别服务,将长段音频数据转写成文本数据,可用于采访录音转写、音频数据录入、会议记录总结等场景。整个识别过程是非实时的,支持:

  • 支持wav, ogg_speex, ogg_opus, mp3, opus格式的录音文件转写;
  • 支持中文普通话
  • 12个小时内出转写结果
  • 后续会开放热词配置、自训练语言模型功能,如需提前体验,请联系商务。

 

可用于基于协议开发的:

  • 轻量级嵌入式设备
  • 采用云对云的方式,接入DUI实时语音转写服务的产品
  • 其他特殊场景

二 调用限制

集成实时语音转写API时,需按照以下要求:

内容 说明
请求协议 https
请求地址

https://lasr.duiopen.com/task/...

接口鉴权 详见:接口授权
字符编码 UTF-8
响应格式 统一采用JSON格式
开发语言 任意,只要可以向思必驰录音文件转写服务发起http请求即可
音频属性 采样率16k、位长16bits、单声道
音频时长 5小时以内
音频格式 wav, ogg_speex, ogg_opus, mp3
语言种类 中文普通话
并发路数 默认5路并发
转写结果保存时长 最多保存7天

 

三 接入说明

集成录音文件长语音转写API,需要先创建基础技术服务产品。

  1. 登录DUI控制台后,点击导航栏的【基础技术】,进入基础技术产品列表页。
  2. 在列表页,点击【基础技术接入】,创建基础技术产品。

四 接口调用

4.1 上传音频文件

4.1.1 上传音频文件

调用服务前,请先进行接口鉴权,详见:接口鉴权

POST /audio/stream/v1?productId=278588090&apikey=0ddddeeeeeeeeeeee88888888260c8ab HTTP/1.1
Host: aos.duiopen.com
Content-Type: multipart/form-data; boundary=b0123456789;
Content-Length: N
   
--b0123456789
Content-Disposition: form-data; name="params"
{
  "request": {
    "audio": {
      "audioType":"audio/mp3" //必选,音频类型,支持:audio/mp3, audio/wav, audio/ogg, audio/opus, audio/spx
    }
  }
}
--b0123456789
Content-Disposition: form-data; name="file"; filename="file"; //文件名可以任意
audio binary data
--b0123456789--

 

4.1.2 form-data表单参数

参数

类型

是否必须

说明

params text

JSON 格式字符串,结构为

{
    "request":{
        "audio":{
            "audioType":"audio/mp3"
        }
    }
}

 

file file 实际上传的音频文件体。

 

4.1.3 音频格式说明

音频格式

流媒体 audioType

长语音 audio_type

wav wav 或者 audio/wav wav
mp3 mp3 或者 audio/mp3 mp3
ogg opus ogg_opus 或者 audio/opus ogg_opus
ogg speex ogg_speex 或者 audio/spx ogg_speex

4.1.4 响应结果

{
    "objectId":"5cbe728d9cfdd500012f39fc",
    "errMsg":"x" //上传失败时会有这个字段
}

4.2 创建转写任务

4.2.1 请求参数说明

参数名 说明 是否必需 参数类型 取值示例
audio_type

支持:wav, ogg_speex, ogg_opus, mp3, opus。

音频参数(约定,不需要在协议里传递)支持:

sample rate: 16000

channel: 1

sample bytes: 2

string

-

 

file_path 音频文件路径,要保障集群内能够直接访问。 string

如果上传音频文件使用的上述 3.1 的接口,则此处填写流媒体服务地址,将下文地址中 objectId 参数替换为 3.1 接口返回的 objectId 对应值即可。

地址:http://streaming-media.cloud.svc.cluster.local:29000/audio/stream/v1?objectId=5cbe728d9cfdd500012f39fc

有如下两种情况:

  1. 如果音频格式为 wav, ogg_speex, ogg_opus 或者 mp3,并且音频 sampleRate 为 16000 Hz,channel 为 1。则直接使用上述链接。

  2. 如果音频不符合 1 的情况。则链接需要添加额外的 format, sampleRate 和 channel 参数,此时从该 URL 获取的音频会直接转换为对应符合要求的格式。

    http://streaming-media.cloud.svc.cluster.local:29000/audio/stream/v1?objectId=5cbe728d9cfdd500012f39fc&format=wav&sampleRate=16000&channel=1。此时上述 audio_type 也要填写为 wav。

注意::对于我们平台识别支持的 4 种格式 wav, mp3, ogg opus 和 ogg speex,并且 sampleRate 为 16000 Hz,channel 为 1。不建议添加转码参数,直接用上述 1 的情况即可。只有对于我们平台不支持的音频格式,再考虑 2 情况。

task_type

任务转写类型

int

默认值:1

use_txt_smooth

口语顺滑开关。0:不使用,1:使用(默认)。

int

1

use_inverse_txt

逆文本转换开关。0:不使用,1:使用(默认)。

int

1

callback

识别完成时的回调HTTP(s)地址。当设置了callback地址,当识别融合后,会把最终结果以POST方式回传(也可以通过/lasr/task/result的方式来主动获取)。

string

-

file_len

音频文件长度。单位:byte

int

-

check_length

音频的时长(单位:秒), 用户校验剩余时长是否充足

double

-

speaker_number

发音人个数,可选值:0-65535。0:表示跳过说话人聚类 。>0:音频里发音人个数。

 

int

默认值:0,跳过说话人识别注意:
  1. 跳过说话人聚类时,任务的最终result里,没有speaker信息。
  2. 跳过说话人聚类时,任务的最终metrics指标里,没有diarizated_t。

4.2.2 创建转写任务

POST /task/create?productId=278588090&apikey=0ddddeeeeeeeeeeee88888888260c8ab HTTP/1.1
Host: lasr.duiopen.com
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
Content-Length: N

4.2.3 响应结果

{
  "errno": 0,
  "error": "",
  "data": {
    "task_id": "383e72a47557490aa05a344074117a9d"
  }
}

4.3 查询转写状态

4.3.1 请求转写状态

POST /task/progress?productId=278588090&apikey=0ddddeeeeeeeeeeee88888888260c8ab HTTP/1.1
Host: lasr.duiopen.com
Content-Type: application/x-www-form-urlencoded; charset=UTF-8

4.3.2 请求参数说明(request body)

参数名 说明 是否必需 参数类型 取值示例
task_id 创建离线转写任务接口返回的任务标识 string 383e72a47557490aa05a344074117a9d

4.3.3 响应结果

{
  "errno": 0,
  "error": "",
  "data": {
    "progress": 0, //0 ~ 100,100标注转写完成
  }
}

4.4 请求转写结果

4.4.1 请求转写结果

POST /task/result?productId=278588090&apikey=0ddddeeeeeeeeeeee88888888260c8ab HTTP/1.1
Host: lasr.duiopen.com
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
}

4.4.2 请求参数说明(request body)

参数名 说明 是否必需 参数类型 取值示例
task_id 创建离线转写任务接口返回的任务标识 string 383e72a47557490aa05a344074117a9d

4.4.3 响应参数说明

参数名

说明

是否必需

参数类型

取值 示例

data.bg

开始时间,单位:毫秒

int

0

data.ed

结束时间,单位:毫秒

int

1000

data.onebest

识别文本

string

思必驰信息科技有限公司。

data.speaker

说话人序号

int

0

data.sensitive_words[0]

检测出来的敏感词列表

string

XX

 

4.4.2 响应结果

{
    "errno":0,
    "error":"",
    "data":{
        "metrics":{

        },
        "request":{

        },
        "result":[
            {
                "bg":0,
                "ed":4950,
                "onebest":"思必驰信息科技有限公司。",
                "speaker":0
            }
        ]
    }
}

五 错误码

错误码如下表:

errno 描述 说明
1 internal error 服务器内部错误
2 method %s not allowed. 请求方法错误
10 %s is empty or not exists. current: %s 客户端参数缺失
12 Invalid file_path / Invalid callback 客户端参数里的url格式不对, 如file_path, callback
13 unknown request path: %s 未知的请求路径
201 download failed, length: %d, status code: %d, message: %s. 音频下载失败
202 cut audio failed. path: %s, return code: %d 音频切割失败
203 save origin audio failed. cause: %s 音频保存失败或路径有异常
302 timeout(finalResFile %s not exists). 音频后处理超时
501 file not exist. path: %s 要加载的音频文件不存在

 

连接错误

http状态码 报文 报文解释
401

{"errId":"120000","errMsg":"apikey auth verify error"}

鉴权失败
403

{"errId":"120100","errMsg":"ocs check error"}

产品达到使用量上限,用量管控
403

{"errId":"120200","errMsg":"limit connection reach the limit"}

产品触发流控