阿里SR Gateway:IDLE_TIMEOUT:Websocket session is idle for too long time

Ali SR will automatically disconnect if there is no data stream input within 10 seconds

The sdk itself has not sent any data for a long time after requesting to establish a connection. After more than 10s, the server will return a 40000004 error message.

Gateway:IDLE_TIMEOUT:Websocket session is idle for too long time

Workaround:
Send an empty, noiseless data stream:

waveInEvent.WaveFormat = new WaveFormat(16000, 16, 1)

sampleRate:采样率,表示每秒钟采集的样本数。
bitsPerSample:每个样本的位数,表示每个样本占用的位数。
channels:声道数,表示音频的声道数,可以是单声道(1)或立体声(2)。

How many bytes are collected in one millisecond

Sampling rate refers to the number of samples taken per second, usually expressed in hertz (Hz). If the sample rate is 16000 Hz, then 16000 samples are taken every second. The number of bits per sample is 16 bits, or 2 bytes. Therefore, the amount of data collected per second is 16000 * 2 = 32000 bytes. If you want to calculate the amount of data collected per millisecond, you can divide the amount of data collected per second by 1000, which is 32000 / 1000 = 32 bytes. Therefore, the amount of data collected per millisecond is 32 bytes.

so

private static readonly byte[] _silenceByteData = new byte[] {
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
            0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
        };
private readonly ArraySegment<byte> _silenceSegments = new ArraySegment<byte>(_silenceByteData, 0, 32);

Set a time t1 at the place where the data is sent, and update the value every time the sending time
starts a task, if the current time t2

When t2 - t1 > 5 seconds, send a 1ms noise-free _silenceSegments stream to the interface

おすすめ

転載: blog.csdn.net/qq_27093891/article/details/130414891