AudioSource
Base class representing an audio stream. The audio stream can be Opus encoded or not, however if the audio stream is not Opus encoded then the audio format must be 16-bit 48KHz stereo PCM.Methods
read
is_opus() method returns True, then it must return 20ms worth of Opus encoded audio. Otherwise, it must be 20ms worth of 16-bit 48KHz stereo PCM, which is about 3,840 bytes per frame (20ms worth of audio).
Returns: bytes - A bytes like object that represents the PCM or Opus data.
is_opus
cleanup
PCMAudio
Represents raw 16-bit 48KHz stereo PCM audio source.Attributes
A file-like object that reads byte data representing raw PCM.
Constructor
A file-like object that reads byte data representing raw PCM.
Example
FFmpegPCMAudio
An audio source from FFmpeg (or AVConv). This launches a sub-process to a specific input file given.Constructor
The input that ffmpeg will take and convert to PCM bytes. If
pipe is True then this is a file-like object that is passed to the stdin of ffmpeg.The executable name (and path) to use. Defaults to
ffmpeg.If
True, denotes that source parameter will be passed to the stdin of ffmpeg.A file-like object to pass to the Popen constructor. Could also be an instance of
subprocess.PIPE.Extra command line arguments to pass to ffmpeg before the
-i flag.Extra command line arguments to pass to ffmpeg after the
-i flag.ClientException- The subprocess failed to be created.
Example
FFmpegOpusAudio
An audio source from FFmpeg (or AVConv). This launches a sub-process to a specific input file given. However, rather than producing PCM packets likeFFmpegPCMAudio does that need to be encoded to Opus, this class produces Opus packets, skipping the encoding step done by the library.
Alternatively, instead of instantiating this class directly, you can use FFmpegOpusAudio.from_probe() to probe for bitrate and codec information. This can be used to opportunistically skip pointless re-encoding of existing Opus audio data for a boost in performance at the cost of a short initial delay to gather the information.
Constructor
The input that ffmpeg will take and convert to Opus bytes. If
pipe is True then this is a file-like object that is passed to the stdin of ffmpeg.The bitrate in kbps to encode the output to. Defaults to
128.The codec to use to encode the audio data. Normally this would be just
libopus, but is used by FFmpegOpusAudio.from_probe() to opportunistically skip pointlessly re-encoding Opus audio data by passing copy as the codec value. Any values other than copy, or libopus will be considered libopus.The executable name (and path) to use. Defaults to
ffmpeg.If
True, denotes that source parameter will be passed to the stdin of ffmpeg.A file-like object to pass to the Popen constructor. Could also be an instance of
subprocess.PIPE.Extra command line arguments to pass to ffmpeg before the
-i flag.Extra command line arguments to pass to ffmpeg after the
-i flag.ClientException- The subprocess failed to be created.
Class Methods
from_probe
FFmpegOpusAudio after probing the input source for audio codec and bitrate information.
The input source to probe and play.
The probing method used to determine bitrate and codec information. As a string, valid values are
native to use ffprobe (or avprobe) and fallback to use ffmpeg (or avconv). As a callable, it must take two string arguments, source and executable.**kwargs
The remaining parameters to be passed to the
FFmpegOpusAudio constructor, excluding bitrate and codec.AttributeError- Invalid probe method, must be ‘native’ or ‘fallback’.TypeError- Invalid value for probe parameter, must be str or a callable.
probe
The input source to probe.
Identical to the
method parameter for from_probe.The executable name to use. Defaults to
ffmpeg.AttributeError- Invalid probe method.TypeError- Invalid value for probe parameter.
Example
PCMVolumeTransformer
Transforms a previousAudioSource to have volume controls.
This does not work on audio sources that have AudioSource.is_opus() set to True.
Constructor
The original AudioSource to transform.
The initial volume to set it to. See
volume property for more info.TypeError- Not an audio source.ClientException- The audio source is opus encoded.
Properties
Retrieves or sets the volume as a floating point percentage (e.g.
1.0 for 100%).The original audio source being transformed.
