Untitled

 avatar
unknown
plain_text
12 days ago
1.2 kB
3
Indexable
class AudioPreviewNode:
    @classmethod
    def INPUT_TYPES(cls):
        return {"required": {"audio": ("AUDIO",)}}

    RETURN_TYPES = ()
    OUTPUT_NODE = True
    CATEGORY = "AudioCraft"
    FUNCTION = "preview"

    def preview(self, audio):
        # Get output directory and ensure it exists
        output_dir = folder_paths.get_output_directory()
        os.makedirs(output_dir, exist_ok=True)
        
        # Generate timestamped filename
        timestamp = str(int(time.time()))[-6:]
        filename = f"AC_{timestamp}.wav"
        full_path = os.path.join(output_dir, filename)
        
        # Ensure audio tensor is CPU and save
        audio_cpu = audio[0].cpu()
        torchaudio.save(full_path, audio_cpu, 32000)
        
        # Register file with ComfyUI's system
        folder_paths.add_output_file(filename)
        
        # Return in ComfyUI's expected format
        return {
            "ui": {
                "audio": [
                    {
                        "filename": filename,
                        "subfolder": "",
                        "type": "output"
                    }
                ]
            }
        }
Leave a Comment