pythontorchaudio

Why is this program using torch studio like this


import torchaudio
# get length of file in samples(得到样本中文件的长度)
info = {}  # 创建列表
si, _ = torchaudio.info(str(path))  # 会返回文件信息(Get signal information of an audio file.)
info['samplerate'] = si.rate
info['samples'] = si.length // si.channels
info['duration'] = info['samples'] / si.rate
return info

I didn't see the two writing methods of si. rate and si. length from any file description. I would like to ask if this writing method is correct, and if so, what is the explanatory document it is based on. The program comes from the utils file in umss in github

I would like to ask if this writing method is correct, and if so, what is the explanatory document it is based on.


Solution

  • accord the doc of torchaudio

    torchaudio.info(filepath: str, ...)
    

    Fetch meta data of an audio file. Refer to torchaudio.backend for the detail.

    the metainfo of the audio is

    CLASStorchaudio.backend.common.AudioMetaData(
        sample_rate: int, 
        num_frames: int, 
        num_channels: int, 
        bits_per_sample: int, 
        encoding: str)
    

    you can see details from https://pytorch.org/audio/stable/backend.html#backend