diff options
| author | Rapptz <[email protected]> | 2016-05-11 21:19:52 -0400 |
|---|---|---|
| committer | Rapptz <[email protected]> | 2016-05-12 06:06:38 -0400 |
| commit | 3c04ec2af092f87fd5e99412368c5d2c36e4a8df (patch) | |
| tree | 0651e9d7c07e5e4aaa21e33a658f1ab108c41a46 | |
| parent | Add VoiceClient.move_to for quick switching of voice channels. (diff) | |
| download | discord.py-3c04ec2af092f87fd5e99412368c5d2c36e4a8df.tar.xz discord.py-3c04ec2af092f87fd5e99412368c5d2c36e4a8df.zip | |
Add a way to change the player volume.
| -rw-r--r-- | discord/voice_client.py | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/discord/voice_client.py b/discord/voice_client.py index 0826ad1e..21c96405 100644 --- a/discord/voice_client.py +++ b/discord/voice_client.py @@ -50,6 +50,7 @@ import subprocess import shlex import functools import datetime +import audioop import nacl.secret log = logging.getLogger(__name__) @@ -70,6 +71,7 @@ class StreamPlayer(threading.Thread): self._connected = connected self.after = after self.delay = encoder.frame_length / 1000.0 + self._volume = 1.0 def run(self): self.loops = 0 @@ -86,6 +88,10 @@ class StreamPlayer(threading.Thread): self.loops += 1 data = self.buff.read(self.frame_size) + + if self._volume != 1.0: + data = audioop.mul(data, 2, min(self._volume, 2.0)) + if len(data) != self.frame_size: self.stop() break @@ -103,6 +109,14 @@ class StreamPlayer(threading.Thread): except: pass + @property + def volume(self): + return self._volume + + @volume.setter + def volume(self, value): + self._volume = max(value, 0.0) + def pause(self): self._resumed.clear() @@ -550,6 +564,10 @@ class VoiceClient: +---------------------+-----------------------------------------------------+ | player.resume() | Resumes the audio stream. | +---------------------+-----------------------------------------------------+ + | player.volume | Allows you to set the volume of the stream. 1.0 is | + | | equivalent to 100% and 0.0 is equal to 0%. The | + | | maximum the volume can be set to is 2.0 for 200%. | + +---------------------+-----------------------------------------------------+ The stream must have the same sampling rate as the encoder and the same number of channels. The defaults are 48000 Hz and 2 channels. You |