Preserve Second Pass audio and scoped Review conditioning, strengthen Take compatibility, and align Review Driving Audio. Keep v5 history readable, document v6 restart requirements, and describe the fixes at the top of both READMEs. Remove workstation-specific paths and private operational records from public documentation.
30 lines
1.0 KiB
Python
30 lines
1.0 KiB
Python
"""Use Core audio DSP; retain the existing adapter for older Core versions."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import importlib
|
|
|
|
|
|
def resample_audio(waveform, source_rate: int, target_rate: int):
|
|
if source_rate == target_rate:
|
|
return waveform
|
|
try:
|
|
core_audio = importlib.import_module("comfy.audio")
|
|
except ModuleNotFoundError as exc:
|
|
if exc.name not in {"comfy", "comfy.audio"}:
|
|
raise
|
|
core_audio = None
|
|
core_resample = getattr(core_audio, "resample", None)
|
|
if core_resample is not None:
|
|
# Errors from an available Core API are real errors, not API absence.
|
|
return core_resample(waveform, source_rate, target_rate)
|
|
try:
|
|
torchaudio = importlib.import_module("torchaudio")
|
|
except ModuleNotFoundError as exc:
|
|
if exc.name != "torchaudio":
|
|
raise
|
|
raise RuntimeError(
|
|
"Audio resampling requires comfy.audio.resample or legacy torchaudio"
|
|
) from exc
|
|
return torchaudio.functional.resample(waveform, source_rate, target_rate)
|