Skip to content

Instantly share code, notes, and snippets.

@yassineAlouini
Created December 17, 2023 16:30
Show Gist options
  • Save yassineAlouini/5a08be74d76be5c93bb98d29aa77cc4e to your computer and use it in GitHub Desktop.
Save yassineAlouini/5a08be74d76be5c93bb98d29aa77cc4e to your computer and use it in GitHub Desktop.
A short script to denoise the audio of a noisy video.
import soundfile as sf
import numpy as np
import librosa
import noisereduce as nr
# If you don't have the libraries above:
# pip install noisereduce librosa numpy soundfile
# Run ffmpeg first to extract the sound from the video
# ffmpeg -i 'noisy_video.mp4' -vn -acodec copy 'noisy_signal.aac'
def denoise_noisy_sound_in_video(input_path, output_path):
# sr is the sampling rate of the audio signal.
y, sr = librosa.load(input_path, sr=None)
reduced_noise_audio = nr.reduce_noise(y=y, sr=sr)
sf.write(output_path, reduced_noise_audio, sr)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment