recipes.cad1.task2.baseline.audio_manager module

A utility class for managing audio files.

class recipes.cad1.task2.baseline.audio_manager.AudioManager(sample_rate: int = 44100, output_audio_path: str | Path = '', soft_clip: bool = False)[source]

Bases: object

A utility class for managing audio files.

add_audios_to_save(file_name: str, waveform: ndarray) None[source]

Add a waveform to the list of audios to save.

Parameters:
  • file_name (str) – The name of the track.

  • waveform (np.ndarray) – The track to save.

clip_audio(signal: ndarray, min_val: float = -1, max_val: float = 1) tuple[int, ndarray][source]

Clip a WAV file to the given range.

Parameters:
  • signal (np.ndarray) – The WAV file to clip.

  • min_val (float) – The minimum value to clip to. Defaults to -1.

  • max_val (float) – The maximum value to clip to. Defaults to 1.

Returns:

Number of samples clipped and the clipped signal.

Return type:

Tuple[int, np.ndarray]

get_lufs_level(signal: ndarray) float[source]

Get the LUFS level of the signal.

Parameters:

signal (np.ndarray) – The signal to get the LUFS level of.

Returns:

The LUFS level of the signal.

Return type:

float

save_audios() None[source]

Save the audios to the given path.

Parameters:

output_audio_path (str) – The path to save the audios to.

scale_to_lufs(signal: ndarray, target_lufs: float) ndarray[source]

Scale the signal to the given LUFS level.

Parameters:
  • signal (np.ndarray) – The signal to scale.

  • target_lufs (float) – The target LUFS level.

Returns:

The scaled signal.

Return type:

np.ndarray