mirror of
https://github.com/justUmen/Bjornulf_custom_nodes.git
synced 2026-03-21 20:52:11 -03:00
0.33
This commit is contained in:
@@ -5,12 +5,14 @@ import logging
|
||||
from pydub import AudioSegment
|
||||
from pydub.playback import play
|
||||
import os
|
||||
import sys
|
||||
import io
|
||||
import random
|
||||
|
||||
class Everything(str):
|
||||
def __ne__(self, __value: object) -> bool:
|
||||
return False
|
||||
|
||||
|
||||
class PickInput:
|
||||
is_paused = True
|
||||
should_stop = False
|
||||
@@ -21,9 +23,10 @@ class PickInput:
|
||||
return {
|
||||
"required": {
|
||||
"number_of_inputs": ("INT", {"default": 2, "min": 1, "max": 10, "step": 1}),
|
||||
"seed": ("INT", {"default": 1}),
|
||||
},
|
||||
"hidden": {
|
||||
**{f"input_{i}": (Everything("*"), {"forceInput": "True"}) for i in range(2, 11)}
|
||||
**{f"input_{i}": (Everything("*"), {"forceInput": "True"}) for i in range(1, 11)}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,11 +36,32 @@ class PickInput:
|
||||
CATEGORY = "Bjornulf"
|
||||
|
||||
def play_audio(self):
|
||||
audio_file = os.path.join(os.path.dirname(__file__), 'bell.m4a')
|
||||
sound = AudioSegment.from_file(audio_file, format="m4a")
|
||||
play(sound)
|
||||
# Check if the operating system is Windows
|
||||
if sys.platform.startswith('win'):
|
||||
try:
|
||||
# Load the audio file into memory
|
||||
audio_file = os.path.join(os.path.dirname(__file__), 'bell.m4a')
|
||||
|
||||
# Load the audio segment without writing to any temp files
|
||||
sound = AudioSegment.from_file(audio_file, format="m4a")
|
||||
|
||||
# Export the AudioSegment to a WAV file in memory
|
||||
wav_io = io.BytesIO()
|
||||
sound.export(wav_io, format='wav')
|
||||
wav_data = wav_io.getvalue()
|
||||
|
||||
# Play the WAV data using winsound
|
||||
import winsound
|
||||
winsound.PlaySound(wav_data, winsound.SND_MEMORY)
|
||||
except Exception as e:
|
||||
print(f"An error occurred: {e}")
|
||||
else:
|
||||
audio_file = os.path.join(os.path.dirname(__file__), 'bell.m4a')
|
||||
sound = AudioSegment.from_file(audio_file, format="m4a")
|
||||
play(sound)
|
||||
|
||||
def pick_input(self, **kwargs):
|
||||
def pick_input(self, seed, **kwargs):
|
||||
random.seed(seed)
|
||||
logging.info(f"Selected input at the start: {PickInput.selected_input}")
|
||||
self.play_audio()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user