Add boolean option to specify if VoiceClient.play_audio should encode.
This allows people to send raw opus encoded data instead of being forced to encode to Opus.
This commit is contained in:
parent
4fa1bcadaa
commit
827ca1e5a2
@ -590,7 +590,7 @@ class VoiceClient:
|
|||||||
self.encoder = OpusEncoder(sample_rate, channels)
|
self.encoder = OpusEncoder(sample_rate, channels)
|
||||||
log.info('created opus encoder with {0.__dict__}'.format(self.encoder))
|
log.info('created opus encoder with {0.__dict__}'.format(self.encoder))
|
||||||
|
|
||||||
def create_stream_player(self, stream, after=None):
|
def create_stream_player(self, stream, *, after=None):
|
||||||
"""Creates a stream player that launches in a separate thread to
|
"""Creates a stream player that launches in a separate thread to
|
||||||
play audio.
|
play audio.
|
||||||
|
|
||||||
@ -626,7 +626,7 @@ class VoiceClient:
|
|||||||
-----------
|
-----------
|
||||||
stream
|
stream
|
||||||
The stream object to read from.
|
The stream object to read from.
|
||||||
after:
|
after
|
||||||
The finalizer that is called after the stream is exhausted.
|
The finalizer that is called after the stream is exhausted.
|
||||||
All exceptions it throws are silently discarded. It is called
|
All exceptions it throws are silently discarded. It is called
|
||||||
without parameters.
|
without parameters.
|
||||||
@ -638,15 +638,17 @@ class VoiceClient:
|
|||||||
"""
|
"""
|
||||||
return StreamPlayer(stream, self.encoder, self._connected, self.play_audio, after)
|
return StreamPlayer(stream, self.encoder, self._connected, self.play_audio, after)
|
||||||
|
|
||||||
def play_audio(self, data):
|
def play_audio(self, data, *, encode=True):
|
||||||
"""Sends an audio packet composed of the data.
|
"""Sends an audio packet composed of the data.
|
||||||
|
|
||||||
You must be connected to play audio.
|
You must be connected to play audio.
|
||||||
|
|
||||||
Parameters
|
Parameters
|
||||||
----------
|
----------
|
||||||
data
|
data : bytes
|
||||||
The *bytes-like object* denoting PCM voice data.
|
The *bytes-like object* denoting PCM or Opus voice data.
|
||||||
|
encode : bool
|
||||||
|
Indicates if ``data`` should be encoded into Opus.
|
||||||
|
|
||||||
Raises
|
Raises
|
||||||
-------
|
-------
|
||||||
@ -657,7 +659,10 @@ class VoiceClient:
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
self.checked_add('sequence', 1, 65535)
|
self.checked_add('sequence', 1, 65535)
|
||||||
encoded_data = self.encoder.encode(data, self.encoder.samples_per_frame)
|
if encode:
|
||||||
|
encoded_data = self.encoder.encode(data, self.encoder.samples_per_frame)
|
||||||
|
else:
|
||||||
|
encoded_data = data
|
||||||
packet = self._get_voice_packet(encoded_data)
|
packet = self._get_voice_packet(encoded_data)
|
||||||
sent = self.socket.sendto(packet, (self.endpoint_ip, self.voice_port))
|
sent = self.socket.sendto(packet, (self.endpoint_ip, self.voice_port))
|
||||||
self.checked_add('timestamp', self.encoder.samples_per_frame, 4294967295)
|
self.checked_add('timestamp', self.encoder.samples_per_frame, 4294967295)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user