allow custom sound

This commit is contained in:
pythongosssss
2024-01-03 18:19:13 +00:00
parent 228ffbcb9c
commit c9bae148b5
2 changed files with 15 additions and 3 deletions
+3 -2
View File
@@ -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,)}
+12 -1
View File
@@ -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();