gpt4 book ai didi

php - Ratchet php/棘爪连接关闭(1009 - )FRAME::CLOSE_TOO_BIG = 1009

转载 作者:行者123 更新时间:2023-12-04 16:14:21 25 4
gpt4 key购买 nike

我很高兴能够使用 Pawl,而且我可以使用它来处理小文件(例如 350 KB)。

但是,当我通过 $fullFileName 发送更大的文件(例如 30 MB)时如下所示,我收到此错误:Connection closed (1009 - ) .

\Ratchet\Client\connect($url)->then(function(\Ratchet\Client\WebSocket $conn) use($contentType, $fullFileName) {
$conn->on('message', function($msg) use ($conn) {
Log::debug("Received: {$msg}");
});
$conn->on('close', function($code = null, $reason = null) {
Log::debug("Connection closed ({$code} - {$reason})");
});
$conn->send(json_encode([
'content-type' => $contentType,
'timestamps' => true,
'speaker_labels' => true,
'smart_formatting' => true,
'inactivity_timeout' => 60 * 5,
'x-watson-learning-opt-out' => true,
'action' => 'start'
]));

$frame = new \Ratchet\RFC6455\Messaging\Frame(file_get_contents($fullFileName), true, \Ratchet\RFC6455\Messaging\Frame::OP_BINARY);
$binaryMsg = new \Ratchet\RFC6455\Messaging\Message();
$binaryMsg->addFrame($frame);
$conn->send($binaryMsg);
$conn->send(json_encode([
'action' => 'stop'
]));
}, function ($e) {
echo "Could not connect: {$e->getMessage()}\n";
});

当我搜索 Frame::CLOSE_TOO_BIG 的用法时, 我看到它只被 \Ratchet\RFC6455\Messaging\CloseFrameChecker 使用过.

但我一直无法弄清楚 \Ratchet\RFC6455\Messaging\CloseFrameChecker作品以及文件大小限制是什么以及如何发送大文件。

我首先尝试使用 str_split 将我的文件拆分成块然后添加单个帧,但是我每次都会遇到 session 超时,即使是小文件也是如此。

发送较大文件的适当方式是什么,避免 Frame::CLOSE_TOO_BIG 1009 错误和 session 超时?

最佳答案

https://cloud.ibm.com/apidocs/speech-to-texthttps://cloud.ibm.com/docs/services/speech-to-text?topic=speech-to-text-websockets#WSreturn说 1009 = 连接关闭,因为帧大小超过 4 MB 限制。

所以我尝试将音频文件拆分为单独的帧。我的第一次尝试总是导致 "Session timed out."错误。

https://cloud.ibm.com/docs/services/speech-to-text?topic=speech-to-text-input#timeouts说:

You do not need to worry about the session timeout after you send the last chunk to indicate the end of the stream. The service continues to process the audio until it returns the final transcription results. When you transcribe a long audio stream, the service can take more than 30 seconds to process the audio and generate a response. The service does not begin to calculate the session timeout until it finishes processing all audio that it has received. The service's processing time cannot cause the session to exceed the 30-second session timeout.



这是似乎对我有用的代码:
/**
* @param \Ratchet\Client\WebSocket $conn
* @param string $fileContents
*/
public function sendBinaryMessage($conn, $fileContents) {
$chunks = str_split($fileContents, 100);
Log::debug('Split audio into this many frames: ' . count($chunks));
$final = true;
foreach ($chunks as $key => $chunk) {
Log::debug('send chunk key ' . $key);
$frame = new \Ratchet\RFC6455\Messaging\Frame($chunk, $final, \Ratchet\RFC6455\Messaging\Frame::OP_BINARY);
$conn->send($frame);
}
}

关于php - Ratchet php/棘爪连接关闭(1009 - )FRAME::CLOSE_TOO_BIG = 1009,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55082401/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com