voicebox.effects package
Submodules
voicebox.effects.chain module
- class voicebox.effects.chain.ParallelChain(*effects: ~voicebox.effects.effect.Effect, dry_gain: float = 0.0, combine_func: ~typing.Callable[[...], ~numpy.ndarray] = <function sum>)[source]
Bases:
EffectApplies effects in parallel and combines the outputs.
All effects must output audios with the same sample rate. The combined output audio will expand to fit the longest effect audio.
- Parameters:
effects – Effects to apply in parallel.
dry_gain – How much of the original audio to include in the output. 0 (default) is none, 1 is unity.
combine_func – Function to combine the output signals. Defaults to
np.sum.
- apply(audio: Audio) Audio[source]
Applies the effect to the audio signal.
May or may not return a new
Audioinstance.
- combine_func: Callable[[ndarray], ndarray]
- dry_gain: float
voicebox.effects.dc_offset module
voicebox.effects.effect module
- class voicebox.effects.effect.EffectWithDryWet(dry: float, wet: float)[source]
Bases:
Effect,ABCBase class for effects that have a dry/wet mix.
- Parameters:
dry – Dry (input) signal level. 0 is none, 1 is unity.
wet – Wet (affected) signal level. 0 is none, 1 is unity.
voicebox.effects.eq module
Equalization effects module.
See Filter.build() for building basic filter effects.
- Simple example:
>>> from voicebox.effects import Filter >>> filter = Filter.build('highpass', 200) >>> filter = Filter.build('bandpass', (100, 10000))
- class voicebox.effects.eq.Filter(filter_param_builder: voicebox.effects.eq.FilterParamBuilder)[source]
Bases:
Effect- apply(audio: Audio) Audio[source]
Applies the effect to the audio signal.
May or may not return a new
Audioinstance.
- classmethod build(btype: Literal['lowpass', 'highpass', 'bandpass', 'bandstop'], freq: int | float | Tuple[int | float, int | float], order: int = 1, rp: float = None, rs: float = None, ftype: Literal['butter', 'cheby1', 'cheby2', 'ellip', 'bessel'] = 'butter') Filter[source]
Builds a filter using
scipy.signal.iirfilter.See here for details: https://docs.scipy.org/doc/scipy/reference/generated/scipy.signal.iirfilter.html
- Parameters:
btype (BType) – The type of filter. Should be one of
'lowpass','highpass','bandpass', or'bandstop'.freq (FreqOrBand) – The filter frequency in Hz. Should be a single number for lowpass/highpass, or a frequency band as a sequence
(low_freq, high_freq)for bandpass/bandstop. See thecenter_to_band()function for easy converting from a center freq with bandwidth to a frequency band.order (int, optional) – The order of the filter. Defaults to 1. Higher orders will have faster dropoffs.
rp (float, optional) – For Chebyshev and elliptic filters, provides the maximum ripple in the passband. (dB)
rs (float, optional) – For Chebyshev and elliptic filters, provides the minimum attenuation in the stop band. (dB)
ftype (FType, optional) –
The type of IIR filter to design. Defaults to
'butter'. Should be one of:'butter'(Butterworth)'cheby1'(Chebychev I)'cheby2'(Chebychev II)'ellip'(Cauer/elliptic)'bessel'(Bessel/Thomson)
- Returns:
A Filter instance with the specified parameters.
- Return type:
- filter_param_builder: FilterParamBuilder
- class voicebox.effects.eq.IIRFilterParamBuilder(order: int, freq: int | float | Tuple[int | float, int | float], rp: float | None, rs: float | None, btype: Literal['lowpass', 'highpass', 'bandpass', 'bandstop'], ftype: Literal['butter', 'cheby1', 'cheby2', 'ellip', 'bessel'])[source]
Bases:
FilterParamBuilder- btype: Literal['lowpass', 'highpass', 'bandpass', 'bandstop']
- freq: int | float | Tuple[int | float, int | float]
- ftype: Literal['butter', 'cheby1', 'cheby2', 'ellip', 'bessel']
- order: int
- rp: float | None
- rs: float | None
voicebox.effects.flanger module
- class voicebox.effects.flanger.Flanger(rate: float = 0.15, min_delay: float = 0.0025, max_delay: float = 0.0035, feedback: float = 0.9, t_offset: float = 0.0, t_offset_func: Callable[[], float] | None=<built-in function monotonic>, dry: float = 0.5, wet: float = 0.5)[source]
Bases:
EffectWithDryWetFlanger effect with a very metallic sound.
- Parameters:
rate – LFO rate in Hz. Default is .15.
min_delay – Minimum delay time in seconds. Default is .0025.
max_delay – Maximum delay time in seconds. Default is .0035.
feedback – Delay feedback. Should be in range (0, 1). Default is .9.
t_offset – Offset time to add to the LFO time, in seconds. Default is 0.
t_offset_func – Optional function that returns a time by which to offset the LFO time (in addition to
t_offset). Defaults to a function that returns the current time, which makes the LFO phase consistent over time between runs.dry – Dry (input) signal level. 0 is none, 1 is unity. Default is .5.
wet – Wet (affected) signal level. 0 is none, 1 is unity. Default is .5.
- feedback: float
- get_wet_signal(audio: Audio) ndarray[source]
Returns the “wet” signal (i.e. signal with effect applied).
- max_delay: float
- min_delay: float
- rate: float
- t_offset: float
- t_offset_func: Callable[[], float] | None
voicebox.effects.glitch module
- class voicebox.effects.glitch.Glitch(chunk_time: float = 0.1, p_repeat: float = 0.07, max_repeats: int = 3, rng: Random = <factory>)[source]
Bases:
EffectCreates a glitchy sound by randomly repeating small chunks of audio.
- Parameters:
chunk_time – Length of each repeated chunk, in seconds.
p_repeat – Probability of repeating each chunk.
max_repeats – Maximum number of times to repeat each chunk.
rng – Random number generator to use. One will be constructed if not given.
- apply(audio: Audio) Audio[source]
Applies the effect to the audio signal.
May or may not return a new
Audioinstance.
- chunk_time: float = 0.1
- max_repeats: int = 3
- p_repeat: float = 0.07
- rng: Random
voicebox.effects.normalize module
- class voicebox.effects.normalize.Normalize(max_amplitude: float = 1.0, remove_dc_offset: bool = True)[source]
Bases:
EffectNormalizes audio such that any DC offset is removed and
max(abs(signal)) == max_amplitude(1.0by default).- apply(audio: Audio) Audio[source]
Applies the effect to the audio signal.
May or may not return a new
Audioinstance.
- max_amplitude: float = 1.0
- remove_dc_offset: bool = True
voicebox.effects.pedalboard module
- class voicebox.effects.pedalboard.PedalboardEffect(plugin: Plugin)[source]
Bases:
EffectWrapper around Pedalboard library plugins from Spotify.
See the Pedalboard library documentation for the full list of plugins: https://spotify.github.io/pedalboard/reference/pedalboard.html
Example
>>> from voicebox.effects import PedalboardEffect >>> import pedalboard >>> effects = [ >>> ..., >>> PedalboardEffect(pedalboard.Reverb()), >>> ]
- apply(audio: Audio) Audio[source]
Applies the effect to the audio signal.
May or may not return a new
Audioinstance.
- plugin: Plugin
- voicebox.effects.pedalboard.pedalboard_effects(*effects: Plugin) Sequence[PedalboardEffect][source]
Creates a sequence of PedalboardEffect objects from Pedalboard plugins.
Example
>>> from voicebox.effects import pedalboard_effects >>> import pedalboard >>> effects = pedalboard_effects( >>> pedalboard.Distortion(), >>> pedalboard.Reverb(), >>> )
voicebox.effects.ring_mod module
- class voicebox.effects.ring_mod.RingMod(carrier_freq: float = 20.0, carrier_wave: ~typing.Callable[[~numpy.ndarray], ~numpy.ndarray] = <ufunc 'sin'>, dry: float = 0.5, wet: float = 0.5)[source]
Bases:
EffectWithDryWetRing modulation effect.
Multiplies the audio signal by a carrier wave. Can be used to create choppy, Doctor Who Dalek-like effects at low carrier frequencies, or bell-like sounds at higher carrier frequencies.
- Parameters:
carrier_freq (float) – Carrier wave frequency in Hz.
carrier_wave – Carrier wave function. Defaults to
np.sin.dry – Dry (input) signal level. 0 is none, 1 is unity. Default is .5.
wet – Wet (affected) signal level. 0 is none, 1 is unity. Default is .5.
- carrier_freq: float = 20.0
- carrier_wave: Callable[[ndarray], ndarray] = <ufunc 'sin'>
voicebox.effects.tail module
- class voicebox.effects.tail.Tail(seconds: float = 1.0)[source]
Bases:
EffectAdds
secondsof silence to the end of the audio.This is useful for adding space between audio clips, or for allowing time-based effects (e.g. reverb) to decay naturally instead of being abruptly cut off.
- apply(audio: Audio) Audio[source]
Applies the effect to the audio signal.
May or may not return a new
Audioinstance.
- seconds: float = 1.0
voicebox.effects.utils module
voicebox.effects.vocoder module
- class voicebox.effects.vocoder.Vocoder(carrier_wave: Callable[[ndarray], ndarray], bandpass_filters: Sequence[Filter], envelope_follower: EnvelopeFollower, max_freq: float, dry: float, wet: float)[source]
Bases:
EffectWithDryWetVocoder effect. Useful for making monotone, robotic voices.
See
Vocoder.build()to easily construct a Vocoder instance.- classmethod build(carrier_freq: float = 160.0, carrier_wave_builder=<class 'voicebox.effects.vocoder.SawtoothWave'>, carrier_wave=None, min_freq: float = 80.0, max_freq: float = 8000.0, bands: int = 40, bandwidth: float = 0.8, bandpass_filter_order: int = 3, bandpass_filter_kwargs: Dict[str, ~typing.Any]=None, envelope_follower_freq: float = 50.0, envelope_follower_kwargs: Dict[str, ~typing.Any]=None, dry: float = 0.0, wet: float = 1.0) Vocoder[source]
Builds a Vocoder instance.
- Parameters:
carrier_freq (float) – Frequency of the carrier wave in Hz.
carrier_wave_builder – Defaults to
SawtoothWave.carrier_wave – Optional pre-built carrier wave. If provided, this will override
carrier_freqandcarrier_wave_builder.min_freq (float) – Minimum frequency of the bandpass filters in Hz.
max_freq (float) – Maximum frequency of the bandpass filters in Hz. Should be <= half the sample rate of the audio.
bands (int) – Number of bands to divide the frequency range into. More bands increases reconstruction quality.
bandwidth (float) – Bandwidth of each band, as a fraction of its maximum width. Range:
(0, 1].bandpass_filter_order (int) – Bandpass filter order. Higher orders have steeper rolloffs.
bandpass_filter_kwargs – Optional keyword arguments to pass to the bandpass filter builder.
envelope_follower_freq (float) – Cutoff frequency of the envelope follower in Hz.
envelope_follower_kwargs – Optional keyword arguments to pass to the envelope follower filter builder.
dry – Dry (input) signal level. 0 is none, 1 is unity.
wet – Wet (affected) signal level. 0 is none, 1 is unity.
- carrier_wave: Callable[[ndarray], ndarray]
Takes in an array of sample times and outputs corresponding wave samples.
- envelope_follower: EnvelopeFollower
- get_wet_signal(audio: Audio) ndarray[source]
Returns the “wet” signal (i.e. signal with effect applied).
- max_freq: float