From a1370ea4620da58d8aa4b06c4a2d4e08d3eba8b1 Mon Sep 17 00:00:00 2001 From: Vadim Date: Wed, 1 Feb 2023 22:27:21 +0100 Subject: [PATCH] Added crepe model_capacity and step_size to Settings --- Settings.py | 3 +++ UltraSinger.py | 8 ++++---- moduls/Pitcher/pitcher.py | 8 ++++---- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/Settings.py b/Settings.py index 4c0a1ae..9ec03ba 100644 --- a/Settings.py +++ b/Settings.py @@ -8,4 +8,7 @@ class Settings: vosk_model_path = '' # "models/vosk-model-small-en-us-0.15" mono_audio_path = '' + crepe_model_capacity = 'tiny' # tiny|small|medium|large|full + crepe_step_size = 10 + diff --git a/UltraSinger.py b/UltraSinger.py index 0e9832d..4a56ca4 100644 --- a/UltraSinger.py +++ b/UltraSinger.py @@ -63,7 +63,7 @@ def pitch_each_chunk_with_crepe(directory): key=lambda x: int(x.split("_")[1])): filepath = os.path.join(directory, filename) # todo: stepsize = duration? then when shorter than "it" it should take the duration. Otherwise there a more notes - pitched_data = get_pitch_with_crepe_file(filepath, 10) + pitched_data = get_pitch_with_crepe_file(filepath, settings.crepe_step_size, settings.crepe_model_capacity) conf_f = get_frequency_with_high_confidence(pitched_data.frequencies, pitched_data.confidence) notes = convert_frequencies_to_notes(conf_f) @@ -204,7 +204,7 @@ def do_ultrastar_stuff(): # Pitch the audio # todo: chunk pitching as option? # midi_notes = pitch_each_chunk_with_crepe(chunk_folder_name) - pitched_data = get_pitch_with_crepe_file(settings.mono_audio_path, 10) + pitched_data = get_pitch_with_crepe_file(settings.mono_audio_path, settings.crepe_step_size, settings.crepe_model_capacity) midi_notes = create_midi_notes_from_pitched_data(ultrastar_class.startTimes, ultrastar_class.endTimes, pitched_data) ultrastar_note_numbers = convert_ultrastar_note_numbers(midi_notes) @@ -225,7 +225,7 @@ def do_ultrastar_stuff(): def plot(input_file, vosk_transcribed_data, midi_notes): - pitched_data = get_pitch_with_crepe_file(input_file, 10) + pitched_data = get_pitch_with_crepe_file(input_file, settings.crepe_step_size, settings.crepe_model_capacity) t, f, c = get_confidence(pitched_data, 0.4) plt.ylim(0, 600) @@ -261,7 +261,7 @@ def do_audio_stuff(): # Pitch detection # todo: chunk pitching as option? # midi_notes = pitch_each_chunk_with_crepe(chunk_folder_name) - pitched_data = get_pitch_with_crepe_file(output_mono_audio, 10) + pitched_data = get_pitch_with_crepe_file(output_mono_audio, settings.crepe_step_size, settings.crepe_model_capacity) start_times = [] end_times = [] diff --git a/moduls/Pitcher/pitcher.py b/moduls/Pitcher/pitcher.py index 0f74d32..8d43c7b 100644 --- a/moduls/Pitcher/pitcher.py +++ b/moduls/Pitcher/pitcher.py @@ -4,19 +4,19 @@ from moduls.Pitcher.pitched_data import PitchedData from scipy.io import wavfile -def get_pitch_with_crepe_file(filename, step_size): +def get_pitch_with_crepe_file(filename, step_size, model_capacity): sr, audio = wavfile.read(filename) pitched_data = PitchedData() - pitched_data.times, pitched_data.frequencies, pitched_data.confidence, activation = crepe.predict(audio, sr, 'tiny', + pitched_data.times, pitched_data.frequencies, pitched_data.confidence, activation = crepe.predict(audio, sr, model_capacity, step_size=step_size, viterbi=True) return pitched_data -def get_pitch_with_crepe(y, sr, step_size): +def get_pitch_with_crepe(y, sr, step_size, model_capacity): pitched_data = PitchedData() - pitched_data.times, pitched_data.frequencies, pitched_data.confidence, activation = crepe.predict(y, sr, 'tiny', step_size=step_size, + pitched_data.times, pitched_data.frequencies, pitched_data.confidence, activation = crepe.predict(y, sr, model_capacity, step_size=step_size, viterbi=True) return pitched_data