Skip to content

Workaround: SpeechBrain torchaudio.info() removed in torchaudio 2.9.x #39

@bobsummerwill

Description

@bobsummerwill

Summary

SpeechBrain's dataio.py uses torchaudio.info() and torchaudio.backend.common.AudioMetaData which were removed in torchaudio 2.9.x. This causes import errors and runtime failures when processing audio files.

Error

AttributeError: module 'torchaudio' has no attribute 'info'

Or:

ModuleNotFoundError: No module named 'torchaudio.backend.common'

Root Cause

  • torchaudio 2.9.x removed torchaudio.info() function
  • torchaudio 2.9.x removed torchaudio.backend.common.AudioMetaData class
  • SpeechBrain uses these to get audio file metadata in read_audio_info()

Affected Versions

  • torchaudio >= 2.9.0
  • SpeechBrain (current versions as of Jan 2026)

Workaround

The install script (Step 10b) patches speechbrain/dataio/dataio.py:

  1. Adds AudioMetaDataCompat class to replace the removed AudioMetaData
  2. Replaces read_audio_info() to use torchaudio.load() for metadata extraction:
class AudioMetaDataCompat:
    """Compatibility class replacing torchaudio.backend.common.AudioMetaData."""
    def __init__(self, sample_rate, num_frames, num_channels, bits_per_sample=16, encoding="PCM_S"):
        self.sample_rate = sample_rate
        self.num_frames = num_frames
        self.num_channels = num_channels
        self.bits_per_sample = bits_per_sample
        self.encoding = encoding

def read_audio_info(path, backend=None) -> AudioMetaDataCompat:
    if hasattr(torchaudio, 'info'):
        # Old torchaudio version - use original approach
        ...
    else:
        # torchaudio 2.9.x: info() removed, use load() to get metadata
        channels_data, sample_rate = torchaudio.load(path, normalize=False)
        return AudioMetaDataCompat(
            sample_rate=sample_rate,
            num_frames=channels_data.size(1),
            num_channels=channels_data.size(0),
        )

Resolution

This workaround can be removed once SpeechBrain releases a version compatible with torchaudio 2.9.x.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions