Created
August 13, 2024 14:10
-
-
Save TheSirC/d7bc9a271410ba8c3e9112a37ab1f68b to your computer and use it in GitHub Desktop.
Wavetable script for M8 (not authour)
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
import librosa | |
import soundfile as sf | |
import os | |
# Define the folder path containing the .wav files | |
folder_path = "/path/to/folder" | |
# Iterate over all .wav files in the folder and subfolders | |
for root, dirs, files in os.walk(folder_path): | |
for file_name in files: | |
if file_name.endswith(".wav"): | |
# Load the audio file | |
audio_path = os.path.join(root, file_name) | |
audio, sr = librosa.load(audio_path, sr=None) | |
# Change the length of the audio file to N samples by padding the end with silence (N = 256 * the number of samples per wave). e.g. if 2048-samples per wave, then N = 524288 | |
target_length = 524288 # SET THIS ACCORDING TO THE FORMULA! | |
if len(audio) < target_length: | |
# If the audio file is shorter than 524288 samples, pad it with silence | |
audio = librosa.util.fix_length(audio, size=target_length) | |
# Save the modified audio file using soundfile | |
sf.write(audio_path, audio, sr) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment