Exposed IAudioClient.SetSpeakingAsync
This commit is contained in:
@@ -21,6 +21,7 @@ namespace Discord.Audio
|
|||||||
int UdpLatency { get; }
|
int UdpLatency { get; }
|
||||||
|
|
||||||
Task StopAsync();
|
Task StopAsync();
|
||||||
|
Task SetSpeakingAsync(bool value);
|
||||||
|
|
||||||
/// <summary>Creates a new outgoing stream accepting Opus-encoded data.</summary>
|
/// <summary>Creates a new outgoing stream accepting Opus-encoded data.</summary>
|
||||||
AudioOutStream CreateOpusStream(int bufferMillis = 1000);
|
AudioOutStream CreateOpusStream(int bufferMillis = 1000);
|
||||||
|
|||||||
@@ -44,6 +44,7 @@ namespace Discord.Audio
|
|||||||
private string _url, _sessionId, _token;
|
private string _url, _sessionId, _token;
|
||||||
private ulong _userId;
|
private ulong _userId;
|
||||||
private uint _ssrc;
|
private uint _ssrc;
|
||||||
|
private bool _isSpeaking;
|
||||||
|
|
||||||
public SocketGuild Guild { get; }
|
public SocketGuild Guild { get; }
|
||||||
public DiscordVoiceAPIClient ApiClient { get; private set; }
|
public DiscordVoiceAPIClient ApiClient { get; private set; }
|
||||||
@@ -242,6 +243,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;
|
||||||
|
_isSpeaking = false;
|
||||||
await ApiClient.SendSetSpeaking(false).ConfigureAwait(false);
|
await ApiClient.SendSetSpeaking(false).ConfigureAwait(false);
|
||||||
_keepaliveTask = RunKeepaliveAsync(5000, _connection.CancelToken);
|
_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)
|
internal void Dispose(bool disposing)
|
||||||
{
|
{
|
||||||
if (disposing)
|
if (disposing)
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ namespace Discord.Audio.Streams
|
|||||||
private readonly SemaphoreSlim _queueLock;
|
private readonly SemaphoreSlim _queueLock;
|
||||||
private readonly Logger _logger;
|
private readonly Logger _logger;
|
||||||
private readonly int _ticksPerFrame, _queueLength;
|
private readonly int _ticksPerFrame, _queueLength;
|
||||||
private bool _isPreloaded, _isSpeaking;
|
private bool _isPreloaded;
|
||||||
private int _silenceFrames;
|
private int _silenceFrames;
|
||||||
|
|
||||||
public BufferedWriteStream(AudioStream next, IAudioClient client, int bufferMillis, CancellationToken cancelToken, int maxFrameSize = 1500)
|
public BufferedWriteStream(AudioStream next, IAudioClient client, int bufferMillis, CancellationToken cancelToken, int maxFrameSize = 1500)
|
||||||
@@ -88,11 +88,7 @@ namespace Discord.Audio.Streams
|
|||||||
Frame frame;
|
Frame frame;
|
||||||
if (_queuedFrames.TryDequeue(out frame))
|
if (_queuedFrames.TryDequeue(out frame))
|
||||||
{
|
{
|
||||||
if (!_isSpeaking)
|
await _client.SetSpeakingAsync(true).ConfigureAwait(false);
|
||||||
{
|
|
||||||
await _client.ApiClient.SendSetSpeaking(true).ConfigureAwait(false);
|
|
||||||
_isSpeaking = true;
|
|
||||||
}
|
|
||||||
_next.WriteHeader(seq++, timestamp, false);
|
_next.WriteHeader(seq++, timestamp, 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);
|
||||||
@@ -113,11 +109,8 @@ namespace Discord.Audio.Streams
|
|||||||
_next.WriteHeader(seq++, timestamp, false);
|
_next.WriteHeader(seq++, timestamp, false);
|
||||||
await _next.WriteAsync(_silenceFrame, 0, _silenceFrame.Length).ConfigureAwait(false);
|
await _next.WriteAsync(_silenceFrame, 0, _silenceFrame.Length).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
else if (_isSpeaking)
|
else
|
||||||
{
|
await _client.SetSpeakingAsync(false).ConfigureAwait(false);
|
||||||
await _client.ApiClient.SendSetSpeaking(false).ConfigureAwait(false);
|
|
||||||
_isSpeaking = false;
|
|
||||||
}
|
|
||||||
nextTick += _ticksPerFrame;
|
nextTick += _ticksPerFrame;
|
||||||
timestamp += OpusEncoder.FrameSamplesPerChannel;
|
timestamp += OpusEncoder.FrameSamplesPerChannel;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user