Comfy-Org/ComfyUI · error · ValueError

Masks must be provided if two audio encoder outputs are…

Error message

Masks must be provided if two audio encoder outputs are used.

What it means

In the two-speaker mode of the Wan audio node, two audio encoder outputs (one per speaker) require a corresponding mask per speaker so the model knows which region each audio stream drives. If audio_encoder_output_2 is set (via the mode dict or directly) but either mask is missing, the node raises before building ref_masks.

Solutions

  1. Provide both mask_1 and mask_2 (one speaker region each) when using two audio encoder outputs
  2. If only one speaker, switch the mode back to single-speaker so no second audio/masks are expected
  3. Check the mode component actually populated mask_1/mask_2 when assembling the DCValues mode dict
Defensive patterns

Strategy: validation

Validate before calling

if audio_encoder_output_2 is not None:
    assert mask_1 is not None and mask_2 is not None, "two audio streams need two masks"
elif mask_1 is not None or mask_2 is not None:
    mask_1 = mask_2 = None  # drop orphan masks for single-speaker mode

Prevention

When it happens

Trigger: Selecting mode 'two_speakers' (which injects audio_encoder_output_2, mask_1, mask_2 from the mode dict) where masks were not provided; or wiring a second audio encoder output while leaving mask_1/mask_2 unconnected.

Common situations: Configuring a two-speaker talking-head workflow but forgetting the two region masks; mode dict built without mask entries; testing with a single speaker while the mode string still says two_speakers.

Related errors


AI-assisted analysis of Comfy-Org/ComfyUI@1c6d8d45b3 (2026-08-14). Data as JSON: /api/errors/45e5302141b37650. Report an issue: GitHub.

Appendix: source

Thrown at comfy_extras/nodes_wan.py:1517

                io.Int.Output(display_name="trim_image"),
            ],
        )

    @classmethod
    def execute(cls, mode: DCValues, model, model_patch, positive, negative, vae, width, height, length, audio_encoder_output_1, motion_frame_count,
                start_image=None, previous_frames=None, audio_scale=None, clip_vision_output=None, audio_encoder_output_2=None, mask_1=None, mask_2=None) -> io.NodeOutput:

        if previous_frames is not None and previous_frames.shape[0] < motion_frame_count:
            raise ValueError("Not enough previous frames provided.")

        if mode["mode"] == "two_speakers":
            audio_encoder_output_2 = mode["audio_encoder_output_2"]
            mask_1 = mode["mask_1"]
            mask_2 = mode["mask_2"]

        if audio_encoder_output_2 is not None:
            if mask_1 is None or mask_2 is None:
                raise ValueError("Masks must be provided if two audio encoder outputs are used.")

        ref_masks = None
        if mask_1 is not None and mask_2 is not None:
            if audio_encoder_output_2 is None:
                raise ValueError("Second audio encoder output must be provided if two masks are used.")
            ref_masks = torch.cat([mask_1, mask_2])

        latent = torch.zeros([1, 16, ((length - 1) // 4) + 1, height // 8, width // 8], device=comfy.model_management.intermediate_device())
        if start_image is not None:
            start_image = comfy.utils.common_upscale(start_image[:length].movedim(-1, 1), width, height, "bilinear", "center").movedim(1, -1)
            image = torch.ones((length, height, width, start_image.shape[-1]), device=start_image.device, dtype=start_image.dtype) * 0.5
            image[:start_image.shape[0]] = start_image

            concat_latent_image = vae.encode(image[:, :, :, :3])
            concat_mask = torch.ones((1, 1, latent.shape[2], concat_latent_image.shape[-2], concat_latent_image.shape[-1]), device=start_image.device, dtype=start_image.dtype)
            concat_mask[:, :, :((start_image.shape[0] - 1) // 4) + 1] = 0.0

            positive = node_helpers.conditioning_set_values(positive, {"concat_latent_image": concat_latent_image, "concat_mask": concat_mask})

View on GitHub (pinned to 1c6d8d45b3)