更新流式语音接口

This commit is contained in:
yaooo 2023-10-10 10:50:52 +08:00
parent 2d361def94
commit cc4e1feb1a

View File

@ -126,14 +126,18 @@ class XunFeiController extends BaseApiController
if(empty($file)){
return $this->fail('未上传音频文件');
}
// 上传到本地服务器
// 上传音频临时文件
$savename = \think\facade\Filesystem::putFile('audio', $file);
$file = app()->getRootPath() .'/runtime/storage/' . $savename;
$file = app()->getRootPath() . '/runtime/storage/' . $savename;
if (!file_exists($file)) {
return $this->fail('未上传音频文件');
}
// $file = "https://lihai001.oss-cn-chengdu.aliyuncs.com/media/iat_mp3_16k.mp3";
$audioFile = fopen($file, 'rb');
if ($audioFile === false) {
return $this->fail('音频文件异常');
}
$words = '';
$iatHostUrl = "wss://iat-api.xfyun.cn/v2/iat";
$iat = new IatClient($this->app_id,$this->api_key,$this->api_secret);
$client = new Client($iat->assembleAuthUrl($iatHostUrl));
@ -196,7 +200,6 @@ class XunFeiController extends BaseApiController
//模拟音频采样间隔
usleep($intervel);
}
$words = '';
while (true) {
$response = $client->receive();
if ($response === null) {