mirror of
https://github.com/rakuri255/UltraSinger.git
synced 2026-11-28 01:48:56 +09:00
Fixed output folder path
Added some tags to ultrastar writer
This commit is contained in:
1 parent
a1370ea462
commit
c067cbba68
6 files changed
+60
-41
No files matched your search
+2
-1
@@ -4,7 +4,8 @@ class Settings:
|
||||
create_audio_chunks = False
|
||||
|
||||
input_file_path = ''
|
||||
audio_chunk_folder_name = 'output/audio-chunks'
|
||||
output_file_path = ''
|
||||
audio_chunk_folder_name = 'audio-chunks'
|
||||
vosk_model_path = '' # "models/vosk-model-small-en-us-0.15"
|
||||
mono_audio_path = ''
|
||||
|
||||
|
||||
+43
-31
@@ -187,40 +187,42 @@ def do_ultrastar_stuff():
|
||||
real_bpm = ultrastar_converter.ultrastar_bpm_to_real_bpm(float(ultrastar_class.bpm.replace(',', '.')))
|
||||
|
||||
# todo: duplicate code
|
||||
ultrastar_mp3_name = ultrastar_class.mp3
|
||||
basename_without_ext = os.path.splitext(ultrastar_mp3_name)[0]
|
||||
dirname = os.path.dirname(settings.input_file_path)
|
||||
settings.mono_audio_path = 'output/mono.wav'
|
||||
create_folder('output')
|
||||
convert_audio_to_mono_wav(dirname + '/' + ultrastar_class.mp3, settings.mono_audio_path)
|
||||
|
||||
# todo: input folder
|
||||
ultrastar_audio_input_path = 'input/' + ultrastar_class.mp3.replace('\n', '')
|
||||
ultrastar_audio_input_path = dirname + '/' + ultrastar_mp3_name
|
||||
song_output = settings.output_file_path + '/' + ultrastar_class.artist + ' - ' + ultrastar_class.title
|
||||
cache_path = song_output + '/cache'
|
||||
settings.mono_audio_path = cache_path + '/' + basename_without_ext + '.wav'
|
||||
create_folder(cache_path)
|
||||
convert_audio_to_mono_wav(ultrastar_audio_input_path, settings.mono_audio_path)
|
||||
|
||||
# todo: here we have to remove all silance, and dont need to store it!
|
||||
# ultrastar_class = remove_silence_from_ultrastar_data(ultrastar_audio_input_path, ultrastar_class)
|
||||
|
||||
if settings.create_audio_chunks:
|
||||
create_folder(settings.audio_chunk_folder_name)
|
||||
export_chunks_from_ultrastar_data(ultrastar_audio_input_path, ultrastar_class, settings.audio_chunk_folder_name)
|
||||
audio_chunks_path = cache_path + '/' + settings.audio_chunk_folder_name
|
||||
create_folder(audio_chunks_path)
|
||||
export_chunks_from_ultrastar_data(ultrastar_audio_input_path, ultrastar_class, audio_chunks_path)
|
||||
|
||||
# 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, settings.crepe_step_size, settings.crepe_model_capacity)
|
||||
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)
|
||||
|
||||
# Create new repitched ultrastar txt
|
||||
# todo: output
|
||||
output_repitched_ultrastar = 'output/ultrastar_repitch.txt'
|
||||
output_repitched_ultrastar = song_output + '/' + ultrastar_class.title + '.txt'
|
||||
ultrastar_writer.create_repitched_txt_from_ultrastar_data(settings.input_file_path, ultrastar_note_numbers,
|
||||
output_repitched_ultrastar)
|
||||
|
||||
if settings.create_midi:
|
||||
# todo: remove .txt
|
||||
voice_instrument = [midi_creator.convert_ultrastar_to_midi_instrument(ultrastar_class)]
|
||||
# todo: output
|
||||
midi_output = settings.input_file_path.replace('.txt', '.mid')
|
||||
midi_output = midi_output.replace('input', 'output')
|
||||
midi_output = song_output + '/' + ultrastar_class.title + '.mid'
|
||||
midi_creator.instruments_to_midi(voice_instrument, real_bpm, midi_output)
|
||||
|
||||
|
||||
@@ -240,18 +242,28 @@ def plot(input_file, vosk_transcribed_data, midi_notes):
|
||||
|
||||
|
||||
def do_audio_stuff():
|
||||
output_mono_audio = 'output/mono.wav'
|
||||
create_folder('output')
|
||||
basename = os.path.basename(settings.input_file_path)
|
||||
basename_without_ext = os.path.splitext(basename)[0]
|
||||
dirname = os.path.dirname(settings.input_file_path)
|
||||
|
||||
ultrastar_audio_input_path = dirname + '/' + basename
|
||||
song_output = settings.output_file_path + '/' + basename_without_ext
|
||||
cache_path = song_output + '/cache'
|
||||
settings.mono_audio_path = cache_path + '/' + basename_without_ext + '.wav'
|
||||
create_folder(cache_path)
|
||||
convert_audio_to_mono_wav(ultrastar_audio_input_path, settings.mono_audio_path)
|
||||
|
||||
# todo: different sample rates for different models
|
||||
convert_audio_to_mono_wav(settings.input_file_path, output_mono_audio)
|
||||
convert_audio_to_mono_wav(settings.input_file_path, settings.mono_audio_path)
|
||||
|
||||
# Audio transcription
|
||||
vosk_transcribed_data = transcribe_with_vosk(output_mono_audio, settings.audio_chunk_folder_name, settings.vosk_model_path)
|
||||
vosk_transcribed_data = transcribe_with_vosk(settings.mono_audio_path, settings.vosk_model_path)
|
||||
|
||||
if settings.create_audio_chunks:
|
||||
create_folder(settings.audio_chunk_folder_name)
|
||||
csv_filename = settings.audio_chunk_folder_name + "/_chunks.csv"
|
||||
export_chunks_from_vosk_data(output_mono_audio, vosk_transcribed_data, settings.audio_chunk_folder_name)
|
||||
audio_chunks_path = cache_path + '/' + settings.audio_chunk_folder_name
|
||||
create_folder(audio_chunks_path)
|
||||
csv_filename = audio_chunks_path + "/_chunks.csv"
|
||||
export_chunks_from_vosk_data(settings.mono_audio_path, vosk_transcribed_data, audio_chunks_path)
|
||||
export_vosk_data_to_csv(vosk_transcribed_data, csv_filename)
|
||||
|
||||
# todo: do we need to correct words?
|
||||
@@ -261,7 +273,8 @@ 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, settings.crepe_step_size, settings.crepe_model_capacity)
|
||||
pitched_data = get_pitch_with_crepe_file(settings.mono_audio_path, settings.crepe_step_size,
|
||||
settings.crepe_model_capacity)
|
||||
|
||||
start_times = []
|
||||
end_times = []
|
||||
@@ -277,19 +290,14 @@ def do_audio_stuff():
|
||||
|
||||
# Ultrastar txt creation
|
||||
real_bpm = get_bpm_from_file(settings.input_file_path)
|
||||
# todo: filename from audio / yt title
|
||||
ultrastar_file_output = 'output/ultrastar.txt'
|
||||
ultrastar_file_output = song_output + '/' + basename_without_ext + '.txt'
|
||||
ultrastar_writer.create_txt_from_transcription(vosk_transcribed_data, ultrastar_note_numbers, ultrastar_file_output,
|
||||
real_bpm)
|
||||
basename_without_ext, basename, real_bpm)
|
||||
|
||||
if settings.create_midi:
|
||||
ultrastar_class = ultrastar_parser.parse_ultrastar_txt(ultrastar_file_output)
|
||||
|
||||
# todo: remove .txt
|
||||
voice_instrument = [midi_creator.convert_ultrastar_to_midi_instrument(ultrastar_class)]
|
||||
# todo: output. remove file extansion
|
||||
midi_output = settings.input_file_path.replace('.wav', '.mid')
|
||||
midi_output = midi_output.replace('input', 'output')
|
||||
midi_output = song_output + '/' + ultrastar_class.title + '.mid'
|
||||
midi_creator.instruments_to_midi(voice_instrument, real_bpm, midi_output)
|
||||
|
||||
|
||||
@@ -310,10 +318,14 @@ def main(argv):
|
||||
elif opt in ("-i", "--ifile"):
|
||||
settings.input_file_path = arg
|
||||
elif opt in ("-o", "--ofile"):
|
||||
settings.audio_chunk_folder_name = arg
|
||||
settings.output_file_path = arg
|
||||
elif opt in ("-v"):
|
||||
settings.vosk_model_path = arg
|
||||
|
||||
if settings.output_file_path == '':
|
||||
dirname = os.path.dirname(settings.input_file_path)
|
||||
settings.output_file_path = dirname + '/output'
|
||||
|
||||
if ".txt" in settings.input_file_path:
|
||||
do_ultrastar_stuff()
|
||||
else:
|
||||
|
||||
@@ -23,7 +23,7 @@ def export_vosk_data_to_csv(vosk_transcribed_data, filename):
|
||||
vosk_transcribed_data[i].conf])
|
||||
|
||||
|
||||
def transcribe_with_vosk(audio_filename, folder_name, model_path):
|
||||
def transcribe_with_vosk(audio_filename, model_path):
|
||||
# Code from here: https://towardsdatascience.com/speech-recognition-with-timestamps-934ede4234b2
|
||||
print("Transcribing {} with vosk and model {}".format(audio_filename, model_path))
|
||||
|
||||
|
||||
@@ -16,13 +16,15 @@ def parse_ultrastar_txt(input_file):
|
||||
count += 1
|
||||
if line.startswith('#'):
|
||||
if line.startswith('#ARTIST'):
|
||||
ultrastar_class.artist = line.split(':')[1]
|
||||
ultrastar_class.artist = line.split(':')[1].replace('\n', '')
|
||||
elif line.startswith('#TITLE'):
|
||||
ultrastar_class.title = line.split(':')[1].replace('\n', '')
|
||||
elif line.startswith('#MP3'):
|
||||
ultrastar_class.mp3 = line.split(':')[1].replace('\n', '')
|
||||
elif line.startswith('#GAP'):
|
||||
ultrastar_class.gap = line.split(':')[1]
|
||||
ultrastar_class.gap = line.split(':')[1].replace('\n', '')
|
||||
elif line.startswith('#BPM'):
|
||||
ultrastar_class.bpm = line.split(':')[1]
|
||||
ultrastar_class.bpm = line.split(':')[1].replace('\n', '')
|
||||
elif line.startswith(':'):
|
||||
parts = line.split()
|
||||
# [0] :
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
class UltrastarTxt:
|
||||
artist = ''
|
||||
title = ''
|
||||
mp3 = ''
|
||||
gap = ''
|
||||
bpm = ''
|
||||
|
||||
@@ -2,7 +2,7 @@ from moduls.Ultrastar.ultrastar_converter import real_bpm_to_ultrastar_bpm, seco
|
||||
import re
|
||||
|
||||
|
||||
def create_txt_from_transcription(vosk_transcribed_data, note_numbers, ultrastar_file_output, bpm=120):
|
||||
def create_txt_from_transcription(vosk_transcribed_data, note_numbers, ultrastar_file_output, title, audio, bpm=120):
|
||||
print("Creating {} from transcription.".format(ultrastar_file_output))
|
||||
|
||||
# todo: Optimize multiplication
|
||||
@@ -11,10 +11,13 @@ def create_txt_from_transcription(vosk_transcribed_data, note_numbers, ultrastar
|
||||
gap = vosk_transcribed_data[0].start
|
||||
ultrastar_bpm = real_bpm_to_ultrastar_bpm(bpm) * multiplication
|
||||
|
||||
# todo: #MP3, #ARTIST, #TITLE
|
||||
f.write('#AUTHOR: UltraSinger' + '\n')
|
||||
f.write('#BPM: ' + str(ultrastar_bpm) + '\n') # not the real BPM!
|
||||
f.write('#GAP: ' + str(int(gap * 1000)) + '\n')
|
||||
f.write('#ARTIST:' + title + '\n')
|
||||
f.write('#TITLE:' + title + '\n')
|
||||
f.write('#CREATOR:UltraSinger' + '\n')
|
||||
f.write('#FIXER:YOUR NAME' + '\n')
|
||||
f.write('#MP3:' + audio + '\n')
|
||||
f.write('#BPM:' + str(ultrastar_bpm) + '\n') # not the real BPM!
|
||||
f.write('#GAP:' + str(int(gap * 1000)) + '\n')
|
||||
|
||||
# Write the singing part
|
||||
for i in range(len(vosk_transcribed_data)):
|
||||
|
||||
Reference in new issue
Block a user