通过前两篇文章[百度文字转语音接口api](https://www.yuanchengzhushou.cn/article/8064.html)和[laravel通过vender()方法引入第三方sdk扩展包](https://www.yuanchengzhushou.cn/article/8066.html) 我们已经知道怎么将百度语音识别包集成在laravel框架中
今天我们再讲一种方法
首先在根目录创建文件夹extends,然后将百度语音识别度下载到这个文件,解压即可
![](https://www.yuanchengzhushou.cn/static/image/baiduai.jpg)
编辑`composer.json`
```
"autoload": {
"classmap": [
"extends/aibaidu/"
],
"psr-4": {
"App\\": "app/",
"Database\\Factories\\": "database/factories/",
"Database\\Seeders\\": "database/seeders/"
}
},
```
然后执行`$ composer dumpautoload`
最后`controller`中调用即可
```
$speech = new \AipSpeech('11062810','dBE***9Ec','bWjE7nKC7p3tmBzsuiHXc3OKTXxFtU4r');
$wd = request()->get('wd','中华人民共和国');
$res = $speech->synthesis($wd,'zh', $ctp=1);
header('Content-Type:audio/mp3');
exit($res);
```