raison/easy-tts-laravel

The easiest way to use tts

1.0.0 2022-10-24 05:48 UTC

This package is auto-updated.

Last update: 2024-04-30 00:32:57 UTC


README

一款满足你的多种TTS平台调用组件

687474703a2f2f706f7365722e707567782e6f72672f726169736f6e2f656173792d7474732d6c61726176656c2f646f776e6c6f616473 687474703a2f2f706f7365722e707567782e6f72672f726169736f6e2f656173792d7474732d6c61726176656c2f6c6963656e7365 687474703a2f2f706f7365722e707567782e6f72672f726169736f6e2f656173792d7474732d6c61726176656c2f726571756972652f706870

特点

  1. 支持目前市面多家服务商
  2. 一套写法兼容所有平台
  3. 支持实时流式返回(短文本)创建异步任务(长文本)
  4. 支持多种参数设置
  5. 更多等你去发现与改进...

平台支持

环境需求

  • PHP >= 7.4

安装

$ composer require raison/easy-tts-laravel

各平台配置说明

在 config/app.php 文件中设置服务提供者和别名。

'providers' => [
    ....
    EasyTts\Providers\LaravelServiceProvider::class,
    ....
],

###请使用下面这条命令来发布配置文件

 php artisan vendor:publish --provider="EasyTts\Providers\LaravelServiceProvider"

科大讯飞

'xunfei' => [
            'driver' => 'xunfei',
            'appid' => '',
            'secret_id' => '',
            'secret_key' => '',
        ],

腾讯云

'tencent' => [
            'driver' => 'tencent',
            'appid' => '',
            'secret_id' => '',
            'secret_key' => '',
        ],

阿里云

'aliyun' => [
            'driver' => 'aliyun',
            'appid' => '',
            'secret_id' => '',
            'secret_key' => '',
        ],

百度云

'baidu' => [
            'driver' => 'baidu',
            'appid' => '',
            'secret_id' => '',
            'secret_key' => '',
        ],

使用

use EasyTts\TtsManager;

(new TtsManager())->client()->textToSpeechStream('PHP是全世界最好的语言');

科大讯飞

平台支持方式 短文本(流返回)

流式返回(短文本) 请求参数说明

use EasyTts\TtsManager;

$text = "php是全世界最好的语言";
$config = [
            'speed' => 50,
            'volume' => 50,
            'vcn' => "xiaoyan",
        ];

return (new TtsManager())->client('xunfei')->setRequestConfig($config)->textToSpeechStream($text);

腾讯云

流式返回(短文本) 请求参数说明

use EasyTts\TtsManager;

$text = "php是全世界最好的语言";
$config = [
            'Speed' => 0,
            'Volume' => 0,
            'VoiceType' => 10510000,
        ];

return (new TtsManager())->client('tencent')->setRequestConfig($config)->textToSpeechStream($text);

创建任务 (长文本) 请求参数说明

use EasyTts\TtsManager;

$text = "php是全世界最好的语言";
$config = [
            'Speed' => 0,
            'Volume' => 0,
            'VoiceType' => 10510000,
        ];

// 创建异步任务
$task_id = (new TtsManager())->client('tencent')->setRequestConfig($config)->createTask($text);
// 通过任务id获取结果
$res = (new TtsManager())->client('tencent')->fetchTaskResult($task_id);

阿里云

流式返回(短文本) 请求参数说明

use EasyTts\TtsManager;

$text = "php是全世界最好的语言";
$config = [
            'speech_rate' => 200,
            'voice' => 70,
            'voice' => "zhitian_emo",
        ];

return (new TtsManager())->client('aliyun')->setRequestConfig($config)->textToSpeechStream($text);

创建任务 (长文本) 请求参数说明

use EasyTts\TtsManager;

$text = "php是全世界最好的语言";
$config = [
            'speech_rate' => 200,
            'voice' => 70,
            'voice' => "zhitian_emo",
        ];

// 创建异步任务
$task_id = (new TtsManager())->client('aliyun')->setRequestConfig($config)->createTask($text);
// 通过任务id获取结果
$res = (new TtsManager())->client('aliyun')->fetchTaskResult($task_id);

百度云

流式返回(短文本) 请求参数说明

use EasyTts\TtsManager;

$text = "php是全世界最好的语言";
$config = [
            'spd' => 10,
            'vol' => 10,
            'per' => 3,
        ];

return (new TtsManager())->client('baidu')->setRequestConfig($config)->textToSpeechStream($text);

创建任务 (长文本) 请求参数说明

use EasyTts\TtsManager;

$text = "php是全世界最好的语言";
$config = [
            'speed' => 10,
            'volume' => 10,
            'voice' => 3,
        ];

// 创建异步任务
$task_id = (new TtsManager())->client('baidu')->setRequestConfig($config)->createTask($text);
// 通过任务id获取结果
$res = (new TtsManager())->client('baidu')->fetchTaskResult($task_id);

License

MIT