44 Commits

Author SHA1 Message Date
Imayhaveborkedit
48b4ea84c9
Add silence padding after transmission breaks
Prevents unwanted interpolation/distortion of audio by sending silence
packets after pausing or ending the audio stream.
2023-09-22 03:38:42 -04:00
Imayhaveborkedit
8b8ce55378
Add encoder params to VoiceClient.play 2023-08-23 21:04:15 -04:00
Rapptz
8d047d9e1d Fix opus.Decoder triggering a segfault 2023-05-11 02:27:01 -04:00
Rapptz
3802780f77 Change a lot of logging INFO calls to be less verbose
Some of the logs were only useful for debug scenarios, so they have
been downgraded to DEBUG. Others were in INFO but supposed to be in
WARNING so those were upgraded.
2022-08-15 10:21:36 -04:00
Star Brilliant
bd637e2462
Specify required argument types for FFI functions
On arm64 macOS, variadic arguments have special calling convention rules.
Therefore, we must specify the required argument types for ctypes to 
pass the arguments correctly.

Apple documentation: https://developer.apple.com/documentation/xcode/writing-arm64-code-for-apple-platforms#Update-Code-that-Passes-Arguments-to-Variadic-Functions

Fix issue #8046
2022-05-18 06:32:03 -04:00
Rapptz
816d2176e9 Ignore type error already handled by exception handling 2022-03-24 23:50:47 -04:00
Stocker
5aa696ccfa
Fix typing issues and improve typing completeness across the library
Co-authored-by: Danny <Rapptz@users.noreply.github.com>
Co-authored-by: Josh <josh.ja.butt@gmail.com>
2022-03-13 23:52:10 -04:00
Josh
2b69b5d545
Remove discord.InvalidArgument
This uses TypeError and ValueError instead.
2022-02-26 01:44:49 -05:00
Josh
70b577e94b
Fix typing in voice related files 2022-02-22 02:37:22 -05:00
Rapptz
88b520b5ab Reformat code using black
Segments where readability was hampered were fixed by appropriate
format skipping directives. New code should hopefully be black
compatible. The moment they remove the -S option is probably the moment
I stop using black though.
2022-02-20 08:04:58 -05:00
apple502j
9db8698748
Typehint opus.py 2021-08-22 06:08:30 -04:00
Rapptz
ea2d972666 Make global log variable in modules private 2021-08-22 02:33:51 -04:00
Stocker
b6590d7f56
Add a few typehints to opus.py 2021-08-19 20:23:35 -04:00
Nadir Chowdhury
89456022cf
Add __all__ to remaining modules 2021-04-07 02:30:32 -04:00
Rapptz
9d39b135f4 Modernize code to use f-strings
This also removes the encoding on the top, since Python 3 does it by
default. It also changes some methods to use `yield from`.
2021-04-04 07:03:53 -04:00
Nadir Chowdhury
63ec23bac2
Code optimisations and refactoring via Sourcery 2021-02-24 21:26:51 -05:00
Nihaal Sangha
69bdc3a184
Change copyright year to present 2021-01-15 05:28:11 -05:00
Devon R
a20ddfa766
Add in Decoder 2020-12-12 20:12:04 -05:00
Rapptz
6071607176 Bump copyright year to 2020
Closes #2510
2020-01-19 20:03:00 -05:00
Imayhaveborkedit
fedf26bf3e Add FFmpegOpusAudio and other voice improvements
Rework FFmpeg player and add FFmpegOpusAudio

I have extracted some of the base FFmpeg source code into its own
base class and reimplemented the PCM and the new Opus variants.

Support avconv probing

Also fix a few things

Update `__all__`

Fix the bugs

Rework probe functions and add factory function

Probing involves subprocess so it has been reworked into an async
factory function.

Add docs + a few tweaks

* Removed unnecessary read() and is_opus() functions from FFmpegAudio
* Clear self._stdout in cleanup()
* Add 20 second process communication timeout to probe functions
* Capped probe function bitrate values at 512

Change AudioPlayer to use more accurate, monotonic time.perf_counter()

Add lazy opus loading

The library now no longer loads libopus on import, only on
opus.Encoder creation or manually.

Fix review nits
2019-07-22 20:46:40 -04:00
Imayhaveborkedit
20fa3001f2 Raise max encoder bitrate to 512kbps
Any higher is useless for opus anyways.
2019-06-20 22:52:47 -04:00
NCPlayz
3c9bcc2851 Improve documentation 2019-06-07 19:27:46 -04:00
Rapptz
04262b9371 Wording nit, library -> function in load_opus 2019-04-08 17:51:15 -04:00
Rapptz
c904e4f25b Add a note to load_opus that it's auto loaded on Windows. 2019-04-08 02:34:26 -04:00
NCPlayz
fb02191b80 Organise documentation 2019-03-19 08:24:42 -04:00
Dante Dam
9656a21ebe Bumped copyright years to 2019. 2019-01-28 22:22:50 -05:00
Hornwitser
efb4ff850e [lint] Fix import order
Reorder imports to be consistenly grouped by standard library, third
party library, and local modules in that order thoughout the library.
2018-11-24 22:17:58 -05:00
Hornwitser
34fd266cf9 [lint] Do log formating lazily
Convert log("fmt" % args) to log("fmt", args) as the latter is lazy and
does not do the formating if the string is never logged.
2018-11-24 22:17:58 -05:00
Hornwitser
4ae8e81660 [lint] Remove redundant exception variables
Use bare raise statement when reraising the exception that occured, and
remove unused exception variables.  Also remove a pointless exception
handler in discord.opus.
2018-11-24 22:17:57 -05:00
Daniel
d53c3a6c12
Fixed opus error check
Fixes #1056
2018-02-06 11:19:42 -05:00
Daniel
881e598a6f Add errcheck functions to opus foreign functions 2018-01-31 18:58:27 -05:00
Tobotimus
3112e1c17e Add intersphinx 2018-01-06 17:23:59 -05:00
Rapptz
b06899e7d4 Defer logging formatting until the logger is actually called.
This would cause unnecessary format calls even if you didn't have
logging enabled.
2017-06-09 18:53:24 -04:00
Rapptz
3b1b26ffb1 Re-implement voice sending.
This is a complete redesign of the old voice code.

A list of major changes is as follows:

* The voice websocket will now automatically reconnect with
  exponential back-off just like the regular Client does.
* Removal of the stream player concept.
* Audio now gracefully pauses and resumes when a disconnect is found.
* Introduce a discord.AudioSource concept to abstract streams
* Flatten previous stream player functionality with the
  VoiceClient, e.g. player.stop() is now voice_client.stop()
* With the above re-coupling this means you no longer have to
  store players anywhere.
* The after function now requires a single parameter, the error,
  if any existed. This will typically be None.

A lot of this design is experimental.
2017-04-18 03:49:48 -04:00
Rapptz
ff9f5749e1 Update copyright year to 2017. 2017-01-20 23:19:19 -05:00
Kyle Repinski
643950abf8 Add ability to set opus encoder input signal type. 2017-01-03 09:51:14 -05:00
Rapptz
2fc496304c Add libopus DLLs for ease of use. 2016-05-06 12:23:24 -04:00
Jake
7efabce4b2 Enable FEC/PLR
Enable forward error correction + packet loss percent tuning in opus encoder. Additionally, use some sane defaults. This should fix people hearing robo in music when packet loss is happening.
2016-05-03 22:34:30 -07:00
Rapptz
055f5291f0 Add ability to set bandwith and bitrate.
Patch by Jake.
2016-02-02 19:58:59 -05:00
Rapptz
db4cc791dd Update license of files to 2016. 2016-01-04 22:28:29 -05:00
Rapptz
9bec041423 Documentation fixes for opus related import errors. 2015-12-08 19:47:47 -05:00
Rapptz
72f355bb64 Add OpusNotLoaded exception and opus.is_loaded utility function. 2015-12-08 19:37:34 -05:00
Rapptz
9deb7796a5 Documentation fixes for opus bindings. 2015-12-08 16:22:01 -05:00
Rapptz
a6d6d832ff Working voice sending implementation.
Currently you can only send from a stream that implements
``read`` and a ``ffmpeg`` or ``avconv``.
2015-12-08 06:37:38 -05:00