""" Python 3.8 兼容性补丁: 修复 speechbrain 中的 list[int] 语法。 在导入 speechbrain 之前 import 本模块即可。 """ import speechbrain.dataio.sampler as _s # Force evaluation of the module to catch the error # The fix: monkey-patch before import completes import sys from speechbrain.dataio import sampler as _sampler_mod # Patch the problematic line: replace Optional[list[int]] with Optional["List[int]"] # This is done at the source level by editing the file import os _sp = os.path.join(os.path.dirname(_sampler_mod.__file__), "sampler.py") if os.path.exists(_sp): with open(_sp) as f: src = f.read() if "from __future__ import annotations" not in src: with open(_sp, "w") as f: f.write("from __future__ import annotations\n" + src) print("[speechbrain_fix] patched sampler.py for Python 3.8")