Automatically toggle speaking boolean
This commit is contained in:
@@ -239,7 +239,7 @@ namespace Discord.Audio
|
|||||||
throw new InvalidOperationException($"Discord selected an unexpected mode: {data.Mode}");
|
throw new InvalidOperationException($"Discord selected an unexpected mode: {data.Mode}");
|
||||||
|
|
||||||
_secretKey = data.SecretKey;
|
_secretKey = data.SecretKey;
|
||||||
await ApiClient.SendSetSpeaking(true).ConfigureAwait(false);
|
//await ApiClient.SendSetSpeaking(true).ConfigureAwait(false);
|
||||||
|
|
||||||
var _ = _connection.CompleteAsync();
|
var _ = _connection.CompleteAsync();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -78,6 +78,7 @@ namespace Discord.Audio.Streams
|
|||||||
Frame frame;
|
Frame frame;
|
||||||
if (_queuedFrames.TryDequeue(out frame))
|
if (_queuedFrames.TryDequeue(out frame))
|
||||||
{
|
{
|
||||||
|
await _next.SetSpeakingAsync(true).ConfigureAwait(false);
|
||||||
await _next.WriteAsync(frame.Buffer, 0, frame.Bytes).ConfigureAwait(false);
|
await _next.WriteAsync(frame.Buffer, 0, frame.Bytes).ConfigureAwait(false);
|
||||||
_bufferPool.Enqueue(frame.Buffer);
|
_bufferPool.Enqueue(frame.Buffer);
|
||||||
_queueLock.Release();
|
_queueLock.Release();
|
||||||
@@ -93,6 +94,8 @@ namespace Discord.Audio.Streams
|
|||||||
{
|
{
|
||||||
if (_silenceFrames++ < MaxSilenceFrames)
|
if (_silenceFrames++ < MaxSilenceFrames)
|
||||||
await _next.WriteAsync(_silenceFrame, 0, _silenceFrame.Length).ConfigureAwait(false);
|
await _next.WriteAsync(_silenceFrame, 0, _silenceFrame.Length).ConfigureAwait(false);
|
||||||
|
else
|
||||||
|
await _next.SetSpeakingAsync(false).ConfigureAwait(false);
|
||||||
nextTick += _ticksPerFrame;
|
nextTick += _ticksPerFrame;
|
||||||
}
|
}
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ namespace Discord.Audio.Streams
|
|||||||
///<summary> Wraps an IAudioClient, sending voice data on write. </summary>
|
///<summary> Wraps an IAudioClient, sending voice data on write. </summary>
|
||||||
public class OutputStream : AudioOutStream
|
public class OutputStream : AudioOutStream
|
||||||
{
|
{
|
||||||
|
private bool _isSpeaking;
|
||||||
|
|
||||||
private readonly DiscordVoiceAPIClient _client;
|
private readonly DiscordVoiceAPIClient _client;
|
||||||
public OutputStream(IAudioClient client)
|
public OutputStream(IAudioClient client)
|
||||||
: this((client as AudioClient).ApiClient) { }
|
: this((client as AudioClient).ApiClient) { }
|
||||||
@@ -14,6 +16,14 @@ namespace Discord.Audio.Streams
|
|||||||
_client = client;
|
_client = client;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task SetSpeakingAsync(bool isSpeaking)
|
||||||
|
{
|
||||||
|
if (_isSpeaking != isSpeaking)
|
||||||
|
{
|
||||||
|
await _client.SendSetSpeaking(isSpeaking).ConfigureAwait(false);
|
||||||
|
_isSpeaking = isSpeaking;
|
||||||
|
}
|
||||||
|
}
|
||||||
public override async Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancelToken)
|
public override async Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancelToken)
|
||||||
{
|
{
|
||||||
cancelToken.ThrowIfCancellationRequested();
|
cancelToken.ThrowIfCancellationRequested();
|
||||||
|
|||||||
Reference in New Issue
Block a user