更新语音
This commit is contained in:
parent
94ea58620c
commit
756be58d0f
@ -241,27 +241,29 @@ class XunFeiController extends BaseApiController
|
||||
{
|
||||
header('X-Accel-Buffering: no');
|
||||
$ttsHostUrl = "wss://tts-api.xfyun.cn/v2/tts";
|
||||
$text = request()->file('text');
|
||||
if(empty($file)){
|
||||
$text = request()->param('text');
|
||||
if(empty($text)){
|
||||
return $this->fail('未上传文本参数');
|
||||
}
|
||||
$business = [
|
||||
'aue' => 'lame',
|
||||
'vcn' => 'xiaoyan',
|
||||
'auf' => 'audio/L16;rate=16000',
|
||||
'speed' => 50,
|
||||
'volume'=> 100,
|
||||
'pitch' => 50,
|
||||
'tte' => 'UTF8',
|
||||
];
|
||||
$tts = new TtsClient($this->app_id,$this->api_key,$this->api_secret, $business);
|
||||
$date = date('YmdHis', time());
|
||||
$file_name = $date . '.mp3';
|
||||
$file_name = $date . mt_rand(1000, 9999) . '.mp3';
|
||||
$audioFile = app()->getRootPath() . '/runtime/storage/audio/' . date('Ymd') . '/' . $file_name;
|
||||
file_put_contents($audioxxxFile, $tts->request($text)->getBody()->getContents());
|
||||
exit;
|
||||
|
||||
|
||||
$business = [
|
||||
'aue' => 'lame', //mp3格式
|
||||
'vcn' => 'xiaoyan', //发音人
|
||||
'auf' => 'audio/L16;rate=16000', //音频采样率
|
||||
'speed' => 50, //语速
|
||||
'volume'=> 100, //音量
|
||||
'pitch' => 50, //音高
|
||||
'tte' => 'UTF8'
|
||||
];
|
||||
try {
|
||||
$tts = new TtsClient($this->app_id, $this->api_key, $this->api_secret, $business);
|
||||
file_put_contents($audioFile, $tts->request($text)->getBody()->getContents());
|
||||
} catch (\Exception $e) {
|
||||
return $this->fail($e->getMessage().'');
|
||||
}
|
||||
return $this->data(['audio_file' => $audioFile]);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -154,7 +154,6 @@ class TtsConfig implements ConfigInterface
|
||||
$this->reg = $config['reg'];
|
||||
$this->rdn = $config['rdn'];
|
||||
$this->ent = $config['ent'];
|
||||
print_r($config);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user