Skip to content

Commit d06f8c7

Browse files
Fix audio test by patching torchcodec version retrieval
1 parent 2267f87 commit d06f8c7

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/sdialog/audio/tts/qwen3/tts.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# SPDX-License-Identifier: MIT
44
import torch
55
import numpy as np
6+
from typing import Optional
67

78
from qwen_tts import Qwen3TTSModel
89
from ..base import BaseTTS, BaseVoiceCloneTTS
@@ -76,7 +77,7 @@ def __init__(
7677

7778
def generate(self,
7879
text: str,
79-
speaker_voice: str | object = None,
80+
speaker_voice: Optional[object] = None,
8081
tts_pipeline_kwargs: dict = {}) -> tuple[np.ndarray, int]:
8182
"""
8283
Generates audio from text using the Hugging Face TTS pipeline.

tests/conftest.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,5 +111,19 @@ def get_samples_played_in_range(self, *_args, **_kwargs):
111111
sys.modules["torchcodec"] = torchcodec_module
112112
sys.modules["torchcodec.decoders"] = decoders_module
113113

114+
# transformers.audio_utils (and others) call importlib.metadata.version("torchcodec")
115+
# at module level. That call bypasses sys.modules and reads on-disk dist-info, so
116+
# it raises PackageNotFoundError even though our stub is in sys.modules, causing a
117+
# cascade failure across ALL tests. Patch it to return a harmless version string.
118+
import importlib.metadata as _imeta
119+
_real_version = _imeta.version
120+
121+
def _patched_version(name: str) -> str:
122+
if name == "torchcodec":
123+
return "0.0.0"
124+
return _real_version(name)
125+
126+
_imeta.version = _patched_version
127+
114128

115129
_install_torchcodec_stub()

0 commit comments

Comments
 (0)