diff --git a/README.MD b/README.MD index c46800b..51f66dc 100644 --- a/README.MD +++ b/README.MD @@ -1,3 +1,6 @@ +# 更新: +增加一个后台播放音频文件的节点Play Sound,包括音量调节。这个节点支持多线程播放。 + # ComfyUI_MSSpeech_TTS ComfyUI下使用的文本转语音插件。使用Microsoft speech TTS 接口将文本内容转为MP3格式的语音文件。 diff --git a/py/playsound.py b/py/playsound.py new file mode 100644 index 0000000..1db9df1 --- /dev/null +++ b/py/playsound.py @@ -0,0 +1,46 @@ +import sys +import os +import threading +from arcade import load_sound, play_sound + +class Sound: + + def play(self, file_name, volume): + sound = load_sound(file_name) + play_sound(sound, volume) + + +def Play(path, volume): + s = Sound() + s.play(path, volume) + +class Play_Sound_Now(): + + def __init__(self): + pass + + @classmethod + def INPUT_TYPES(cls): + return { + "required": { + "path": ("STRING", {"default": 'comfyui.mp3'}), + "volume": ("FLOAT", {"default": 1, "min": 0.0, "max": 1.0, "step": 0.01}), + }, + "optional": { + }, + } + + RETURN_TYPES = () + FUNCTION = "do_playsound" + OUTPUT_NODE = True + CATEGORY = "MicorsoftSpeech_TTS" + + def do_playsound(self, path, volume): + t = threading.Thread(target=Play(path, volume)) + t.start() + return {"ui": {"text": ("",)}} + + +NODE_CLASS_MAPPINGS = { + "Play Sound": Play_Sound_Now +} diff --git a/requirements.txt b/requirements.txt index 753a1af..c90ffe2 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ -numpy==1.23.4 +numpy edge_tts asyncio - +arcade