语音合成-长文本合成
<p>[TOC]</p>
<h3>描述</h3>
<ul>
<li>长文本在线合成接口可以将10万字以内文本一次性合成,异步返回音频。支持多种优质音库,将超长文本快速转换成稳定流畅、饱满真实的音频。适用于阅读听书、新闻播报等客户。</li>
</ul>
<h3>1 使用流程</h3>
<h4>1.1 第一步 --发起任务</h4>
<ul>
<li>根据文本内容、音频格式、音库等参数创建语音合成任务,获取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>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>根据文本内容、音频格式、音库等参数创建语音合成任务,获取task_id,成功进行计费。</li>
</ul>
<h5>3.1.1 请求地址</h5>
<p><code>https://api.jumdata.com/speech-synthesis/text-long/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>text</td>
<td>String</td>
<td>是</td>
<td>待合成的文本 总字数不超过10万个字符,1个中文字、英文字母、数字或符号均算作1个字符</td>
</tr>
<tr>
<td>format</td>
<td>String</td>
<td>否</td>
<td>音频格式 mp3-16k,mp3-48k,wav,pcm-8k,pcm-16k,默认为mp3-16k</td>
</tr>
<tr>
<td>voice</td>
<td>Integer</td>
<td>否</td>
<td>音库 基础音库:度小宇=1,度小美=0,度逍遥(基础)=3,度丫丫=4;精品音库:度逍遥(精品)=5003,度小鹿=5118,度博文=106,度小童=110,度小萌=111,度米朵=103,度小娇=5。默认为度小美</td>
</tr>
<tr>
<td>speed</td>
<td>Integer</td>
<td>否</td>
<td>语速 取值0-15,默认为5中语速</td>
</tr>
<tr>
<td>pitch</td>
<td>Integer</td>
<td>否</td>
<td>音调 取值0-15,默认为5中语调</td>
</tr>
<tr>
<td>volume</td>
<td>Integer</td>
<td>否</td>
<td>音量 基础音库取值0-9,精品音库取值0-15,默认为5中音量(取值为0时为音量最小值,并非为无声)</td>
</tr>
<tr>
<td>enableSubtitle</td>
<td>Integer</td>
<td>否</td>
<td>是否开启字幕时间戳 取值范围0, 1, 2,默认为0。0表示不开启字幕时间戳,1表示开启句级别字幕时间戳,2表示开启词级别字幕时间戳</td>
</tr>
<tr>
<td>interval</td>
<td>Integer</td>
<td>否</td>
<td>段落间隔 取值 0-5000 ,单位ms,用于合成文本分段传入时设置段落间间隔。</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;文本不能为空&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-synthesis/text-long/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;340419447206566228602625&quot;,//本次请求号
&quot;charge&quot;: false,//计费标志,true 计费,false 不计费
&quot;data&quot;: {
&quot;tasks_info&quot;: [ //任务信息
{
&quot;task_status&quot;: &quot;Success&quot;,//任务状态
&quot;task_result&quot;: {//任务结果
&quot;speech_url&quot;: &quot;xxx&quot;,//音频下载链接
&quot;speech_timestamp&quot;: {//字幕时间戳信息
&quot;sentences&quot;: [//句子列表
{
&quot;paragraph_index&quot;: 0,//句子在传入文本中段落位置
&quot;sentence_texts&quot;: &quot;xxx&quot;,//句子文本信息
&quot;begin_time&quot;: 104,//句子文本在合成音频的开始时间戳
&quot;end_time&quot;: 5970,//句子文本在合成音频的结束时间戳
&quot;characters&quot;: [//句子中各个词的信息
{
&quot;character_text&quot;: &quot;今&quot;,//句子中的词文本
&quot;begin_time&quot;: 106, //句子中的词在合成音频的开始时间戳
&quot;end_time&quot;: 313 //句子中的词在合成音频的结束时间戳
}
]
}
]
}
},
&quot;task_id&quot;: &quot;63c6550e52064d000104da0d&quot;//任务Id
}
]
}
}</code></pre>
<h3>错误返回样例</h3>
<pre><code class="language-json">{
&quot;code&quot;: 201,
&quot;msg&quot;: &quot;taskId不存在&quot;
}</code></pre>