Skip to content

Instantly share code, notes, and snippets.

@iCorv
Created October 3, 2021 13:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iCorv/5f3ae22587ddfa94fca51d02b85e25e1 to your computer and use it in GitHub Desktop.
Save iCorv/5f3ae22587ddfa94fca51d02b85e25e1 to your computer and use it in GitHub Desktop.
Wraps a SoxBindings transformation in such a way that it can be used inside a tf.data map call.
sox_effects = {
'compand': {},
'chorus': {},
'highpass': {'frequency': 100},
'lowpass': {'frequency': 8000},
'phaser': {},
'reverb': {}
}
def get_sox_effect(
effect_type: str,
effect_params: dict
) -> Callable[[tf.Tensor], np.ndarray]:
# this allows multi-threading envs
@sox.sox_context()
def sox_effect(y: tf.Tensor) -> np.ndarray:
y = y.numpy()
tfm = sox.Transformer()
getattr(tfm, effect_type)(**effect_params)
y_out = tfm.build_array(input_array=y,
sample_rate_in=SR)
return y_out
return sox_effect
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment