Table of Contents

Class OpusEncodeStream

Namespace
Kook.Audio.Streams
Assembly
Kook.Net.WebSocket.dll

表示一个 Opus 编码音频流。

public class OpusEncodeStream : AudioOutStream, IAsyncDisposable, IDisposable
Inheritance
OpusEncodeStream
Implements
Inherited Members

Constructors

OpusEncodeStream(AudioStream, int, AudioApplication, int)

初始化一个 OpusEncodeStream 类的新实例。

public OpusEncodeStream(AudioStream next, int bitrate, AudioApplication application, int packetLoss)

Parameters

next AudioStream

要写入编码数据的音频流,是音频流写入链中的下一个音频流对象。

bitrate int

音频流的比特率。

application AudioApplication

音频应用程序的应用场景。

packetLoss int

音频流的丢包率。

Fields

SampleRate

获取音频流的采样率。

public const int SampleRate = 48000

Field Value

int

Methods

ClearAsync(CancellationToken)

清空该流.

public override Task ClearAsync(CancellationToken cancellationToken)

Parameters

cancellationToken CancellationToken

用于取消该异步操作的取消令牌。

Returns

Task

一个清空操作的异步任务。

Remarks

此操作会导致丢失所有缓冲的数据。

Dispose(bool)

Releases the unmanaged resources used by the Stream and optionally releases the managed resources.

protected override void Dispose(bool disposing)

Parameters

disposing bool

true to release both managed and unmanaged resources; false to release only unmanaged resources.

FlushAsync(CancellationToken)

Asynchronously clears all buffers for this stream, causes any buffered data to be written to the underlying device, and monitors cancellation requests.

public override Task FlushAsync(CancellationToken cancellationToken)

Parameters

cancellationToken CancellationToken

The token to monitor for cancellation requests. The default value is None.

Returns

Task

A task that represents the asynchronous flush operation.

Exceptions

ObjectDisposedException

The stream has been disposed.

OperationCanceledException

The cancellation token was canceled. This exception is stored into the returned task.

WriteAsync(byte[], int, int, CancellationToken)

Asynchronously writes a sequence of bytes to the current stream, advances the current position within this stream by the number of bytes written, and monitors cancellation requests.

public override Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)

Parameters

buffer byte[]

The buffer to write data from.

offset int

The zero-based byte offset in buffer from which to begin copying bytes to the stream.

count int

The maximum number of bytes to write.

cancellationToken CancellationToken

The token to monitor for cancellation requests. The default value is None.

Returns

Task

A task that represents the asynchronous write operation.

Exceptions

ArgumentNullException

buffer is null.

ArgumentOutOfRangeException

offset or count is negative.

ArgumentException

The sum of offset and count is larger than the buffer length.

NotSupportedException

The stream does not support writing.

ObjectDisposedException

The stream has been disposed.

InvalidOperationException

The stream is currently in use by a previous write operation.

OperationCanceledException

The cancellation token was canceled. This exception is stored into the returned task.

WriteSilentFramesAsync()

发送静默帧以避免数据传输中断后的插值错误。

public Task WriteSilentFramesAsync()

Returns

Task

一个表示写入静默帧操作的异步任务。