Created
October 3, 2021 13:11
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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