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.

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
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

合成参数
参数名 类型 必传 描述 示例
aue string 音频编码,可选值:
raw未压缩的pcm
lamemp3 (当aue=lame时需传参sfl=1)
speex-org-wb;7 标准开源speexfor speex_wideband即16k数字代表指定压缩等级默认等级为8
speex-org-nb;7 标准开源speexfor speex_narrowband即8k数字代表指定压缩等级默认等级为8
speex;7压缩格式压缩等级1-10默认为78k讯飞定制speex
speex-wb;7压缩格式压缩等级1-10默认为716k讯飞定制speex
"raw"
"speex-org-wb;7" 数字代表指定压缩等级默认等级为8数字必传
标准开源speex编码以及讯飞定制speex说明请参考音频格式说明
sfl int 需要配合aue=lame使用开启流式返回
mp3格式音频
取值1 开启
1
auf string 音频采样率,可选值:
audio/L16;rate=8000合成8K 的音频
audio/L16;rate=16000合成16K 的音频
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 合成音频的背景音
0:无背景音(默认值)
1:有背景音
0
tte string 文本编码格式
GB2312
GBK
BIG5
UNICODE(小语种必须使用UNICODE编码合成的文本需使用utf16小端的编码方式
GB18030
UTF8
"UTF8"
reg string 设置英文发音方式:
0自动判断处理如果不确定将按照英文词语拼写处理缺省
1所有英文按字母发音
2自动判断处理如果不确定将按照字母朗读
默认按英文单词发音
"2"
rdn string 合成音频数字发音方式
0自动判断默认值
1完全数值
2完全字符串
3字符串优先
"0"