更新iat语音编码
This commit is contained in:
parent
87f2f22a32
commit
98b083fcb6
@ -144,9 +144,17 @@ class XunFeiController extends BaseApiController
|
||||
return $this->fail('录音文件太长');
|
||||
}
|
||||
$ext = pathinfo($file, PATHINFO_EXTENSION);
|
||||
if ($ext != 'mp3') {
|
||||
$extArray = ['mp3', 'pcm'];
|
||||
if (!in_array($ext, $extArray)) {
|
||||
return $this->fail('录音格式错误');
|
||||
}
|
||||
$encoding = 'raw';
|
||||
if ($ext == 'mp3') {
|
||||
$encoding = 'lame';
|
||||
}
|
||||
if ($ext == 'pcm') {
|
||||
$encoding = 'raw';
|
||||
}
|
||||
// $file = "https://lihai001.oss-cn-chengdu.aliyuncs.com/media/iat_mp3_16k.mp3";
|
||||
$audioFile = fopen($file, 'rb');
|
||||
if ($audioFile === false) {
|
||||
@ -160,7 +168,7 @@ class XunFeiController extends BaseApiController
|
||||
$client = new Client($iat->assembleAuthUrl($iatHostUrl));
|
||||
if ($client) {
|
||||
$frameSize = 1280; //每一帧的音频大小
|
||||
$intervel = 40 * 1000; //发送音频间隔
|
||||
$intervel = 20 * 1000; //发送音频间隔
|
||||
$status = 0;
|
||||
while (true) {
|
||||
$len = fread($audioFile, $frameSize);
|
||||
@ -185,7 +193,7 @@ class XunFeiController extends BaseApiController
|
||||
'status' => 0,
|
||||
'format' => 'audio/L16;rate=16000',
|
||||
'audio' => base64_encode($len),
|
||||
'encoding' => 'lame'
|
||||
'encoding' => $encoding
|
||||
)
|
||||
);
|
||||
$client->send(json_encode($frameData));
|
||||
@ -197,7 +205,7 @@ class XunFeiController extends BaseApiController
|
||||
'status' => 1,
|
||||
'format' => 'audio/L16;rate=16000',
|
||||
'audio' => base64_encode($len),
|
||||
'encoding' => 'raw'
|
||||
'encoding' => $encoding
|
||||
)
|
||||
);
|
||||
$client->send(json_encode($frameData));
|
||||
@ -208,7 +216,7 @@ class XunFeiController extends BaseApiController
|
||||
'status' => 2,
|
||||
'format' => 'audio/L16;rate=16000',
|
||||
'audio' => base64_encode($len),
|
||||
'encoding' => 'raw'
|
||||
'encoding' => $encoding
|
||||
)
|
||||
);
|
||||
$client->send(json_encode($frameData));
|
||||
|
Loading…
x
Reference in New Issue
Block a user