PHP code example of fyflzjz / speech

1. Go to this page and download the library: Download fyflzjz/speech 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/ */

    

fyflzjz / speech example snippets


$app_id = 'app id';
$app_key = 'app key';
$secret_key = 'secret key';
$log_path = '';
$client = new \fyflzjz\speech\Baidu\AipSpeech($app_id, $app_key, $secret_key, $log_path);
$result = $client->synthesis('你好百度', 'zh',1,['vol' => 5,]);

// 识别正确返回语音二进制 错误则返回json 参照下面错误码
if (!is_array($result)) {
	file_put_contents('audio.mp3', $result);
}