fmujie / baidu-speech-synthesis

百度AI平台语音合成扩展包

1.0.4 2021-08-02 08:24 UTC

This package is auto-updated.

Last update: 2024-09-29 05:36:17 UTC


README

目前仅支持百度AI平台的语音合成功能

安装

  1. 安装包文件

    $ composer require fmujie/baidu-speech-synthesis

配置

  1. 注册 ServiceProvider

    Fmujie\BaiduSpeech\BaiduSpeechServiceProvider::class,
  2. 创建配置文件:

    php artisan vendor:publish

    通常需要选择publish哪个服务,因为没有参数,选择编号 [n ]

    [n ] Provider: Fmujie\BaiduSpeech\BaiduSpeechServiceProvider

    执行命令后会在 config 目录下生成本扩展配置文件:laravel-baidu-speech.php

  3. .env 文件中增加如下配置:

    • BAIDU_APP_ID:百度的AppId

    • BAIDU_API_KEY:百度的ApiKey

    • BAIDU_SECRET_KEY:百度的SecretKey

使用

  1. 语音合成

    $BaiduSpeech = new Fmujie\BaiduSpeech\BaiduSpeech();
    $BaiduSpeech->combine($text, $userID, $lan, $speed, $pitch, $volume, $person);

    接口字段:

    接口返回字段详细见 百度官方文档.

    返回的语音信息保存在storage/audios/back.mp3中

    调用示例

    <?php
    namespace App\Http\Controllers\test;
    
    use Illuminate\Http\Request;
    use App\Http\Controllers\Controller;
    use Fmujie\BaiduSpeech\BaiduSpeech;
    
    class TestController extends Controller
    {
        public function test()
        {
            $text = '我真的很爱很爱你';
            $userID = 'fmujie';
            $lan = 'zh';
            $speed = 5;
            $pitch = 5;
            $volume = 5;
            $person = 4;
            $BaiduSpeech = new BaiduSpeech();
            $result = $BaiduSpeech->combine($text, $userID, $lan, $speed, $pitch, $volume, $person);
            dd($result);
            return "";
        }
    }

许可协议

MIT许可协议 (MIT)。请参阅 许可文件 了解更多信息。