Browse Source

Exposed IAudioClient.SetSpeakingAsync

pull/611/head
RogueException 8 years ago
parent
commit
8d9e11c08a
3 changed files with 16 additions and 11 deletions
  1. +1
    -0
      src/Discord.Net.Core/Audio/IAudioClient.cs
  2. +11
    -0
      src/Discord.Net.WebSocket/Audio/AudioClient.cs
  3. +4
    -11
      src/Discord.Net.WebSocket/Audio/Streams/BufferedWriteStream.cs

+ 1
- 0
src/Discord.Net.Core/Audio/IAudioClient.cs View File

@@ -21,6 +21,7 @@ namespace Discord.Audio
int UdpLatency { get; }

Task StopAsync();
Task SetSpeakingAsync(bool value);

/// <summary>Creates a new outgoing stream accepting Opus-encoded data.</summary>
AudioOutStream CreateOpusStream(int bufferMillis = 1000);


+ 11
- 0
src/Discord.Net.WebSocket/Audio/AudioClient.cs View File

@@ -44,6 +44,7 @@ namespace Discord.Audio
private string _url, _sessionId, _token;
private ulong _userId;
private uint _ssrc;
private bool _isSpeaking;

public SocketGuild Guild { get; }
public DiscordVoiceAPIClient ApiClient { get; private set; }
@@ -242,6 +243,7 @@ namespace Discord.Audio
throw new InvalidOperationException($"Discord selected an unexpected mode: {data.Mode}");

SecretKey = data.SecretKey;
_isSpeaking = false;
await ApiClient.SendSetSpeaking(false).ConfigureAwait(false);
_keepaliveTask = RunKeepaliveAsync(5000, _connection.CancelToken);

@@ -453,6 +455,15 @@ namespace Discord.Audio
}
}

public async Task SetSpeakingAsync(bool value)
{
if (_isSpeaking != value)
{
_isSpeaking = value;
await ApiClient.SendSetSpeaking(value).ConfigureAwait(false);
}
}

internal void Dispose(bool disposing)
{
if (disposing)


+ 4
- 11
src/Discord.Net.WebSocket/Audio/Streams/BufferedWriteStream.cs View File

@@ -35,7 +35,7 @@ namespace Discord.Audio.Streams
private readonly SemaphoreSlim _queueLock;
private readonly Logger _logger;
private readonly int _ticksPerFrame, _queueLength;
private bool _isPreloaded, _isSpeaking;
private bool _isPreloaded;
private int _silenceFrames;

public BufferedWriteStream(AudioStream next, IAudioClient client, int bufferMillis, CancellationToken cancelToken, int maxFrameSize = 1500)
@@ -88,11 +88,7 @@ namespace Discord.Audio.Streams
Frame frame;
if (_queuedFrames.TryDequeue(out frame))
{
if (!_isSpeaking)
{
await _client.ApiClient.SendSetSpeaking(true).ConfigureAwait(false);
_isSpeaking = true;
}
await _client.SetSpeakingAsync(true).ConfigureAwait(false);
_next.WriteHeader(seq++, timestamp, false);
await _next.WriteAsync(frame.Buffer, 0, frame.Bytes).ConfigureAwait(false);
_bufferPool.Enqueue(frame.Buffer);
@@ -113,11 +109,8 @@ namespace Discord.Audio.Streams
_next.WriteHeader(seq++, timestamp, false);
await _next.WriteAsync(_silenceFrame, 0, _silenceFrame.Length).ConfigureAwait(false);
}
else if (_isSpeaking)
{
await _client.ApiClient.SendSetSpeaking(false).ConfigureAwait(false);
_isSpeaking = false;
}
else
await _client.SetSpeakingAsync(false).ConfigureAwait(false);
nextTick += _ticksPerFrame;
timestamp += OpusEncoder.FrameSamplesPerChannel;
}


Loading…
Cancel
Save