You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

34 lines
2.8 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#### 语音合成
##### 示例代码
```php
<?php
include './vendor/autoload.php';
// 设置合成参数
$ttsConfig = [
'aue' => 'lame'
//...
];
// 这里的$app_id、$api_key、$api_secret是在开放平台控制台获得
$client = new IFlytek\Xfyun\Speech\TtsClient($app_id, $api_key, $api_secret, $ttsConfig);
// 返回格式为音频文件的二进制数组可以直接通过file_put_contents存入本地文件
$content = $client->request('欢迎使用科大讯飞语音能力,让我们一起用人工智能改变世界')->getBody()->getContents();
```
更详细请参见[Demo](https://github.com/iFLYTEK-OP/websdk-php-demo/blob/master/src/TtsDemo.php)
##### 合成参数
|参数名|类型|必传|描述|示例|
|---|---|---|---|---|
|aue|string|是|音频编码,可选值:<br>raw未压缩的pcm<br>lamemp3 **(当aue=lame时需传参sfl=1)**<br>speex-org-wb;7 标准开源speexfor speex_wideband即16k数字代表指定压缩等级默认等级为8<br>speex-org-nb;7 标准开源speexfor speex_narrowband即8k数字代表指定压缩等级默认等级为8<br>speex;7压缩格式压缩等级1-10默认为78k讯飞定制speex<br>speex-wb;7压缩格式压缩等级1-10默认为716k讯飞定制speex<br>|"raw" <br>"speex-org-wb;7" 数字代表指定压缩等级默认等级为8数字必传<br>标准开源speex编码以及讯飞定制speex说明请参考[音频格式说明](https://www.xfyun.cn/doc/asr/voicedictation/Audio.html#speex%E7%BC%96%E7%A0%81)|
|sfl|int|否|需要配合aue=lame使用开启流式返回<br>mp3格式音频<br>取值1 开启|1|
|auf|string|否|音频采样率,可选值:<br> audio/L16;rate=8000合成8K 的音频<br> audio/L16;rate=16000合成16K 的音频<br>auf不传值合成16K 的音频|"audio/L16;rate=16000"|
|vcn|string|是|发音人,可选值:请到控制台添加试用或购买发音人,添加后即显示发音人参数值|"xiaoyan"|
|speed|int|否|语速,可选值:[0-100]默认为50|50|
|volume|int|否|音量,可选值:[0-100]默认为50|50|
|pitch|int|否|音高,可选值:[0-100]默认为50|50|
|bgs|int|否|合成音频的背景音<br>0:无背景音(默认值) <br>1:有背景音|0|
|tte|string|否|文本编码格式<br>GB2312<br>GBK<br>BIG5<br>UNICODE(小语种必须使用UNICODE编码合成的文本需使用utf16小端的编码方式<br>GB18030<br>UTF8|"UTF8"|
|reg|string|否|设置英文发音方式:<br>0自动判断处理如果不确定将按照英文词语拼写处理缺省<br>1所有英文按字母发音<br>2自动判断处理如果不确定将按照字母朗读<br>默认按英文单词发音|"2"|
|rdn|string|否|合成音频数字发音方式<br>0自动判断默认值<br>1完全数值<br>2完全字符串<br>3字符串优先|"0"|