speech-synthesis/speech-synthesis

The composer plugin for speech-synthesis

1.0.2 2020-07-01 09:08 UTC

This package is not auto-updated.

Last update: 2024-04-18 04:18:47 UTC


README

支持阿里、百度、腾讯、科大讯飞语音合成接口

composer下载

composer require speech-synthesis/speech-synthesis

科大讯飞的使用示例:

$config = [
    'Iflytek'=>[ 
        'fileRoot'=>'/uploads',// 文件保存的路径
        'app_id' => '****',
        'api_secret'=>'****',
        'api_key'=>'****',
    ]
];
$syn = new SynthesisFactory('Iflytek','此处是文件名',$config);
$msg = $syn->getErrorMsg();
if($msg){
    echo $msg;// 错误信息
    return false;
}
    $speechFile = $syn->getSpeechFile();

阿里云使用示例:

1、获取access_token

composer require alibabacloud/sdk

阿里官方demo

<?php
require __DIR__ . '/vendor/autoload.php';
use AlibabaCloud\Client\AlibabaCloud;
use AlibabaCloud\Client\Exception\ClientException;
use AlibabaCloud\Client\Exception\ServerException;
/**
 * 第一步:设置一个全局客户端
 * 使用阿里云RAM账号的AccessKey ID和AccessKey Secret进行鉴权
 */
AlibabaCloud::accessKeyClient(
            "<your-access-key-id>",
            "<your-access-key-secret>")
            ->regionId("cn-shanghai")
            ->asDefaultClient();
try {
    $response = AlibabaCloud::nlsCloudMeta()
                            ->v20180518()
                            ->createToken()
                            ->request();
    print $response . "\n";
    $token = $response["Token"];
    if ($token != NULL) {
        print "Token 获取成功:\n";
        print_r($token);
    }
    else {
        print "token 获取失败\n";
    }
} catch (ClientException $exception) {
    // 获取错误消息
    print_r($exception->getErrorMessage());
} catch (ServerException $exception) {
    // 获取错误消息
    print_r($exception->getErrorMessage());
}

2、合成

$config = [
    'Iflytek'=>[
        'fileRoot'=>'/',
        "app_id"=>"****",
        "api_secret"=>"****",
        "api_key"=>"****",
    ],
    'Ali'=>[
        'fileRoot'=>'/',
        'appkey'=>'****',
        'token'=>'****',
        'format'=>'mp3',
        'draftContent'=>'对于一个在北平住惯的人,像我,冬天要是不刮风,。'
//        ....
    ]
];
$syn = new SynthesisFactory('Ali','测试的名字',$config);
$msg = $syn->getErrorMsg();// 错误信息
if(!$msg){
    $speechFile = $syn->getSpeechFile();// 文件
}

腾讯云使用示例:

$config = [
    'Iflytek'=>[
        'fileRoot'=>'/',
        "app_id"=>"***",
        "api_secret"=>"***",
        "api_key"=>"***",
    ],
    'Ali'=>[
        'fileRoot'=>'/',
        'appkey'=>'****',
        'token'=>'****',
        'format'=>'mp3',
        'draftContent'=>'对于一个在北平住惯的人,像我,冬天要是不刮风,。'
//        ....
    ],
    'Tencent'=>[
        'fileRoot'=>'/',
        'AppId'=>000,
        'SecretId'=>'***',
        'SecretKey'=>'***'
    ]
];
$syn = new SynthesisFactory('Tencent','Tencent',$config);
$msg = $syn->getErrorMsg();// 错误信息
if(!$msg){
    $speechFile = $syn->getSpeechFile();// 文件
}