使用方法 把 yyy.php 放到有PHP环境的服务器
http://域名或IP/yyy.php?text=123 比如 http://127.0.0.1/yyy.php?text=123 (等于后面的123 可以替换任意汉字或数字 字母) 发送GET请求 返回文本转语音内容
http://150.158.39.109/jsq/yyy.php?text=123 真实可以测试
[PHP] 纯文本查看 复制代码 <?php
function wzzyy($arg1) {
// 圆管中对中线语音播报
$a = $arg1;
// 需要发送的参数
$params = [
'tex' => $a,
'per' => '0',
'spd' => '4',
'pit' => '5',
'vol' => '5',
'aue' => '3',
'cuid' => '123456PHP',
'tok' => '24.ef8d24dcc1f85e8db5be5e7309be5f6a.2592000.1741618027.282335-4304922',
'lan' => 'zh',
'ctp' => '1',
'additionalParam' => 'value' // 这是新增的参数
];
// 将参数对象转换为URL编码的字符串
$queryString = http_build_query($params);
// 构建请求URL
$url = 'http://tsn.baidu.com/text2audio?' . $queryString;
// 使用file_get_contents发送GET请求
$audioData = file_get_contents($url);
if ($audioData === FALSE) {
echo '请求失败';
return;
}
// 创建一个临时文件来保存音频数据
$audioFile = tempnam(sys_get_temp_dir(), 'audio');
file_put_contents($audioFile, $audioData);
// 输出音频文件,以便浏览器播放
header('Content-Type: audio/mpeg');
readfile($audioFile);
// 删除临时文件
unlink($audioFile);
}
// 从 GET 请求中获取参数
if (isset($_GET['text'])) {
$text = $_GET['text'];
wzzyy($text);
} else {
echo '请提供文本参数';
}
?>
yyy.rar
(870 Bytes, 下载次数: 0)
|