From 48b4b8f483b31b723482480cafab5eaabc8eb3a1 Mon Sep 17 00:00:00 2001 From: TheZet Date: Sat, 14 Dec 2024 09:42:20 -0500 Subject: [PATCH 01/12] Quality of Life changes --- README.md | 22 ++++++---- src/UltraSinger.py | 80 ++++++++++++++++++++++++----------- src/modules/common_print.py | 24 ++++++----- src/modules/console_colors.py | 5 ++- 4 files changed, 86 insertions(+), 45 deletions(-) diff --git a/README.md b/README.md index d7b6595..65ff0ea 100644 --- a/README.md +++ b/README.md @@ -108,14 +108,19 @@ _Not all options working now!_ (-p Check pitch of Ultrastar.txt input) # In Progress (-m Create midi file) # In Progress + [separation] + # Default is htdemucs + --demucs Model name htdemucs|htdemucs_ft|htdemucs_6s|hdemucs_mmi|mdx|mdx_extra|mdx_q|mdx_extra_q >> ((default) is htdemucs) + [transcription] # Default is whisper - --whisper Multilingual model > tiny|base|small|medium|large-v1|large-v2 >> ((default) is large-v2 + --whisper Multilingual model > tiny|base|small|medium|large-v1|large-v2|large-v3 >> ((default) is large-v2 English-only model > tiny.en|base.en|small.en|medium.en --whisper_align_model Use other languages model for Whisper provided from huggingface.co --language Override the language detected by whisper, does not affect transcription but steps after transcription --whisper_batch_size Reduce if low on GPU mem >> ((default) is 16) --whisper_compute_type Change to "int8" if low on GPU mem (may reduce accuracy) >> ((default) is "float16" for cuda devices, "int8" for cpu) + --keep_numbers Numbers will be transcribed as numerics instead of as words >> True|False >> ((default) is False) [pitcher] # Default is crepe @@ -123,18 +128,17 @@ _Not all options working now!_ --crepe_step_size unit is miliseconds >> ((default) is 10) [extra] - --hyphenation True|False >> ((default) is True) - --disable_separation True|False >> ((default) is False) - --disable_karaoke True|False >> ((default) is False) - --ignore_audio True|False >> ((default) is False) - --create_audio_chunks True|False >> ((default) is False) - --keep_cache True|False >> ((default) is False) - --plot True|False >> ((default) is False) + --disable_hyphenation Disable word hyphenation. Hyphenation is enabled by default. + --disable_separation Disable track separation. Track separation is enabled by default. + --disable_karaoke Disable creation of karaoke style txt file. Karaoke is enabled by default. + --create_audio_chunks Enable creation of audio chunks. Audio chunks are disabled by default. + --keep_cache Keep cache folder after creation. Cache folder is removed by default. + --plot Enable creation of plots. Plots are disabled by default. --format_version 0.3.0|1.0.0|1.1.0 >> ((default) is 1.0.0) --musescore_path path to MuseScore executable [device] - --force_cpu True|False >> ((default) is False) All steps will be forced to cpu + --force_cpu Force all steps to be processed on CPU. --force_whisper_cpu True|False >> ((default) is False) Only whisper will be forced to cpu --force_crepe_cpu True|False >> ((default) is False) Only crepe will be forced to cpu ``` diff --git a/src/UltraSinger.py b/src/UltraSinger.py index 17ae768..97958a6 100644 --- a/src/UltraSinger.py +++ b/src/UltraSinger.py @@ -16,6 +16,8 @@ from modules.Audio.vocal_chunks import ( create_audio_chunks_from_ultrastar_data, ) from modules.Audio.silence_processing import remove_silence_from_transcription_data, mute_no_singing_parts +from modules.Speech_Recognition.Whisper import WhisperModel +from modules.Audio.separation import DemucsModel from modules.Audio.convert_audio import convert_audio_to_mono_wav, convert_wav_to_mp3 from modules.Audio.youtube import ( @@ -28,6 +30,8 @@ from modules.console_colors import ( gold_highlighted, red_highlighted, green_highlighted, + cyan_highlighted, + bright_green_highlighted, ) from modules.Midi.midi_creator import ( create_midi_segments_from_transcribed_data, @@ -131,7 +135,20 @@ def run() -> tuple[str, Score, Score]: """The processing function of this program""" #List selected options (can add more later) if settings.keep_numbers: - print(f"{ULTRASINGER_HEAD} {cyan_highlighted('Option:')} Numbers will be transcribed as numerics (i.e. 1, 2, 3, etc.)") + print(f"{ULTRASINGER_HEAD} {bright_green_highlighted('Option:')} {cyan_highlighted('Numbers will be transcribed as numerics (i.e. 1, 2, 3, etc.)')}") + if settings.create_plot: + print(f"{ULTRASINGER_HEAD} {bright_green_highlighted('Option:')} {cyan_highlighted('Plot will be created')}") + if settings.keep_cache: + print(f"{ULTRASINGER_HEAD} {bright_green_highlighted('Option:')} {cyan_highlighted('Cache folder will not be deleted')}") + if settings.create_audio_chunks: + print(f"{ULTRASINGER_HEAD} {bright_green_highlighted('Option:')} {cyan_highlighted('Audio chunks will be created')}") + if not settings.create_karaoke: + print(f"{ULTRASINGER_HEAD} {bright_green_highlighted('Option:')} {cyan_highlighted('Karaoke txt will not be created')}") + if not settings.use_separated_vocal: + print(f"{ULTRASINGER_HEAD} {bright_green_highlighted('Option:')} {cyan_highlighted('Vocals will not be separated')}") + if not settings.hyphenation: + print(f"{ULTRASINGER_HEAD} {bright_green_highlighted('Option:')} {cyan_highlighted('Hyphenation will not be applied')}") + process_data = InitProcessData() process_data.process_data_paths.cache_folder_path = ( @@ -139,7 +156,7 @@ def run() -> tuple[str, Score, Score]: if settings.cache_override_path is None else settings.cache_override_path ) - + # Create process audio process_data.process_data_paths.processing_audio_path = CreateProcessAudio(process_data) @@ -193,7 +210,7 @@ def run() -> tuple[str, Score, Score]: # Cleanup if not settings.keep_cache: remove_cache_folder(process_data.process_data_paths.cache_folder_path) - + # Print Support print_support() return ultrastar_file_output, simple_score, accurate_score @@ -599,7 +616,12 @@ def init_settings(argv: list[str]) -> Settings: settings.output_folder_path = arg elif opt in ("--whisper"): settings.transcriber = "whisper" - settings.whisper_model = arg + #Addition of whisper model choice. Added error handling for unknown models. + try: + settings.whisper_model = WhisperModel(arg) + except ValueError as ve: + print(f"The model {arg} is not a valid whisper model selection. Please use one of the following models: {blue_highlighted(', '.join([m.value for m in WhisperModel]))}") + sys.exit() elif opt in ("--whisper_align_model"): settings.whisper_align_model = arg elif opt in ("--whisper_batch_size"): @@ -607,7 +629,7 @@ def init_settings(argv: list[str]) -> Settings: elif opt in ("--whisper_compute_type"): settings.whisper_compute_type = arg elif opt in ("--keep_numbers"): - settings.keep_numbers = arg in ["True", "true"] + settings.keep_numbers = True elif opt in ("--language"): settings.language = arg elif opt in ("--crepe"): @@ -615,27 +637,27 @@ def init_settings(argv: list[str]) -> Settings: elif opt in ("--crepe_step_size"): settings.crepe_step_size = int(arg) elif opt in ("--plot"): - settings.create_plot = arg in ["True", "true"] + settings.create_plot = True elif opt in ("--midi"): - settings.create_midi = arg in ["True", "true"] - elif opt in ("--hyphenation"): - settings.hyphenation = eval(arg.title()) + settings.create_midi = True + elif opt in ("--disable_hyphenation"): + settings.hyphenation = False elif opt in ("--disable_separation"): - settings.use_separated_vocal = not arg + settings.use_separated_vocal = False elif opt in ("--disable_karaoke"): - settings.create_karaoke = not arg + settings.create_karaoke = False elif opt in ("--create_audio_chunks"): settings.create_audio_chunks = arg elif opt in ("--ignore_audio"): - settings.ignore_audio = arg in ["True", "true"] + settings.ignore_audio = True elif opt in ("--force_cpu"): - settings.force_cpu = arg + settings.force_cpu = True if settings.force_cpu: os.environ["CUDA_VISIBLE_DEVICES"] = "-1" elif opt in ("--force_whisper_cpu"): - settings.force_whisper_cpu = eval(arg.title()) + settings.force_whisper_cpu = True elif opt in ("--force_crepe_cpu"): - settings.force_crepe_cpu = eval(arg.title()) + settings.force_crepe_cpu = True elif opt in ("--format_version"): if arg == FormatVersion.V0_3_0.value: settings.format_version = FormatVersion.V0_3_0 @@ -648,10 +670,17 @@ def init_settings(argv: list[str]) -> Settings: f"{ULTRASINGER_HEAD} {red_highlighted('Error: Format version')} {blue_highlighted(arg)} {red_highlighted('is not supported.')}" ) sys.exit(1) - elif opt in ("--keep_cache"): - settings.keep_cache = arg + elif opt in ("--keep_cache"): + settings.keep_cache = True elif opt in ("--musescore_path"): settings.musescore_path = arg + #Addition of demucs model choice. Work seems to be needed to make sure syntax is same for models. Added error handling for unknown models + elif opt in ("--demucs"): + try: + settings.demucs_model = DemucsModel(arg) + except ValueError as ve: + print(f"The model {arg} is not a valid demucs model selection. Please use one of the following models: {blue_highlighted(', '.join([m.value for m in DemucsModel]))}") + sys.exit() if settings.output_folder_path == "": if settings.input_file_path.startswith("https:"): dirname = os.getcwd() @@ -665,6 +694,7 @@ def init_settings(argv: list[str]) -> Settings: return settings +#For convenience, made True/False options into noargs def arg_options(): short = "hi:o:amv:" long = [ @@ -680,18 +710,18 @@ def arg_options(): "language=", "plot=", "midi=", - "hyphenation=", - "disable_separation=", - "disable_karaoke=", - "create_audio_chunks=", + "disable_hyphenation", + "disable_separation", + "disable_karaoke", + "create_audio_chunks", "ignore_audio=", - "force_cpu=", - "force_whisper_cpu=", - "force_crepe_cpu=", + "force_cpu", + "force_whisper_cpu", + "force_crepe_cpu", "format_version=", "keep_cache", "musescore_path=", - "keep_numbers=" + "keep_numbers" ] return long, short diff --git a/src/modules/common_print.py b/src/modules/common_print.py index 568e150..a03d25a 100644 --- a/src/modules/common_print.py +++ b/src/modules/common_print.py @@ -31,9 +31,13 @@ def print_help() -> None: (-p Check pitch of Ultrastar.txt input) # In Progress (-m Create midi file) # In Progress + [separation] + # Default is htdemucs + --demucs Model name htdemucs|htdemucs_ft|htdemucs_6s|hdemucs_mmi|mdx|mdx_extra|mdx_q|mdx_extra_q >> ((default) is htdemucs) + [transcription] # Default is whisper - --whisper Multilingual model > tiny|base|small|medium|large-v1|large-v2 >> ((default) is large-v2 + --whisper Multilingual model > tiny|base|small|medium|large-v1|large-v2|large-v3 >> ((default) is large-v2 English-only model > tiny.en|base.en|small.en|medium.en --whisper_align_model Use other languages model for Whisper provided from huggingface.co --language Override the language detected by whisper, does not affect transcription but steps after transcription @@ -47,19 +51,19 @@ def print_help() -> None: --crepe_step_size unit is miliseconds >> ((default) is 10) [extra] - --hyphenation True|False >> ((default) is True) - --disable_separation True|False >> ((default) is False) - --disable_karaoke True|False >> ((default) is False) - --create_audio_chunks True|False >> ((default) is False) - --keep_cache True|False >> ((default) is False) - --plot True|False >> ((default) is False) + --disable_hyphenation Disable word hyphenation. Hyphenation is enabled by default. + --disable_separation Disable track separation. Track separation is enabled by default. + --disable_karaoke Disable creation of karaoke style txt file. Karaoke is enabled by default. + --create_audio_chunks Enable creation of audio chunks. Audio chunks are disabled by default. + --keep_cache Keep cache folder after creation. Cache folder is removed by default. + --plot Enable creation of plots. Plots are disabled by default. --format_version 0.3.0|1.0.0|1.1.0 >> ((default) is 1.0.0) --musescore_path path to MuseScore executable [device] - --force_cpu True|False >> ((default) is False) All steps will be forced to cpu - --force_whisper_cpu True|False >> ((default) is False) Only whisper will be forced to cpu - --force_crepe_cpu True|False >> ((default) is False) Only crepe will be forced to cpu + --force_cpu Force all steps to be processed on CPU. + --force_whisper_cpu Force whisper transcription to be processed on CPU. + --force_crepe_cpu Force crepe pitch detection to be processed on CPU. """ print(help_string) diff --git a/src/modules/console_colors.py b/src/modules/console_colors.py index 59328ff..1b674c2 100644 --- a/src/modules/console_colors.py +++ b/src/modules/console_colors.py @@ -32,11 +32,13 @@ def red_highlighted(text: str) -> str: """Returns a red highlighted text""" return f"{Bcolors.red}{text}{Bcolors.endc}" - def cyan_highlighted(text: str) -> str: """Returns a cyan highlighted text""" return f"{Bcolors.cyan}{text}{Bcolors.endc}" +def bright_green_highlighted(text: str) -> str: + """Returns a cyan highlighted text""" + return f"{Bcolors.bright_green}{text}{Bcolors.endc}" class Bcolors: """Colors for the console""" @@ -49,3 +51,4 @@ class Bcolors: gold = "\033[93m" underline = "\033[4m" endc = "\033[0m" + bright_green = "\033[38;2;204;255;204m" From 6389dd8f49cb8b4c8e1b704b3157786db1264047 Mon Sep 17 00:00:00 2001 From: TheZet Date: Thu, 19 Dec 2024 18:50:43 -0500 Subject: [PATCH 02/12] Fixed model message --- src/UltraSinger.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/UltraSinger.py b/src/UltraSinger.py index 97958a6..3eebe80 100644 --- a/src/UltraSinger.py +++ b/src/UltraSinger.py @@ -620,7 +620,7 @@ def init_settings(argv: list[str]) -> Settings: try: settings.whisper_model = WhisperModel(arg) except ValueError as ve: - print(f"The model {arg} is not a valid whisper model selection. Please use one of the following models: {blue_highlighted(', '.join([m.value for m in WhisperModel]))}") + print(f"{ULTRASINGER_HEAD} The model {arg} is not a valid whisper model selection. Please use one of the following models: {blue_highlighted(', '.join([m.value for m in WhisperModel]))}") sys.exit() elif opt in ("--whisper_align_model"): settings.whisper_align_model = arg @@ -679,7 +679,7 @@ def init_settings(argv: list[str]) -> Settings: try: settings.demucs_model = DemucsModel(arg) except ValueError as ve: - print(f"The model {arg} is not a valid demucs model selection. Please use one of the following models: {blue_highlighted(', '.join([m.value for m in DemucsModel]))}") + print(f"{ULTRASINGER_HEAD} The model {arg} is not a valid demucs model selection. Please use one of the following models: {blue_highlighted(', '.join([m.value for m in DemucsModel]))}") sys.exit() if settings.output_folder_path == "": if settings.input_file_path.startswith("https:"): From 4beb2ed430eda10414869efa42fcc3bb40d4417b Mon Sep 17 00:00:00 2001 From: TheZet Date: Thu, 19 Dec 2024 18:55:47 -0500 Subject: [PATCH 03/12] updated readme --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 65ff0ea..9d9e552 100644 --- a/README.md +++ b/README.md @@ -114,13 +114,13 @@ _Not all options working now!_ [transcription] # Default is whisper - --whisper Multilingual model > tiny|base|small|medium|large-v1|large-v2|large-v3 >> ((default) is large-v2 + --whisper Multilingual model > tiny|base|small|medium|large-v1|large-v2|large-v3 >> ((default) is large-v2) English-only model > tiny.en|base.en|small.en|medium.en --whisper_align_model Use other languages model for Whisper provided from huggingface.co --language Override the language detected by whisper, does not affect transcription but steps after transcription --whisper_batch_size Reduce if low on GPU mem >> ((default) is 16) --whisper_compute_type Change to "int8" if low on GPU mem (may reduce accuracy) >> ((default) is "float16" for cuda devices, "int8" for cpu) - --keep_numbers Numbers will be transcribed as numerics instead of as words >> True|False >> ((default) is False) + --keep_numbers Numbers will be transcribed as numerics instead of as words >> ((default) is False) [pitcher] # Default is crepe @@ -139,8 +139,8 @@ _Not all options working now!_ [device] --force_cpu Force all steps to be processed on CPU. - --force_whisper_cpu True|False >> ((default) is False) Only whisper will be forced to cpu - --force_crepe_cpu True|False >> ((default) is False) Only crepe will be forced to cpu + --force_whisper_cpu Only whisper will be forced to cpu + --force_crepe_cpu Only crepe will be forced to cpu ``` For standard use, you only need to use [opt]. All other options are optional. From 302b1bcd172547458572c2c94584c0a5d7f1646a Mon Sep 17 00:00:00 2001 From: TheZet Date: Thu, 19 Dec 2024 19:21:49 -0500 Subject: [PATCH 04/12] MonkeyPatch FasterWhisperPipeline to detect low confidence --- src/Settings.py | 2 +- src/modules/Speech_Recognition/Whisper.py | 57 +++++++++++++++++++++-- 2 files changed, 55 insertions(+), 4 deletions(-) diff --git a/src/Settings.py b/src/Settings.py index 2c9e68f..ff53ccc 100644 --- a/src/Settings.py +++ b/src/Settings.py @@ -11,7 +11,7 @@ from modules.Ultrastar.ultrastar_txt import FormatVersion @dataclass class Settings: APP_VERSION = "0.0.12" - + CONFIDENCE_THRESHOLD = 0.6 create_midi = True create_plot = False create_audio_chunks = False diff --git a/src/modules/Speech_Recognition/Whisper.py b/src/modules/Speech_Recognition/Whisper.py index 7778fef..11806cd 100644 --- a/src/modules/Speech_Recognition/Whisper.py +++ b/src/modules/Speech_Recognition/Whisper.py @@ -1,7 +1,6 @@ """Whisper Speech Recognition Module""" - -import sys - +import inspect +import textwrap import torch import whisperx from enum import Enum @@ -52,6 +51,24 @@ def number_to_words(line,language='en'): out_tokens.append(token) return ''.join(out_tokens) +def replace_code_lines(source, start_token, end_token, + replacement, escape_tokens=True): + """Replace the source code between `start_token` and `end_token` + in `source` with `replacement`. The `start_token` portion is included + in the replaced code. If `escape_tokens` is True (default), + escape the tokens to avoid them being treated as a regular expression.""" + + if escape_tokens: + start_token = re.escape(start_token) + end_token = re.escape(end_token) + + def replace_with_indent(match): + indent = match.group(1) + return textwrap.indent(replacement, indent) + + return re.sub(r"^(\s+)({}[\s\S]+?)(?=^\1{})".format(start_token, end_token), + replace_with_indent, source, flags=re.MULTILINE) + def transcribe_with_whisper( audio_path: str, model: WhisperModel, @@ -63,6 +80,40 @@ def transcribe_with_whisper( keep_numbers: bool = False, ) -> TranscriptionResult: """Transcribe with whisper""" + # Info: Monkey Patch FasterWhisperPipeline.detect_language to include error handling for low confidence Test with https://www.youtube.com/watch?v=tcV7VN3l3bY + src = textwrap.dedent(inspect.getsource(whisperx.asr.FasterWhisperPipeline.detect_language)) + # Replace the relevant part of the method + start_token = "if audio.shape[0] < N_SAMPLES:" + end_token = "return language" + replacement = """\ + #Added imports + from modules.console_colors import ULTRASINGER_HEAD, blue_highlighted, red_highlighted + from Settings import Settings + #End Import addition + if audio.shape[0] < N_SAMPLES: + print("Warning: audio is shorter than 30s, language detection may be inaccurate.") + model_n_mels = self.model.feat_kwargs.get("feature_size") + segment = log_mel_spectrogram(audio[: N_SAMPLES], + n_mels=model_n_mels if model_n_mels is not None else 80, + padding=0 if audio.shape[0] >= N_SAMPLES else N_SAMPLES - audio.shape[0]) + encoder_output = self.model.encode(segment) + results = self.model.model.detect_language(encoder_output) + language_token, language_probability = results[0][0] + language = language_token[2:-2] + print(f"Detected language: {language} ({language_probability:.2f}) in first 30s of audio...") + #Added handling for low detection probability (test with https://www.youtube.com/watch?v=tcV7VN3l3bY) + if language_probability < Settings.CONFIDENCE_THRESHOLD: + print(f"{ULTRASINGER_HEAD} {red_highlighted('Warning:')} Language detection probability for detected language {language} is below {Settings.CONFIDENCE_THRESHOLD}, results may be inaccurate.") + language_response = input(f"{ULTRASINGER_HEAD} Do you want to continue with {language} (default) or override with another language (y)? (y/n): ").strip().lower() == 'y' + if language_response: + language = input(f"{ULTRASINGER_HEAD} Please enter the language code for the language you want to use (e.g. 'en', 'de', 'es', etc.): ").strip().lower() + #End addition + """ + new_src = replace_code_lines(src, start_token, end_token, replacement) + # Compile it and execute it in the target module's namespace + exec(compile(new_src, "", "exec"), whisperx.asr.__dict__) + whisperx.asr.FasterWhisperPipeline.detect_language = whisperx.asr.detect_language + #End Monkey Patch # Info: Regardless of the audio sampling rate used in the original audio file, whisper resample the audio signal to 16kHz (via ffmpeg). So the standard input from (44.1 or 48 kHz) should work. From e623ea254a9ea0c661ca4baa9137485c68a91886 Mon Sep 17 00:00:00 2001 From: TheZet Date: Sun, 22 Dec 2024 09:04:41 -0500 Subject: [PATCH 05/12] Addressed PR Comments --- requirements.in | 3 ++- requirements.txt | 6 +++++- src/Settings.py | 3 ++- src/modules/Speech_Recognition/Whisper.py | 25 ++++++++++++++++++++--- 4 files changed, 31 insertions(+), 6 deletions(-) diff --git a/requirements.in b/requirements.in index d89ff24..618ba4d 100644 --- a/requirements.in +++ b/requirements.in @@ -30,4 +30,5 @@ music21 unidecode dataclasses dataclasses_json -num2words \ No newline at end of file +num2words +inputimeout \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 2107d5d..3397548 100644 --- a/requirements.txt +++ b/requirements.txt @@ -71,7 +71,9 @@ contourpy==1.2.1 crepe==0.0.15 # via -r requirements.in ctranslate2==4.4.0 - # via faster-whisper + # via + # faster-whisper + # whisperx cycler==0.12.1 # via matplotlib dataclasses==0.6 @@ -166,6 +168,8 @@ imageio==2.34.2 # via crepe iniconfig==2.0.0 # via pytest +inputimeout==1.0.4 + # via -r requirements.in isort==5.13.2 # via # -r requirements.in diff --git a/src/Settings.py b/src/Settings.py index ff53ccc..9a68acf 100644 --- a/src/Settings.py +++ b/src/Settings.py @@ -10,8 +10,9 @@ from modules.Ultrastar.ultrastar_txt import FormatVersion @dataclass_json @dataclass class Settings: - APP_VERSION = "0.0.12" + APP_VERSION = "0.0.13-dev1" CONFIDENCE_THRESHOLD = 0.6 + CONFIDENCE_PROMPT_TIMEOUT = 4 create_midi = True create_plot = False create_audio_chunks = False diff --git a/src/modules/Speech_Recognition/Whisper.py b/src/modules/Speech_Recognition/Whisper.py index 11806cd..7896134 100644 --- a/src/modules/Speech_Recognition/Whisper.py +++ b/src/modules/Speech_Recognition/Whisper.py @@ -80,7 +80,7 @@ def transcribe_with_whisper( keep_numbers: bool = False, ) -> TranscriptionResult: """Transcribe with whisper""" - # Info: Monkey Patch FasterWhisperPipeline.detect_language to include error handling for low confidence Test with https://www.youtube.com/watch?v=tcV7VN3l3bY + # Info: Monkey Patch FasterWhisperPipeline.detect_language to include error handling for low confidence src = textwrap.dedent(inspect.getsource(whisperx.asr.FasterWhisperPipeline.detect_language)) # Replace the relevant part of the method start_token = "if audio.shape[0] < N_SAMPLES:" @@ -89,6 +89,7 @@ def transcribe_with_whisper( #Added imports from modules.console_colors import ULTRASINGER_HEAD, blue_highlighted, red_highlighted from Settings import Settings + from inputimeout import inputimeout, TimeoutOccurred #End Import addition if audio.shape[0] < N_SAMPLES: print("Warning: audio is shorter than 30s, language detection may be inaccurate.") @@ -101,10 +102,28 @@ def transcribe_with_whisper( language_token, language_probability = results[0][0] language = language_token[2:-2] print(f"Detected language: {language} ({language_probability:.2f}) in first 30s of audio...") - #Added handling for low detection probability (test with https://www.youtube.com/watch?v=tcV7VN3l3bY) + #Added handling for low detection probability if language_probability < Settings.CONFIDENCE_THRESHOLD: print(f"{ULTRASINGER_HEAD} {red_highlighted('Warning:')} Language detection probability for detected language {language} is below {Settings.CONFIDENCE_THRESHOLD}, results may be inaccurate.") - language_response = input(f"{ULTRASINGER_HEAD} Do you want to continue with {language} (default) or override with another language (y)? (y/n): ").strip().lower() == 'y' + print(f"{ULTRASINGER_HEAD} Override the language below or re-run with parameter {blue_highlighted('--language xx')} to specify the song language...") + try: + response = inputimeout( + prompt=f"{ULTRASINGER_HEAD} Do you want to continue with {language} (default) or override with another language (y)? (y/n): ", + timeout=Settings.CONFIDENCE_PROMPT_TIMEOUT + ).strip().lower() + except TimeoutOccurred: + import locale + print(f"{ULTRASINGER_HEAD} No user input received in {Settings.CONFIDENCE_PROMPT_TIMEOUT} seconds. Attempting automatic override with system locale.") + print(f"{ULTRASINGER_HEAD} Trying to get language from default locale...") + current_locale = locale.getlocale() + if current_locale[0]: + language_code = current_locale[0][:2].strip().lower() + print(f"{ULTRASINGER_HEAD} Found language code: {language_code} in locale. Setting language to {blue_highlighted(language_code)}...") + language = language_code + else: + print(f"{ULTRASINGER_HEAD} No locale is set.") + response = 'n' + language_response = response == 'y' if language_response: language = input(f"{ULTRASINGER_HEAD} Please enter the language code for the language you want to use (e.g. 'en', 'de', 'es', etc.): ").strip().lower() #End addition From 3a382bd32d66f216df1c32a1e8c7811b1b0a5181 Mon Sep 17 00:00:00 2001 From: TheZet Date: Sun, 22 Dec 2024 09:14:59 -0500 Subject: [PATCH 06/12] fixed README --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index b7b2b15..18248c3 100644 --- a/README.md +++ b/README.md @@ -131,7 +131,7 @@ _Not all options working now!_ --plot Enable creation of plots. Plots are disabled by default. --format_version 0.3.0|1.0.0|1.1.0|1.2.0 >> ((default) is 1.2.0) --musescore_path path to MuseScore executable - --keep_numbers Transcribe numbers as digits and not words > True|False >> ((default) is False) + --keep_numbers Transcribe numbers as digits and not words [yt-dlp] --cookiefile File name where cookies should be read from @@ -201,10 +201,10 @@ Example for romanian: Is on by default. Can also be deactivated if hyphenation does not produce anything useful. Note that the word is simply split, without paying attention to whether the separated word really -starts at the place or is heard. +starts at the place or is heard. To disable: ```commandline --i XYZ --hyphenation True +-i XYZ --disable_hyphenation ``` ### 👂 Pitcher @@ -224,7 +224,7 @@ The vocals are separated from the audio before they are passed to the models. If you have the option to disable this function; in which case the original audio file is used instead. ```commandline --i XYZ --disable_separation True +-i XYZ --disable_separation ``` ### Sheet Music From 4f9fc87880682ba03dd6a97204f0dbaecc6f97ee Mon Sep 17 00:00:00 2001 From: TheZet Date: Sun, 22 Dec 2024 09:18:17 -0500 Subject: [PATCH 07/12] Fixed README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 18248c3..44e59e8 100644 --- a/README.md +++ b/README.md @@ -115,7 +115,7 @@ _Not all options working now!_ --language Override the language detected by whisper, does not affect transcription but steps after transcription --whisper_batch_size Reduce if low on GPU mem >> ((default) is 16) --whisper_compute_type Change to "int8" if low on GPU mem (may reduce accuracy) >> ((default) is "float16" for cuda devices, "int8" for cpu) - --keep_numbers Numbers will be transcribed as numerics instead of as words >> ((default) is False) + --keep_numbers Numbers will be transcribed as numerics instead of as words [pitcher] # Default is crepe From 8df2d954361e188dffbcc95f7fd5dfa051348309 Mon Sep 17 00:00:00 2001 From: TheZet Date: Mon, 23 Dec 2024 09:25:04 -0500 Subject: [PATCH 08/12] Fix musicbrainz_client.py for issue #202 --- src/modules/musicbrainz_client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/musicbrainz_client.py b/src/modules/musicbrainz_client.py index f945aa7..c3c04fb 100644 --- a/src/modules/musicbrainz_client.py +++ b/src/modules/musicbrainz_client.py @@ -3,7 +3,7 @@ import string from Levenshtein import ratio from dataclasses import dataclass from typing import Optional -from src.Settings import Settings +from Settings import Settings from modules.console_colors import ULTRASINGER_HEAD, blue_highlighted, red_highlighted From 108c84c4b073e48ab2724a20a885264738bad5e0 Mon Sep 17 00:00:00 2001 From: Vadim Date: Mon, 23 Dec 2024 22:34:32 +0100 Subject: [PATCH 09/12] Added colab --- README.md | 5 +++-- colab/UltraSinger.ipynb | 48 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 colab/UltraSinger.ipynb diff --git a/README.md b/README.md index f23f814..4b667b4 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,10 @@ [![Discord](https://img.shields.io/discord/1048892118732656731?logo=discord)](https://discord.gg/rYz9wsxYYK) +[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/rakuri255/UltraSinger/blob/master/colab/UltraSinger.ipynb) ![Status](https://img.shields.io/badge/status-development-yellow) + ![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/rakuri255/UltraSinger/main.yml) [![GitHub](https://img.shields.io/github/license/rakuri255/UltraSinger)](https://github.com/rakuri255/UltraSinger/blob/main/LICENSE) [![CodeFactor](https://www.codefactor.io/repository/github/rakuri255/ultrasinger/badge)](https://www.codefactor.io/repository/github/rakuri255/ultrasinger) - [![Check Requirements](https://github.com/rakuri255/UltraSinger/actions/workflows/main.yml/badge.svg)](https://github.com/rakuri255/UltraSinger/actions/workflows/main.yml) [![Pytest](https://github.com/rakuri255/UltraSinger/actions/workflows/pytest.yml/badge.svg)](https://github.com/rakuri255/UltraSinger/actions/workflows/pytest.yml) [![docker](https://github.com/rakuri255/UltraSinger/actions/workflows/docker.yml/badge.svg)](https://hub.docker.com/r/rakuri255/ultrasinger) @@ -157,7 +158,7 @@ For standard use, you only need to use [opt]. All other options are optional. ##### Youtube ```commandline --i https://www.youtube.com/watch?v=BaW_jenozKc +-i https://www.youtube.com/watch?v=YwNs1Z0qRY0 ``` Note that if you run into a yt-dlp error such as `Sign in to confirm you’re not a bot. This helps protect our community` ([yt-dlp issue](https://github.com/yt-dlp/yt-dlp/issues/10128)) you can follow these steps: diff --git a/colab/UltraSinger.ipynb b/colab/UltraSinger.ipynb new file mode 100644 index 0000000..398d00a --- /dev/null +++ b/colab/UltraSinger.ipynb @@ -0,0 +1,48 @@ +{ + "nbformat": 4, + "nbformat_minor": 0, + "metadata": { + "colab": { + "provenance": [], + "gpuType": "T4" + }, + "kernelspec": { + "name": "python3", + "display_name": "Python 3" + }, + "language_info": { + "name": "python" + }, + "accelerator": "GPU" + }, + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "Hki_kX_kSbZX" + }, + "outputs": [], + "source": [ + "%cd /content\n", + "!git clone https://github.com/rakuri255/UltraSinger.git\n", + "%cd /content/UltraSinger\n", + "!pip install --no-cache-dir -r requirements.txt\n", + "!pip install --no-cache-dir torch==2.3.0 torchvision==0.18.0 torchaudio==2.3.0 --index-url https://download.pytorch.org/whl/cu121\n", + "!pip install --no-cache-dir tensorflow[and-cuda]==2.17.1\n", + "%cd /content/UltraSinger/src" + ] + }, + { + "cell_type": "code", + "source": [ + "!python UltraSinger.py -i https://www.youtube.com/watch?v=YwNs1Z0qRY0 -o /content/output" + ], + "metadata": { + "id": "O0j4vUW0YAG2" + }, + "execution_count": null, + "outputs": [] + } + ] +} \ No newline at end of file From a499f9fcf2b20d32db02aec695c547386187711e Mon Sep 17 00:00:00 2001 From: Vadim Date: Mon, 23 Dec 2024 22:43:35 +0100 Subject: [PATCH 10/12] Bump to 0.0.13dev2 --- ReleaseNotes.md | 6 +++++- src/Settings.py | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/ReleaseNotes.md b/ReleaseNotes.md index 116a635..2a7e9eb 100644 --- a/ReleaseNotes.md +++ b/ReleaseNotes.md @@ -1,8 +1,12 @@ -# Version: 0.0.13dev1 +# Version: 0.0.13dev2 Date: 2024.12.22 - Changes: - Download Cover from MusicBrainz - Fix selection of whisper model + - Added colab notebook + - Optimized whisper language check with confidence + - Improved arguments, so you dont need to use true or false + - Added interactive mode # Version: 0.0.12 Date: 2024.12.19 diff --git a/src/Settings.py b/src/Settings.py index 0721f13..6772d3c 100644 --- a/src/Settings.py +++ b/src/Settings.py @@ -10,7 +10,7 @@ from modules.Ultrastar.ultrastar_txt import FormatVersion @dataclass_json @dataclass class Settings: - APP_VERSION = "0.0.13-dev1" + APP_VERSION = "0.0.13-dev2" CONFIDENCE_THRESHOLD = 0.6 CONFIDENCE_PROMPT_TIMEOUT = 4 From 72963982885d8bd9f201b1fd2af5fc67a923a8eb Mon Sep 17 00:00:00 2001 From: TheZet Date: Mon, 23 Dec 2024 20:01:46 -0500 Subject: [PATCH 11/12] Installer Fix --- install/CPU/windows_cpu.bat | 6 +++--- install/CUDA/windows_cuda_gpu.bat | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/install/CPU/windows_cpu.bat b/install/CPU/windows_cpu.bat index 37751bb..18c43b8 100644 --- a/install/CPU/windows_cpu.bat +++ b/install/CPU/windows_cpu.bat @@ -2,6 +2,6 @@ cd .. cd .. py -3.10 -m venv .venv -call .venv\Scripts\activate -pip install -r requirements.txt -pip install torch==2.0.1 torchvision==0.15.2 torchaudio==2.0.2 +SET VenvPythonPath=%CD%\.venv\Scripts\python.exe +call %VenvPythonPath% -m pip install -r requirements.txt +call %VenvPythonPath% -m pip install torch==2.0.1 torchvision==0.15.2 torchaudio==2.0.2 diff --git a/install/CUDA/windows_cuda_gpu.bat b/install/CUDA/windows_cuda_gpu.bat index ea3f987..1f8e7a5 100644 --- a/install/CUDA/windows_cuda_gpu.bat +++ b/install/CUDA/windows_cuda_gpu.bat @@ -2,6 +2,6 @@ cd .. cd .. py -3.10 -m venv .venv -call .venv\Scripts\activate -pip install -r requirements.txt -pip install torch==2.0.1+cu117 torchvision==0.15.2+cu117 torchaudio==2.0.2+cu117 --index-url https://download.pytorch.org/whl/cu117 \ No newline at end of file +SET VenvPythonPath=%CD%\.venv\Scripts\python.exe +call %VenvPythonPath% -m pip install -r requirements.txt +call %VenvPythonPath% -m pip install torch==2.0.1+cu117 torchvision==0.15.2+cu117 torchaudio==2.0.2+cu117 --index-url https://download.pytorch.org/whl/cu117 \ No newline at end of file From 20499960c197190e02b793f3fe52b06f4422e68d Mon Sep 17 00:00:00 2001 From: TheZet Date: Wed, 25 Dec 2024 09:18:58 -0500 Subject: [PATCH 12/12] Added setlocal and endlocal --- install/CPU/windows_cpu.bat | 2 ++ install/CUDA/windows_cuda_gpu.bat | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/install/CPU/windows_cpu.bat b/install/CPU/windows_cpu.bat index 18c43b8..b2090c4 100644 --- a/install/CPU/windows_cpu.bat +++ b/install/CPU/windows_cpu.bat @@ -1,7 +1,9 @@ @echo off +setlocal cd .. cd .. py -3.10 -m venv .venv SET VenvPythonPath=%CD%\.venv\Scripts\python.exe call %VenvPythonPath% -m pip install -r requirements.txt call %VenvPythonPath% -m pip install torch==2.0.1 torchvision==0.15.2 torchaudio==2.0.2 +endlocal \ No newline at end of file diff --git a/install/CUDA/windows_cuda_gpu.bat b/install/CUDA/windows_cuda_gpu.bat index 1f8e7a5..be49ed5 100644 --- a/install/CUDA/windows_cuda_gpu.bat +++ b/install/CUDA/windows_cuda_gpu.bat @@ -1,7 +1,9 @@ @echo off +setlocal cd .. cd .. py -3.10 -m venv .venv SET VenvPythonPath=%CD%\.venv\Scripts\python.exe call %VenvPythonPath% -m pip install -r requirements.txt -call %VenvPythonPath% -m pip install torch==2.0.1+cu117 torchvision==0.15.2+cu117 torchaudio==2.0.2+cu117 --index-url https://download.pytorch.org/whl/cu117 \ No newline at end of file +call %VenvPythonPath% -m pip install torch==2.0.1+cu117 torchvision==0.15.2+cu117 torchaudio==2.0.2+cu117 --index-url https://download.pytorch.org/whl/cu117 +endlocal \ No newline at end of file