From c9bae148b536d7147b4e10352948d3333b78d157 Mon Sep 17 00:00:00 2001 From: pythongosssss <125205205+pythongosssss@users.noreply.github.com> Date: Wed, 3 Jan 2024 18:19:13 +0000 Subject: [PATCH] allow custom sound --- py/play_sound.py | 5 +++-- web/js/playSound.js | 13 ++++++++++++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/py/play_sound.py b/py/play_sound.py index 17688b1..65f599d 100644 --- a/py/play_sound.py +++ b/py/play_sound.py @@ -14,7 +14,8 @@ class PlaySound: return {"required": { "any": (any, {}), "mode": (["always", "on empty queue"], {}), - "volume": ("FLOAT", {"min": 0, "max": 1, "step": 0.1, "default": 0.5}) + "volume": ("FLOAT", {"min": 0, "max": 1, "step": 0.1, "default": 0.5}), + "file": ("STRING", { "default": "notify.mp3" }) }} FUNCTION = "nop" @@ -28,7 +29,7 @@ class PlaySound: def IS_CHANGED(self, **kwargs): return float("NaN") - def nop(self, any, mode, volume): + def nop(self, any, mode, volume, file): return {"ui": {"a": []}, "result": (any,)} diff --git a/web/js/playSound.js b/web/js/playSound.js index e472170..de71058 100644 --- a/web/js/playSound.js +++ b/web/js/playSound.js @@ -15,7 +15,18 @@ app.registerExtension({ return; } } - const url = new URL(`assets/notify.mp3`, import.meta.url); + let file = this.widgets[2].value; + if (!file) { + file = "notify.mp3"; + } + if (!file.startsWith("http")) { + if (!file.includes("/")) { + file = "assets/" + file; + } + file = new URL(file, import.meta.url) + } + + const url = new URL(file); const audio = new Audio(url); audio.volume = this.widgets[1].value; audio.play();