百度语音生成
<?php
var_dump(voice_generate("你有新订单了,请注意查收"));die;
function voice_generate($text,$path="./"){
require_once './AipSpeech.php';
$APP_ID = '**';
$API_KEY = '**';
$SECRET_KEY = '**';
$client = new AipSpeech($APP_ID,$API_KEY, $SECRET_KEY);
$result = $client->synthesis($text, 'zh', 1, array(
'vol' => 15,
'spd' => 5,
'pit' => 5,
'per' => 0,
));
$time=time();
if(!is_array($result)){
file_put_contents($path.$time.'.mp3', $result);
}
return $path.$time.'.mp3';
}
语音识别
<?php
require_once 'AipSpeech.php';
const APP_ID = '18292366';
const API_KEY = 'WpNg4xVzYVobpVexcqDFGw25';
const SECRET_KEY = 'ryQHjupKjxY1ssIu1MiOBbpjIG39qb1x';
$client = new AipSpeech(APP_ID, API_KEY, SECRET_KEY);
$cz=$client->asr(file_get_contents('audio1.wav'), 'wav', 16000, array('dev_pid' => 1536,));
var_dump($cz,1);die;