added preview widgets
This commit is contained in:
@@ -241,11 +241,12 @@ class LoadAudio:
|
||||
|
||||
def load_audio(self, audio, sr):
|
||||
audio_path = folder_paths.get_annotated_filepath(audio)
|
||||
print(f"{audio_path=} {audio=}")
|
||||
widgetId = get_hash(audio_path)
|
||||
audio_name = os.path.basename(audio).split(".")[0]
|
||||
sr = None if sr=="None" else int(sr)
|
||||
audio = load_input_audio(audio_path,sr=sr)
|
||||
return (audio_name,lambda:audio_to_bytes(*audio))
|
||||
return {"ui": {"preview": [{"filename": audio_name, "type": "input", "widgetId": widgetId}]}, "result": (audio_name, lambda:audio_to_bytes(*audio))}
|
||||
# return (audio_name,lambda:audio_to_bytes(*audio))
|
||||
|
||||
@classmethod
|
||||
def IS_CHANGED(cls, audio):
|
||||
|
||||
+15
-2
@@ -1,10 +1,13 @@
|
||||
import os
|
||||
import shutil
|
||||
|
||||
from ..lib.audio import SUPPORTED_AUDIO, audio_to_bytes, bytes_to_audio, load_input_audio, save_input_audio
|
||||
from ..lib.utils import get_hash
|
||||
from .utils import increment_filename_no_overwrite
|
||||
import folder_paths
|
||||
|
||||
temp_path = folder_paths.get_temp_directory()
|
||||
|
||||
class PreviewAudio:
|
||||
def __init__(self):
|
||||
pass
|
||||
@@ -18,6 +21,7 @@ class PreviewAudio:
|
||||
"save_format": (SUPPORTED_AUDIO,{"default": "flac"},),
|
||||
"save_channels": ([1,2],{"default": 1}),
|
||||
"overwrite_existing": ("BOOLEAN", {"default": True}),
|
||||
"autoplay": ("BOOLEAN", {"default": True}),
|
||||
},
|
||||
}
|
||||
|
||||
@@ -30,7 +34,7 @@ class PreviewAudio:
|
||||
|
||||
FUNCTION = "save_audio"
|
||||
|
||||
def save_audio(self, audio, filename, save_format, save_channels, overwrite_existing):
|
||||
def save_audio(self, audio, filename, save_format, save_channels, overwrite_existing, autoplay):
|
||||
|
||||
filename = filename.strip()
|
||||
assert filename, "Filename cannot be empty"
|
||||
@@ -44,10 +48,19 @@ class PreviewAudio:
|
||||
if os.path.isfile(output_path) and not overwrite_existing:
|
||||
output_path = increment_filename_no_overwrite(output_path)
|
||||
|
||||
|
||||
input_audio = bytes_to_audio(audio())
|
||||
print(save_input_audio(output_path,input_audio,to_int16=True,to_stereo=save_channels==2))
|
||||
|
||||
return output_path, lambda:audio_to_bytes(*input_audio)
|
||||
tempdir = os.path.join(temp_path,"preview")
|
||||
os.makedirs(tempdir, exist_ok=True)
|
||||
widgetId = get_hash(output_path,save_channels)
|
||||
audio_name = f"{widgetId}.{save_format}"
|
||||
preview_file = os.path.join(tempdir,audio_name)
|
||||
if not os.path.isfile(preview_file): shutil.copyfile(output_path,preview_file)
|
||||
return {"ui": {"preview": [{
|
||||
"filename": audio_name, "type": "temp", "subfolder": "preview", "widgetId": widgetId, "autoplay": autoplay
|
||||
}]}, "result": (output_path, lambda:audio_to_bytes(*input_audio))}
|
||||
|
||||
@classmethod
|
||||
def IS_CHANGED(cls, audio):
|
||||
|
||||
+9
-2
@@ -1,4 +1,5 @@
|
||||
import os
|
||||
import shutil
|
||||
|
||||
from ..lib.audio import audio_to_bytes, bytes_to_audio, load_input_audio, save_input_audio
|
||||
|
||||
@@ -57,7 +58,8 @@ class RVCNode:
|
||||
|
||||
def convert(self, audio, model, hubert_model, pitch_extraction_params, format, use_cache=True, **kwargs):
|
||||
|
||||
cache_name = os.path.join(BASE_CACHE_DIR,"rvc",f"{get_hash(audio(), model, *pitch_extraction_params.items())}.{format}")
|
||||
widgetId = get_hash(audio(), model, *pitch_extraction_params.items())
|
||||
cache_name = os.path.join(BASE_CACHE_DIR,"rvc",f"{widgetId}.{format}")
|
||||
|
||||
if use_cache and os.path.isfile(cache_name): output_audio = load_input_audio(cache_name)
|
||||
else:
|
||||
@@ -65,7 +67,12 @@ class RVCNode:
|
||||
output_audio = vc_single(hubert_model=hubert_model(),input_audio=input_audio,**model(),**pitch_extraction_params,**kwargs)
|
||||
print(save_input_audio(cache_name, output_audio))
|
||||
|
||||
return (lambda:audio_to_bytes(*output_audio),)
|
||||
tempdir = os.path.join(temp_path,"preview")
|
||||
os.makedirs(tempdir, exist_ok=True)
|
||||
audio_name = os.path.basename(cache_name)
|
||||
preview_file = os.path.join(tempdir,audio_name)
|
||||
if not os.path.isfile(preview_file): shutil.copyfile(cache_name,preview_file)
|
||||
return {"ui": {"preview": [{"filename": audio_name, "type": "temp", "subfolder": "preview", "widgetId": widgetId}]}, "result": (lambda:audio_to_bytes(*output_audio),)}
|
||||
|
||||
|
||||
@classmethod
|
||||
|
||||
+13
-5
@@ -10,7 +10,7 @@ from ..lib.utils import gc_collect, get_hash
|
||||
from .settings.downloader import RVC_DOWNLOAD_LINK, download_file
|
||||
from ..lib import BASE_MODELS_DIR
|
||||
import numpy as np
|
||||
from ..lib.audio import MAX_INT16, audio_to_bytes, bytes_to_audio, merge_audio, remix_audio
|
||||
from ..lib.audio import MAX_INT16, audio_to_bytes, bytes_to_audio, load_input_audio, merge_audio, remix_audio, save_input_audio
|
||||
|
||||
CATEGORY = "🌺RVC-Studio/utils"
|
||||
temp_path = folder_paths.get_temp_directory()
|
||||
@@ -357,10 +357,18 @@ class MergeAudioNode:
|
||||
|
||||
def merge(self, audio1, audio2, sr, merge_type, normalize):
|
||||
if sr=="None": sr=None
|
||||
input_audio1 = bytes_to_audio(audio1())
|
||||
input_audio2 = bytes_to_audio(audio2())
|
||||
merged_audio = merge_audio(input_audio1,input_audio2,sr=sr,to_int16=True,norm=normalize,merge_type=merge_type)
|
||||
return (lambda: audio_to_bytes(*merged_audio),)
|
||||
|
||||
widgetId = get_hash(audio1(),audio2(),sr,merge_type,normalize)
|
||||
audio_path = os.path.join(temp_path,"preview",f"{widgetId}.flac")
|
||||
|
||||
if os.path.isfile(audio_path): merged_audio = load_input_audio(audio_path, sr, norm=normalize)
|
||||
else:
|
||||
input_audio1 = bytes_to_audio(audio1())
|
||||
input_audio2 = bytes_to_audio(audio2())
|
||||
merged_audio = merge_audio(input_audio1,input_audio2,sr=sr,to_int16=True,norm=normalize,merge_type=merge_type)
|
||||
print(save_input_audio(audio_path,merged_audio))
|
||||
audio_name = os.path.basename(audio_path)
|
||||
return {"ui": {"preview": [{"filename": audio_name, "type": "temp", "subfolder": "preview", "widgetId": widgetId}]}, "result": (lambda: audio_to_bytes(*merged_audio),)}
|
||||
|
||||
@classmethod
|
||||
def IS_CHANGED(cls, *args, **kwargs):
|
||||
|
||||
+1
-1
@@ -84,4 +84,4 @@ class UVR5Node:
|
||||
@classmethod
|
||||
def IS_CHANGED(cls, *args, **kwargs):
|
||||
print(f"{args=} {kwargs=}")
|
||||
return get_hash(*args, *kwargs.items())
|
||||
return get_hash(args,kwargs)
|
||||
Reference in New Issue
Block a user