Created
October 14, 2020 19:32
-
-
Save mathigatti/63728cfffeec49c5c7c1fa70a73e89fa to your computer and use it in GitHub Desktop.
Short script for creating missing note samples detuning the ones you have.
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
!pip install librosa | |
import glob | |
import os | |
import librosa | |
def closest_sample(note, notes): | |
absolute_difference_function = lambda list_value : abs(list_value - note) | |
return min(notes, key=absolute_difference_function) | |
def detune(audio_file, semitone_steps, output_file): | |
y, sr = librosa.load(audio_file, sr=16000) | |
y_shifted = librosa.effects.pitch_shift(y, sr, n_steps=semitone_steps) | |
librosa.output.write_wav(output_file, y_shifted, sr) | |
def audio_file_name(note): | |
samples_folder = "samples" | |
return os.path.join(samples_folder,f"{note}.mp3") | |
notas_con_samples = [48,52,56,60,64] | |
for nota in range(48,65): | |
if not nota in notas_con_samples: | |
nota_mas_cercana = closest_sample(nota, notas_con_samples) | |
ruta_al_sample = audio_file_name(nota_mas_cercana) | |
detune(ruta_al_sample, nota - nota_mas_cercana, audio_file_name(nota)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment