From 7e978a281470d95dd0d441d47100fd435139e930 Mon Sep 17 00:00:00 2001 From: Vadim Date: Mon, 22 May 2023 21:40:06 +0200 Subject: [PATCH] - added option to force cpu for separation and whisper --- README.md | 4 ++++ Settings.py | 6 ++++-- UltraSinger.py | 12 +++++++++--- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index fbd3963..0d58cc8 100644 --- a/README.md +++ b/README.md @@ -61,6 +61,8 @@ _Not all options working now!_ --disable_separation True|False >> ((default) is False) --disable_karaoke True|False >> ((default) is False) --create_audio_chunks True|False >> ((default) is False) + --force_whisper_cpu True|False >> ((default) is False) + --force_separation_cpu True|False >> ((default) is False) [pitcher] # Default is crepe full @@ -190,3 +192,5 @@ When you want to use `conda` instead you need a different installation command. If somthing crash because of low VRAM than use a smaller model. Whisper needs more than 8GB VRAM in the `large` model! + +But you can force cpu usage with the extra options `--force_whisper_cpu` and `--force_separation_cpu`. diff --git a/Settings.py b/Settings.py index f455436..e60f15a 100644 --- a/Settings.py +++ b/Settings.py @@ -15,7 +15,7 @@ class Settings: # Whisper transcriber = 'whisper' # whisper|vosk - whisper_model = 'large' # Multilingual model tiny|base|small|medium|large + whisper_model = 'large' # Multilingual model tiny|base|small|medium|large # English-only model tiny.en|base.en|small.en|medium.en # Vosk @@ -26,5 +26,7 @@ class Settings: crepe_step_size = 10 # Device - device = 'cpu' # cpu|cuda|gpu + device = 'cpu' # cpu|cuda + force_whisper_cpu = False + force_separation_cpu = False diff --git a/UltraSinger.py b/UltraSinger.py index a85e685..b345af9 100644 --- a/UltraSinger.py +++ b/UltraSinger.py @@ -280,8 +280,9 @@ def run(): def transcribe_audio(transcribed_data): if settings.transcriber == "whisper": + device = "cpu" if settings.force_whisper_cpu else settings.device transcribed_data, language = transcribe_with_whisper(settings.mono_audio_path, settings.whisper_model, - settings.device) + device) else: # vosk transcribed_data = transcribe_with_vosk(settings.mono_audio_path, settings.vosk_model_path) # todo: make language selectable @@ -291,8 +292,9 @@ def transcribe_audio(transcribed_data): def separate_vocal_from_audio(basename_without_ext, cache_path, ultrastar_audio_input_path): audio_separation_path = os.path.join(cache_path, "separated", "htdemucs", basename_without_ext) + device = "cpu" if settings.force_separation_cpu else settings.device if settings.use_separated_vocal or settings.create_karaoke: - separate_audio(ultrastar_audio_input_path, cache_path, settings.device) + separate_audio(ultrastar_audio_input_path, cache_path, device) if settings.use_separated_vocal: vocals_path = os.path.join(audio_separation_path, "vocals.wav") convert_audio_to_mono_wav(vocals_path, settings.mono_audio_path) @@ -433,7 +435,7 @@ def main(argv): def init_settings(argv): short = "hi:o:amv:" long = ["ifile=", "ofile=", "crepe=", "vosk=", "whisper=", "hyphenation=", "disable_separation=", - "disable_karaoke=", "create_audio_chunks="] + "disable_karaoke=", "create_audio_chunks=", "force_whisper_cpu=", "force_separation_cpu="] opts, args = getopt.getopt(argv, short, long) if len(opts) == 0: print_help() @@ -462,6 +464,10 @@ def init_settings(argv): settings.create_karaoke = not arg elif opt in ("--create_audio_chunks"): settings.create_audio_chunks = arg + elif opt in ("--force_whisper_cpu"): + settings.force_whisper_cpu = arg + elif opt in ("--force_separation_cpu"): + settings.force_separation_cpu = arg if settings.output_file_path == '': if settings.input_file_path.startswith('https:'): dirname = os.getcwd()