Files
Federico Volovnik-Jose 284d50b44c fix: convert to relative imports + cache key/cpu/cleanup_one fixes
- Use relative imports across nodes/ and lib/ so ComfyUI's loader resolves the
  local subpackages instead of colliding with ComfyUI's own top-level nodes module.
- tts_output_to_audio_dict now returns CPU tensors so downstream nodes don't see CUDA tensors.
- model_state cache key uses resolved dtype string, so dtype=auto and the matching
  explicit choice share one cache slot (no spurious 13 GB reload).
- Add cleanup_one(key) helper as called for in spec section 4.
- Fix pyproject Homepage URL to point at this repo.
2026-04-25 16:51:32 +02:00

37 lines
1.1 KiB
Python

"""Resolve a ComfyUI AUDIO input or string path into a voice-reference dict."""
import logging
import os
from typing import Optional
from .audio import audio_dict_to_wav
log = logging.getLogger(__name__)
def build_voice_reference(
audio: Optional[dict],
audio_path: str,
temp_dir: str,
) -> dict:
"""Return a voice-reference container.
Priority:
1. If `audio` is set, write it to a temp WAV and use that path.
If `audio_path` is also set, log a warning and ignore it.
2. Else if `audio_path` is non-empty, validate the path exists and use it.
3. Else return source="none" / path=None (default voice).
"""
if audio is not None:
if audio_path:
log.warning("Both audio and audio_path provided; ignoring audio_path=%r", audio_path)
path = audio_dict_to_wav(audio, dest_dir=temp_dir)
return {"path": path, "source": "audio"}
if audio_path:
if not os.path.isfile(audio_path):
raise FileNotFoundError(f"Voice reference audio not found: {audio_path}")
return {"path": audio_path, "source": "path"}
return {"path": None, "source": "none"}