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: Effect

Applies 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 Audio instance.

combine_func: Callable[[ndarray], ndarray]
dry_gain: float
effects: Sequence[Effect]
class voicebox.effects.chain.SeriesChain(*effects: Effect)[source]

Bases: Effect

Applies a chain of effects serially.

apply(audio: Audio) Audio[source]

Applies the effect to the audio signal.

May or may not return a new Audio instance.

effects: Sequence[Effect]

voicebox.effects.dc_offset module

class voicebox.effects.dc_offset.RemoveDcOffset[source]

Bases: Effect

Removes any DC offset from the audio signal by subtracting the mean.

apply(audio)[source]

Applies the effect to the audio signal.

May or may not return a new Audio instance.

voicebox.effects.effect module

class voicebox.effects.effect.Effect[source]

Bases: ABC

Base class for all effects.

abstractmethod apply(audio: Audio) Audio[source]

Applies the effect to the audio signal.

May or may not return a new Audio instance.

class voicebox.effects.effect.EffectWithDryWet(dry: float, wet: float)[source]

Bases: Effect, ABC

Base 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.

apply(audio: Audio) Audio[source]

Applies the effect to the audio signal.

May or may not return a new Audio instance.

abstractmethod get_wet_signal(audio: Audio) ndarray[source]

Returns the “wet” signal (i.e. signal with effect applied).

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 Audio instance.

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 the center_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

filter_param_builder: FilterParamBuilder
class voicebox.effects.eq.FilterParamBuilder[source]

Bases: object

abstractmethod build(sample_rate: float) ndarray[source]

Returns filter parameters in sos format.

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']
build(sample_rate: float) ndarray[source]

Returns filter parameters in sos format.

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.eq.center_to_band(freq: int | float, bandwidth: int | float) Tuple[int | float, int | float][source]

Converts a center frequency with bandwidth to a frequency band.

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: ~typing.Callable[[], float] | None = <built-in function monotonic>, dry: float = 0.5, wet: float = 0.5)[source]

Bases: EffectWithDryWet

Flanger 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.Random = <factory>)[source]

Bases: Effect

Creates 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 Audio instance.

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: Effect

Normalizes audio such that any DC offset is removed and max(abs(signal)) == max_amplitude (1.0 by default).

apply(audio: Audio) Audio[source]

Applies the effect to the audio signal.

May or may not return a new Audio instance.

max_amplitude: float = 1.0
remove_dc_offset: bool = True

voicebox.effects.pedalboard module

class voicebox.effects.pedalboard.PedalboardEffect(plugin: Plugin)[source]

Bases: Effect

Wrapper 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 Audio instance.

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: EffectWithDryWet

Ring 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'>
get_wet_signal(audio: Audio) ndarray[source]

Returns the “wet” signal (i.e. signal with effect applied).

voicebox.effects.tail module

class voicebox.effects.tail.Tail(seconds: float = 1.0)[source]

Bases: Effect

Adds seconds of 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 Audio instance.

seconds: float = 1.0

voicebox.effects.utils module

voicebox.effects.utils.db(db_: float) float[source]

Convert decibels to gain. Examples:

  • db(0) -> 1

  • db(-6) -> 0.501

  • db(+6) -> 1.995

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: EffectWithDryWet

Vocoder effect. Useful for making monotone, robotic voices.

See Vocoder.build() to easily construct a Vocoder instance.

bandpass_filters: Sequence[Filter]
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: ~typing.Dict[str, ~typing.Any] = None, envelope_follower_freq: float = 50.0, envelope_follower_kwargs: ~typing.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_freq and carrier_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

Module contents

voicebox.effects.default_effects() List[Effect][source]

Returns the default effects list, which is just [Normalize()].