noise_reduction package
Contents
noise_reduction package#
Submodules#
noise_reduction.noise_reduction module#
- class noise_reduction.noise_reduction.DFN(target_directory: pathlib.Path, verbose: bool = True, silence_threshold: Optional[float] = None, pad: bool = True, atten_lim_db: Optional[int] = None, **kwargs)[source]#
Bases:
noise_reduction.noise_reduction.ReduceNoiseBase
- clean_audio(data: torch.Tensor) → torch.Tensor[source]#
Clean the audio from noise. Here you should implement the noise reduction algorithm.
- Parameters
data – The audio data to clean.
- Returns
The cleaned audio.
- class noise_reduction.noise_reduction.ReduceNoise(target_directory: pathlib.Path, verbose: bool = True, silence_threshold: Optional[float] = None, sample_rate: int = 16000, duration: Optional[int] = None, channel: Optional[int] = None)[source]#
Bases:
noise_reduction.noise_reduction.ReduceNoiseBase
- clean_audio(data: numpy.ndarray) → numpy.ndarray[source]#
Clean the audio from noise. Here you should implement the noise reduction algorithm.
- Parameters
data – The audio data to clean.
- Returns
The cleaned audio.
- class noise_reduction.noise_reduction.ReduceNoiseBase(target_directory: pathlib.Path, verbose: bool = True, silence_threshold: Optional[float] = None)[source]#
Bases:
object
Base class for noise reduction. This class is aimed to be inherited by specific noise reduction algorithms. You must implement the following methods: - clean_audio: The method to clean the audio, where the noise reduction algorithm is implemented. - save_audio: The method to save the audio to a file. - load_audio: The method to load the audio from a file.
After implementing the above methods, you can use the reduce_noise method to reduce noise from audio files.
- abstract clean_audio(data) → Union[numpy.ndarray, torch.Tensor][source]#
Clean the audio from noise. Here you should implement the noise reduction algorithm.
- Parameters
data – The audio data to clean.
- Returns
The cleaned audio.
- abstract load_audio(file: str) → Tuple[Union[numpy.ndarray, torch.Tensor], int][source]#
Load the audio from a file.
- Parameters
file – The file to load the audio from.
- Returns
A tuple of: - the audio data - the sample rate
- reduce_noise(audio_file: pathlib.Path) → Tuple[bool, Tuple[str, str]][source]#
Reduce noise from the given audio file.
- Parameters
audio_file – The audio file to reduce noise from.
- Returns
A tuple of: - a boolean indicating whether an error occurred - a tuple of:
audio file name
target path in case of success / error message in case of failure.
- remove_silence(audio: numpy.ndarray)[source]#
Remove silence sections from the audio.
- Parameters
audio – The audio to remove silence from.
- Returns
The audio without silence.
- noise_reduction.noise_reduction.reduce_noise(audio_source: str, target_directory: str, sample_rate: int = 16000, duration: Optional[int] = None, channel: Optional[int] = None, silence_threshold: Optional[float] = None, use_multiprocessing: int = 0, verbose: bool = True)[source]#
Reduce noise from audio file or directory containing audio files. The audio files must be in .wav format. The cleaned audio files will be saved in the target_directory. For information about the noise reduction algorithm see: https://github.com/timsainb/noisereduce Notice that the saved files are in wav format, even if the original files are in other format.
- Parameters
audio_source – path to audio file or directory containing audio files
target_directory – path to directory to save the cleaned audio files.
sample_rate – Number of samples in one second in the audio file. Pass None to keep the original sample rate.
duration – Duration of the audio file to clean in seconds. Pass None to keep the original duration.
channel – Channel to clean. Pass the number of the channel to clean. To clean all channels pass None.
silence_threshold – The threshold to remove silence from the audio, in dB. If None, no silence removal is performed.
use_multiprocessing – Number of processes to use for cleaning the audio files. If 0, no multiprocessing is used.
verbose – Verbosity level. If True, display progress bar.
- noise_reduction.noise_reduction.reduce_noise_dfn(audio_source: str, target_directory: str, pad: bool = True, atten_lim_db: Optional[int] = None, silence_threshold: Optional[float] = None, use_multiprocessing: int = 0, verbose: bool = True, **kwargs)[source]#
Reduce noise from audio files using DeepFilterNet. For more information about the noise reduction algorithm see: https://github.com/Rikorose/DeepFilterNet Notice that the saved files are in wav format, even if the original files are in other format.
- Parameters
audio_source – path to audio file or directory of audio files
target_directory – path to target directory to save cleaned audio files
pad – whether to pad the audio file with zeros before cleaning
atten_lim_db – maximum attenuation in dB
silence_threshold – the threshold to remove silence from the audio, in dB. If None, no silence removal is performed.
use_multiprocessing – Number of processes to use for cleaning the audio files. If 0, no multiprocessing is used.
verbose – verbosity level. If True, display progress bar and logs.
kwargs – additional arguments to pass to torchaudio.load(). For more information see: https://pytorch.org/audio/stable/generated/torchaudio.load.html