Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions comfy_extras/nodes_audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,24 @@ def VALIDATE_INPUTS(s, audio):
return "Invalid audio file: {}".format(audio)
return True

class RecordAudio:
@classmethod
def INPUT_TYPES(s):
return {"required": {"audio": ("AUDIO_RECORD", {})}}

CATEGORY = "audio"

RETURN_TYPES = ("AUDIO", )
FUNCTION = "load"

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note for any other reviewers (or future me): Because the uploaded files are named via timestamps by the frontend, an existing uploaded audio file should never be updated. That's why we don't need the IS_CHANGED here.

def load(self, audio):
audio_path = folder_paths.get_annotated_filepath(audio)

waveform, sample_rate = torchaudio.load(audio_path)
audio = {"waveform": waveform.unsqueeze(0), "sample_rate": sample_rate}
return (audio, )


NODE_CLASS_MAPPINGS = {
"EmptyLatentAudio": EmptyLatentAudio,
"VAEEncodeAudio": VAEEncodeAudio,
Expand All @@ -331,6 +349,7 @@ def VALIDATE_INPUTS(s, audio):
"LoadAudio": LoadAudio,
"PreviewAudio": PreviewAudio,
"ConditioningStableAudio": ConditioningStableAudio,
"RecordAudio": RecordAudio,
}

NODE_DISPLAY_NAME_MAPPINGS = {
Expand All @@ -342,4 +361,5 @@ def VALIDATE_INPUTS(s, audio):
"SaveAudio": "Save Audio (FLAC)",
"SaveAudioMP3": "Save Audio (MP3)",
"SaveAudioOpus": "Save Audio (Opus)",
"RecordAudio": "Record Audio",
}