add trigger control for playsound nodes

This commit is contained in:
chflame163
2023-12-09 15:23:42 +08:00
parent c30f323df8
commit 2b9f36d54d
17 changed files with 105 additions and 36 deletions
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+44
View File
@@ -0,0 +1,44 @@
class AnyType(str):
"""always equal in 'not equal comparisons(__ne__)' """
def __ne__(self, __value: object) -> bool:
return False
any = AnyType("*")
class Trigger:
def __init__(self):
pass
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"always_true": ("BOOLEAN", {"default": False}),
},
"optional": {
"anything": (any, {}),
},
}
RETURN_TYPES = ("BOOLEAN",)
FUNCTION = "check_input"
OUTPUT_NODE = True
CATEGORY = "MicrosoftSpeech_TTS"
def check_input(self, always_true, anything=None):
ret = False
if always_true or (anything is not None):
ret = True
print(f"Input Trigger: {ret}")
return (ret,)
NODE_CLASS_MAPPINGS = {
"Input Trigger": Trigger
}
+12 -12
View File
@@ -10,7 +10,7 @@ async def gen_tts(_text,_voice,_rate,filename):
tts = edge_tts.Communicate(text = _text, voice = _voice, rate = _rate)
await tts.save(filename)
class Text2AutioEdgeTts:
class Text2AudioEdgeTts:
def __init__(self):
self.output_dir = os.path.join(folder_paths.get_output_directory(), 'audio')
if not os.path.exists(self.output_dir):
@@ -36,34 +36,34 @@ class Text2AutioEdgeTts:
}
RETURN_TYPES = ("STRING",)
RETURN_NAMES = ("MP3 file: String",)
FUNCTION = "text_2_autio"
FUNCTION = "text_2_audio"
OUTPUT_NODE = True
CATEGORY = "MicorsoftSpeech_TTS"
CATEGORY = "MicrosoftSpeech_TTS"
def text_2_autio(self,voice,filename_prefix,text,rate):
def text_2_audio(self,voice,filename_prefix,text,rate):
full_output_folder, filename, counter, subfolder, filename_prefix = folder_paths.get_save_image_path(filename_prefix, self.output_dir)
_datetime = datetime.datetime.now().strftime("%Y%m%d")
_datetime = _datetime + datetime.datetime.now().strftime("%H%M%S%f")
file = f"{filename}_{_datetime}_{voice}.mp3"
autio_path=os.path.join(full_output_folder, file)
audio_path=os.path.join(full_output_folder, file)
_rate = str(rate) + "%" if rate < 0 else "+" + str(rate) + "%"
print(f"MicrosoftSpeech TTS: Generating voice files, voice=‘{voice}’, rate={rate}, audiofile_path='{autio_path}, 'text='{text}'")
# asyncio.run(edge_tts_text_2_aution(voice,text,autio_path))
asyncio.run(gen_tts(text,voice,_rate,autio_path))
print(f"MicrosoftSpeech TTS: Generating voice files, voice=‘{voice}’, rate={rate}, audiofile_path='{audio_path}, 'text='{text}'")
asyncio.run(gen_tts(text,voice,_rate,audio_path))
return {"ui": {"text": "Audio file:"+os.path.join(full_output_folder, file),
'autios':[{'filename':file,'type':'output','subfolder':'autio'}]}, "result": (autio_path, )}
'audios':[{'filename':file,'type':'output','subfolder':'audio'}]}, "result": (audio_path, )}
async def edge_tts_text_2_aution(VOICE,TEXT,OUTPUT_FILE) -> None:
async def edge_tts_text_2_audion(VOICE,TEXT,OUTPUT_FILE) -> None:
communicate = edge_tts.Communicate(TEXT, VOICE)
await communicate.save(OUTPUT_FILE)
NODE_CLASS_MAPPINGS = {
"MicorsoftSpeech_TTS": Text2AutioEdgeTts
"MicrosoftSpeech_TTS": Text2AudioEdgeTts
}
NODE_DISPLAY_NAME_MAPPINGS = {
"MicorsoftSpeech_TTS": "MicorsoftSpeech_TTS"
"MicrosoftSpeech_TTS": "MicrosoftSpeech_TTS"
}
+12 -8
View File
@@ -1,13 +1,12 @@
import sys
import os
import threading
from arcade import load_sound
def Play(path, volume, speed):
s = load_sound(path)
s.play(volume, 0, False, speed)
class Play_Sound_Now():
class Play_Sound_Now:
def __init__(self):
pass
@@ -19,6 +18,7 @@ class Play_Sound_Now():
"path": ("STRING", {"default": 'comfyui.mp3'}),
"volume": ("FLOAT", {"default": 1, "min": 0.0, "max": 1.0, "step": 0.01}),
"speed": ("FLOAT", {"default": 1, "min": 0.1, "max": 2.0, "step": 0.1}),
"trigger": ("BOOLEAN",{"default": True}),
},
"optional": {
},
@@ -27,12 +27,16 @@ class Play_Sound_Now():
RETURN_TYPES = ()
FUNCTION = "do_playsound"
OUTPUT_NODE = True
CATEGORY = "MicorsoftSpeech_TTS"
CATEGORY = "MicrosoftSpeech_TTS"
def do_playsound(self, path, volume, speed):
t = threading.Thread(target=Play(path, volume, speed))
t.start()
return {"ui": {"text": ("",)}}
def do_playsound(self, path, volume, speed, trigger):
print(f"play sound: path={path},volume={volume},speed={speed},trigger={trigger}")
if trigger:
t = threading.Thread(target=Play(path, volume, speed))
t.start()
return {}
NODE_CLASS_MAPPINGS = {
+10 -6
View File
@@ -1,4 +1,3 @@
import sys
import os
import threading
from pygame import mixer
@@ -14,7 +13,7 @@ def Play(path, volume, loop):
else:
mixer.music.play()
class Play_Sound_pygame_Now():
class Play_Sound_pygame_Now:
def __init__(self):
pass
@@ -26,6 +25,7 @@ class Play_Sound_pygame_Now():
"path": ("STRING", {"default": 'comfyui.mp3'}),
"volume": ("FLOAT", {"default": 1, "min": 0.0, "max": 1.0, "step": 0.01}),
"loop": ("BOOLEAN", {"default": False}),
"trigger": ("BOOLEAN", {"default": True}),
},
"optional": {
},
@@ -34,11 +34,15 @@ class Play_Sound_pygame_Now():
RETURN_TYPES = ()
FUNCTION = "do_playsound"
OUTPUT_NODE = True
CATEGORY = "MicorsoftSpeech_TTS"
CATEGORY = "MicrosoftSpeech_TTS"
def do_playsound(self, path, volume, loop, trigger):
print(f"play sound: path={path},volume={volume},loop={loop},trigger={trigger}")
if trigger:
t = threading.Thread(target=Play(path, volume, loop))
t.start()
def do_playsound(self, path, volume, loop):
t = threading.Thread(target=Play(path, volume, loop))
t.start()
return {}