PHP code example of wenxi / tts-api

1. Go to this page and download the library: Download wenxi/tts-api library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

wenxi / tts-api example snippets



/**
 * User: [email protected]
 * Date: 17/8/5
 * Time: 下午2:30
 */

header("Content-type: text/html; charset=utf-8");

'apiSecretKey' => 'f35b13eb1b9a4****f742445368ecbdd',
        'expires'      => time() + 3600,
        'voice'        => 'cnmale',
        'format'       => 'MP3',
        'speed'        => 1,
    ],
    'baidu'      => [
        'client_id'     => 'BsUAmCwHCLQUU****hnoUAatpHtnHGlU',
        'client_secret' => 'HM3oWwefKKZbG****v1xkSF071bZy9ne',
        'lan'           => 'zh',
        'ctp'           => 1,
        'cuid'          => '',
        'spd'           => '',
        'pit'           => '',
        'vol'           => '',
        'per'           => '',
    ]
];

//$platformName = 'jixianyuan';
$platformName = 'baidu';
$config       = $configs[$platformName];

$tts = new Tts($config);

try {
    $response = $tts->send("hello,world!", $platformName);
    var_dump($response);
} catch (\WenXi\TtsApi\Exceptions\InvalidArgumentException $iex) {
    echo "tts参数异常\n";
    echo $iex->getMessage();
} catch (\WenXi\TtsApi\Exceptions\PlatformErrorException $pex) {
    echo "tts平台异常\n";
    echo $pex->getMessage();
} catch (\WenXi\TtsApi\Exceptions\Exception $ex) {
    echo "tts异常\n";
    echo $ex->getMessage();
} catch (Exception $ex) {
    echo "系统异常\n";
    echo $ex->getMessage();
}