ratchetphp/Pawl连接已关闭(1009-)FRAME :: CLOSE_TOO_BIG = 1009 [英] ratchetphp/Pawl Connection closed (1009 - ) FRAME::CLOSE_TOO_BIG = 1009

查看:226
本文介绍了ratchetphp/Pawl连接已关闭(1009-)FRAME :: CLOSE_TOO_BIG = 1009的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Pawl感到很兴奋,并且它适用于较小的文件(例如350 KB).

I'm excited to be using Pawl, and I have it working for small files (such as 350 KB).

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

However, when I send a larger file (say, 30 MB) via $fullFileName as shown below, I get this error: 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使用.

When I search for usages of Frame::CLOSE_TOO_BIG, I see that it's only ever used by \Ratchet\RFC6455\Messaging\CloseFrameChecker.

但是我一直无法弄清\Ratchet\RFC6455\Messaging\CloseFrameChecker的工作原理,文件大小限制以及如何发送大文件.

But I've been unable to figure out how \Ratchet\RFC6455\Messaging\CloseFrameChecker works and what the file size limits are and how to send large files.

我尝试过先使用str_split将文件拆分为多个块,然后添加单个帧,但是随后每次都遇到会话超时,即使是小文件也是如此.

I've tried first splitting my file into chunks using str_split and then adding individual frames, but then I hit session timeouts every time, even for small files.

什么是发送较大文件,避免Frame::CLOSE_TOO_BIG 1009错误和会话超时的合适方法?

What is the appropriate way to send larger files, avoiding the Frame::CLOSE_TOO_BIG 1009 error and session timeouts?

推荐答案

https://cloud.ibm.com/apidocs/speech-to-text

https://cloud.ibm.com/apidocs/speech-to-text and https://cloud.ibm.com/docs/services/speech-to-text?topic=speech-to-text-websockets#WSreturn say 1009 = The connection closed because the frame size exceeded the 4 MB limit.

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

So I tried splitting the audio file into separate frames. My first attempts always resulted in a "Session timed out." error.

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

在发送最后一个块以指示流结束之后,您不必担心会话超时.该服务将继续处理音频,直到返回最终的转录结果.转录较长的音频流时,该服务可能需要30秒钟以上的时间来处理音频并生成响应.该服务在完成处理已收到的所有音频之前,不会开始计算会话超时.服务的处理时间不能导致会话超过30秒的会话超时.

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.

以下代码似乎对我有用:

Here is the code that seems to work for me:

/**
 * @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);
    }
}

这篇关于ratchetphp/Pawl连接已关闭(1009-)FRAME :: CLOSE_TOO_BIG = 1009的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆