当前插件集成了百度文本转语音功能,支持laravel 9版本以上.

下载方式:

1、通过composer下载:composer require yreborn/laravel-speech

2、在composer.json 新增 “yreborn/laravel-speech”: “dev-main”,在命令行使用composer install进行安装
1、创建config/speech.php 配置文件

<?php return [ 'API_KEY' => '', 'SECRET_KEY' => '', ]; 2、在config/app目录加载插件 'providers' => [ Yreborn\LaravelSpeech\SpeechServiceProvider::class ], 'aliases' => [ 'Speech' => Yreborn\LaravelSpeech\Facades\Speech::class ], 3、在控制器使用 <?php namespace App\Http\Controllers; use Illuminate\Foundation\Auth\Access\AuthorizesRequests; use Illuminate\Foundation\Validation\ValidatesRequests; use Illuminate\Http\Request; use Illuminate\Routing\Controller as BaseController; use Illuminate\Support\Facades\Storage; use Yreborn\LaravelUpload\Facades\Upload; class IndexController extends Controller { public function index(Request $request) { //tex:文本 cuid:唯一标识 lang:中文 task_ids:任务id $short = ['tex' => '现在的时间是20231013','cuid' => '2iQCcRhICQ2KUeAS46oK31EJNkau52Oz']; $long = ['text' => '现在的时间是20231013','lang' => 'zh']; $query = ['task_ids' => ['6528a1e31134240001d39fff']]; $data = Speech::query($query); //长文本查询 $data = Speech::short($short); //短文本生成 $data = Speech::long($long); //长文本生成 if(!is_array($data)){ file_put_contents('audio.mp3', $data); return view('video', ['view' => 'audio.mp3']); } } } 4、html页面播放 ```php xgplayer
```
Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐