Make an advanced audio enhancer in python that adds vocal cleaning, enhancements, and…
- User
Make an advanced audio enhancer in python that adds vocal cleaning, enhancements, and composer with smoothness.
Without spleeter.
- Assistant
Make an advanced audio enhancer in python that adds vocal cleaning, enhancements, and composer with smoothness.
Without spleeter.
Creating an advanced audio enhancer in Python involves several steps to clean and enhance vocals, as well as apply effects that contribute to the overall smoothness of the audio. Below is a comprehensive guide to building such an enhancer without using Spleeter. This implementation leverages various Python libraries for audio processing, including librosa, noisereduce, pydub, and scipy.
librosa and convert it to a suitable format for processing.Before diving into the code, ensure you have the following libraries installed. You can install them using pip:
pip install numpy librosa noisereduce pydub scipy
Note: Additionally, pydub requires ffmpeg to be installed on your system. You can download it from FFmpeg's official website and ensure it's added to your system's PATH.
import numpy as np
import librosa
import noisereduce as nr
from pydub import AudioSegment, effects
from scipy.signal import butter, lfilter
import scipy.io.wavfile as wav
import os
# Function to apply a bandpass filter
def bandpass_filter(data, lowcut, highcut, fs, order=4):
nyquist = 0.5 * fs
low = lowcut / nyquist
high = highcut / nyquist
b, a = butter(order, [low, high], btype='band')
y = lfilter(b, a, data)
return y
# Function to apply compression
def compress_audio(data, threshold=0.1, ratio=4.0, attack=0.01, release=0.1):
# Simple compressor implementation
compressor = effects.compress_dynamic_range(AudioSegment(
data.tobytes(),
frame_rate=fs,
sample_width=data.dtype.itemsize,
channels=1
), threshold=threshold * 32767, ratio=ratio, attack=attack*1000, release=release*1000)
return np.array(compressor.get_array_of_samples()).astype(np.float32) / 32767.0
# Load the audio file
input_path = 'input_audio.wav' # Replace with your input file path
output_path = 'enhanced_audio.wav' # Replace with your desired output file path
# Load audio with librosa
y, sr = librosa.load(input_path, sr=None, mono=True)
print(f"Original Audio: {y.shape[0]/sr:.2f} seconds, Sample Rate: {sr} Hz")
# Step 1: Noise Reduction
# Estimate noise from the first 0.5 seconds
noise_sample = y[:int(0.5 * sr)]
y_denoised = nr.reduce_noise(y=y, sr=sr, y_noise=noise_sample, prop_decrease=1.0)
print("Noise reduction applied.")
# Step 2: Equalization (Bandpass Filter to enhance vocal frequencies)
# Typical vocal range: 80 Hz to 300 Hz (male), 150 Hz to 400 Hz (female)
# We'll use a broader range for general purposes
y_eq = bandpass_filter(y_denoised, lowcut=80.0, highcut=4000.0, fs=sr, order=6)
print("Equalization (bandpass filter) applied.")
# Step 3: Compression
# Compress the dynamic range to make vocals more prominent
y_compressed = compress_audio(y_eq, threshold=0.1, ratio=4.0, attack=0.01, release=0.1)
print("Compression applied.")
# Step 4: Add Reverb for Smoothness
# Convert numpy array to AudioSegment
audio_segment = AudioSegment(
y_compressed.tobytes(),
frame_rate=sr,
sample_width=y_compressed.dtype.itemsize,
channels=1
)
# Apply reverb using pydub's built-in effects (simulate reverb with echo)
reverb = audio_segment.overlay(audio_segment, delay=50).overlay(audio_segment, delay=100)
print("Reverb applied for smoothness.")
# Optional: Stereo Enhancement
# Duplicate the mono track to make it stereo
reverb = reverb.set_channels(2)
print("Stereo enhancement applied.")
# Export the enhanced audio
reverb.export(output_path, format='wav')
print(f"Enhanced audio saved to {output_path}")
Loading the Audio:
librosa.load, which returns the audio time series (y) and the sample rate (sr).pydub to convert it.Noise Reduction:
noisereduce library reduces background noise using this noise profile.Equalization (Bandpass Filter):
lowcut and highcut based on the specific requirements of your audio.Compression:
threshold, ratio, attack, release) can be tweaked for desired effect.Reverb for Smoothness:
Stereo Enhancement:
Exporting the Enhanced Audio:
pydub.Adaptive Noise Reduction: Instead of using a fixed noise profile, implement adaptive noise reduction that continuously estimates and updates the noise profile.
Advanced Equalization: Use parametric equalizers to target specific frequencies more precisely.
Dynamic Effects: Implement dynamic effects such as sidechain compression to interact with other audio elements.
Machine Learning Enhancements: For more sophisticated vocal separation and enhancement, consider integrating machine learning models tailored for audio processing.
User Interface: Build a GUI using libraries like Tkinter or PyQt for easier interaction and real-time processing.
The provided Python script offers a foundation for building an advanced audio enhancer focusing on vocal cleaning and enhancement without relying on Spleeter. By combining noise reduction, equalization, compression, and reverb, you can significantly improve the quality and smoothness of audio recordings. Depending on your specific needs, further customization and enhancements can be incorporated to achieve even better results.
Not yet included in a published release.