音频文件转写
<p>[TOC]</p>
<h3>描述</h3>
<ul>
<li>音频文件转写接口可以将大批量的音频文件异步转写为文字。</li>
<li>适合音视频字幕生产、批量录音质检、会议内容总结、录音内容分析等场景,一般12小时内返回结果。</li>
</ul>
<h3>1 使用流程</h3>
<h4>1.1 第一步 --发起任务</h4>
<ul>
<li>根据音频url、音频格式等参数创建音频转写任务,获取task_id参数。</li>
</ul>
<h4>1.2 第二步 -- 查询结果</h4>
<ul>
<li>根据task_id的数组批量查询音频转写任务结果,查询不计费。</li>
</ul>
<hr />
<h3>2 接口调用说明</h3>
<h4>2.1 请求方式</h4>
<p>如接口没有单独说明,均为:<strong>POST</strong></p>
<h4>2.2 请求格式</h4>
<p>如接口没有单独说明,所有接口均为:application/x-www-form-urlencoded</p>
<h4>2.3 请求参数</h4>
<p>请求参数包括公共参数和业务参数(业务参数见具体接口说明)
如果请求格式为application/x-www-form-urlencoded的,需要把<strong>公共参数</strong>和<strong>业务参数</strong>一并放在<strong>请求参数</strong>中提交
如果请求格式为application/json的,需要把<strong>公共参数</strong>放在<strong>请求Header</strong>中提交</p>
<h5>2.3.1 公共参数</h5>
<table>
<thead>
<tr>
<th>名称</th>
<th>类型</th>
<th>必须</th>
<th><div style="width:420px;">说明</div></th>
</tr>
</thead>
<tbody>
<tr>
<td>appId</td>
<td>String</td>
<td>是</td>
<td>服务商分配的唯一标识</td>
</tr>
<tr>
<td>timestamp</td>
<td>Long</td>
<td>是</td>
<td>当前时间戳(毫秒)</td>
</tr>
<tr>
<td>sign</td>
<td>String</td>
<td>是</td>
<td>签名,详见<a href="#签名算法">签名算法说明</a></td>
</tr>
</tbody>
</table>
<h5>2.3.2 签名算法说明</h5>
<pre><code>sign = sha256(appId + appSecret + timestamp)</code></pre>
<p>用服务商分配的 <strong>appId</strong>、服务商分配的 <strong>appSecret</strong>,当前时间戳(毫秒) <strong>timestamp</strong>,按上述顺序拼接成字符串,再进行 <strong>sha256</strong> 哈希得到。如下:</p>
<pre><code class="language-java">String appId = &quot;xyzxy2121zxyz&quot;;
String timestamp = &quot;1555378976238&quot;;
String appSecret = &quot;efcefcef1121cefcefc1212121&quot;;
String str = appId + appSecret + timestamp;
String sign = sha256(str);</code></pre>
<h4>2.4 返回说明</h4>
<h5>2.4.1 公共返回字段说明</h5>
<p>所有接口均返回以下公共字段:</p>
<table>
<thead>
<tr>
<th>字段名</th>
<th><div style="width:420px">说明</div></th>
</tr>
</thead>
<tbody>
<tr>
<td>code</td>
<td>返回码,详见:公共code返回码说明</td>
</tr>
<tr>
<td>msg</td>
<td>code对应的描述</td>
</tr>
<tr>
<td>taskNo</td>
<td>本次请求号</td>
</tr>
<tr>
<td>data</td>
<td>返回具体结果,object类型,详见各接口返回说明</td>
</tr>
</tbody>
</table>
<p><a name="code返回码说明"></a></p>
<h5>2.4.2 code返回码说明</h5>
<table>
<thead>
<tr>
<th>code</th>
<th><div style="width:420px;">说明</div></th>
</tr>
</thead>
<tbody>
<tr>
<td>200</td>
<td>成功</td>
</tr>
<tr>
<td>201</td>
<td>taskId不存在</td>
</tr>
<tr>
<td>202</td>
<td>音频文件格式不对</td>
</tr>
<tr>
<td>203</td>
<td>打开音频文件失败</td>
</tr>
<tr>
<td>204</td>
<td>音频文件长度太短</td>
</tr>
<tr>
<td>205</td>
<td>无效语音</td>
</tr>
<tr>
<td>206</td>
<td>读音频文件失败</td>
</tr>
<tr>
<td>207</td>
<td>无法解析格式的音频</td>
</tr>
<tr>
<td>400</td>
<td>参数错误</td>
</tr>
<tr>
<td>404</td>
<td>接口地址不正确</td>
</tr>
<tr>
<td>500</td>
<td>系统维护,请稍候再试</td>
</tr>
<tr>
<td>601</td>
<td>接口未开通</td>
</tr>
<tr>
<td>602</td>
<td>账号停用</td>
</tr>
<tr>
<td>604</td>
<td>接口停用</td>
</tr>
<tr>
<td>606</td>
<td>调用超限,请稍候再试</td>
</tr>
<tr>
<td>607</td>
<td>ip不在白名单</td>
</tr>
<tr>
<td>609</td>
<td>请求过于频繁,请稍候再试</td>
</tr>
<tr>
<td>610</td>
<td>请求超时</td>
</tr>
</tbody>
</table>
<hr />
<h3>3 基础接口</h3>
<h4>3.1 音频文件转写发起任务</h4>
<ul>
<li>根据音频url、音频格式等参数创建音频转写任务,获取task_id参数,成功进行计费。</li>
</ul>
<h5>3.1.1 请求地址</h5>
<p><code>https://api.jumdata.com/speech-recognition/convert/request</code></p>
<h5>3.1.2 业务参数</h5>
<table>
<thead>
<tr>
<th>名称</th>
<th>类型</th>
<th>必须</th>
<th><div style="width:420px;">说明</div></th>
</tr>
</thead>
<tbody>
<tr>
<td>url</td>
<td>String</td>
<td>是</td>
<td>音频url</td>
</tr>
<tr>
<td>format</td>
<td>String</td>
<td>是</td>
<td>音频格式 ["mp3", "wav", "pcm","m4a","amr"]</td>
</tr>
<tr>
<td>channel</td>
<td>Integer</td>
<td>否</td>
<td>声道 [1、2]</td>
</tr>
</tbody>
</table>
<h5>3.1.3 返回说明</h5>
<h3>正确返回样例</h3>
<pre><code class="language-json">{
&quot;code&quot;: 200,//返回码,详见返回码说明
&quot;msg&quot;: &quot;成功&quot;,//返回码对应描述
&quot;taskNo&quot;: &quot;340419447206566228602625&quot;,//本次请求号
&quot;charge&quot;: true,//计费标志,true 计费,false 不计费
&quot;data&quot;: {
&quot;task_status&quot;: &quot;Created&quot;,//状态
&quot;task_id&quot;: &quot;66642562a281fd000186ffb4&quot;//返回task_id 查询用
}
}</code></pre>
<h3>错误返回样例</h3>
<pre><code class="language-json">{
&quot;code&quot;: 400,
&quot;msg&quot;: &quot;音频url不能为空&quot;
}</code></pre>
<h4>3.2 音频文件转写查询结果</h4>
<ul>
<li>根据task_id的数组批量查询音频转写任务结果,查询不计费。</li>
</ul>
<h5>3.2.1 请求地址</h5>
<p><code>https://api.jumdata.com/speech-recognition/convert/result</code></p>
<h5>3.2.2 业务参数</h5>
<table>
<thead>
<tr>
<th>名称</th>
<th>类型</th>
<th>必须</th>
<th><div style="width:420px;">说明</div></th>
</tr>
</thead>
<tbody>
<tr>
<td>taskIds</td>
<td>String</td>
<td>是</td>
<td>任务id 推荐一次查询多个任务id,单次最多可查询200个</td>
</tr>
</tbody>
</table>
<h5>3.2.3 返回样例</h5>
<h3>正确返回样例</h3>
<pre><code class="language-json">{
&quot;code&quot;: 200,//返回code
&quot;msg&quot;: &quot;成功&quot;,//code对应的说明描述
&quot;taskNo&quot;: &quot;067480648234069097809498&quot;,//本次请求号
&quot;charge&quot;: false,//计费标志,true 计费,false 不计费
&quot;data&quot;: {
&quot;task_info&quot;: [//任务信息
{
&quot;task_status&quot;: &quot;Success&quot;,//任务状态
&quot;task_result&quot;: { //任务结果
&quot;result&quot;: [
&quot;北京科技馆。&quot;
],
&quot;audio_duration&quot;: 4050,
&quot;detailed_result&quot;: [
{
&quot;res&quot;: [
&quot;北京科技馆。&quot;
],
&quot;end_time&quot;: 4050,
&quot;begin_time&quot;: 0,
&quot;words_info&quot;: [],
&quot;sn&quot;: &quot;265877890791723874627&quot;,
&quot;corpus_no&quot;: &quot;7403985146698616320&quot;
}
],
&quot;corpus_no&quot;: &quot;7403985146698616320&quot;
},
&quot;task_id&quot;: &quot;66c03d2d83eebb000135560c&quot;
}
]
}
}
</code></pre>
<h3>错误返回样例</h3>
<pre><code class="language-json">{
&quot;code&quot;: 201,
&quot;msg&quot;: &quot;taskId不存在&quot;
}</code></pre>