{"record":{"id":"45e5302141b37650","repo":"Comfy-Org/ComfyUI","slug":"masks-must-be-provided-if-two-audio-encoder-output","errorCode":null,"errorMessage":"Masks must be provided if two audio encoder outputs are used.","messagePattern":"Masks must be provided if two audio encoder outputs are used\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"comfy_extras/nodes_wan.py","lineNumber":1517,"sourceCode":"                io.Int.Output(display_name=\"trim_image\"),\n            ],\n        )\n\n    @classmethod\n    def execute(cls, mode: DCValues, model, model_patch, positive, negative, vae, width, height, length, audio_encoder_output_1, motion_frame_count,\n                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:\n\n        if previous_frames is not None and previous_frames.shape[0] < motion_frame_count:\n            raise ValueError(\"Not enough previous frames provided.\")\n\n        if mode[\"mode\"] == \"two_speakers\":\n            audio_encoder_output_2 = mode[\"audio_encoder_output_2\"]\n            mask_1 = mode[\"mask_1\"]\n            mask_2 = mode[\"mask_2\"]\n\n        if audio_encoder_output_2 is not None:\n            if mask_1 is None or mask_2 is None:\n                raise ValueError(\"Masks must be provided if two audio encoder outputs are used.\")\n\n        ref_masks = None\n        if mask_1 is not None and mask_2 is not None:\n            if audio_encoder_output_2 is None:\n                raise ValueError(\"Second audio encoder output must be provided if two masks are used.\")\n            ref_masks = torch.cat([mask_1, mask_2])\n\n        latent = torch.zeros([1, 16, ((length - 1) // 4) + 1, height // 8, width // 8], device=comfy.model_management.intermediate_device())\n        if start_image is not None:\n            start_image = comfy.utils.common_upscale(start_image[:length].movedim(-1, 1), width, height, \"bilinear\", \"center\").movedim(1, -1)\n            image = torch.ones((length, height, width, start_image.shape[-1]), device=start_image.device, dtype=start_image.dtype) * 0.5\n            image[:start_image.shape[0]] = start_image\n\n            concat_latent_image = vae.encode(image[:, :, :, :3])\n            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)\n            concat_mask[:, :, :((start_image.shape[0] - 1) // 4) + 1] = 0.0\n\n            positive = node_helpers.conditioning_set_values(positive, {\"concat_latent_image\": concat_latent_image, \"concat_mask\": concat_mask})","sourceCodeStart":1499,"sourceCodeEnd":1535,"githubUrl":"https://github.com/Comfy-Org/ComfyUI/blob/1c6d8d45b3693bfbb32385b410d813a7fd6be216/comfy_extras/nodes_wan.py#L1499-L1535","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Provide both mask_1 and mask_2 (one speaker region each) when using two audio encoder outputs","If only one speaker, switch the mode back to single-speaker so no second audio/masks are expected","Check the mode component actually populated mask_1/mask_2 when assembling the DCValues mode dict"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"if audio_encoder_output_2 is not None:\n    assert mask_1 is not None and mask_2 is not None, \"two audio streams need two masks\"\nelif mask_1 is not None or mask_2 is not None:\n    mask_1 = mask_2 = None  # drop orphan masks for single-speaker mode","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Treat two-speaker mode as a unit: 2 audio encoders + 2 masks, always together","For single speaker, clear all second-stream inputs"],"tags":["wan","audio-video","two-speakers","masks"],"backgroundTag":null,"analyzedSha":"1c6d8d45b3693bfbb32385b410d813a7fd6be216","analyzedAt":"2026-08-14T19:37:18.893Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}