-2
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.

2
  • It's a bit unclear what you're asking for here. It's getting the signal rate from whatever file you're passing it in, most audio formats encode things like sample rates within them. Commented Aug 30, 2023 at 16:56
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. Commented Aug 30, 2023 at 19:20

1 Answer 1

0

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

Sign up to request clarification or add additional context in comments.

4 Comments

thank you,but I have read this instruction file many times, but I still cannot find the basis for obtaining sampling rate and audio length in this program. There is no file indicating two usage methods such as si. rate and si. length
@eureka I thinks it a version problem. in old version of torchaudio. I found mattip.github.io/audio/0.7/…, which has rate and length, also the info return a tuple.
Another question, is a higher version of TorchAudio compatible with lower versions of functions?
@eureka It depends, you can use the newest version of torchaudio. I think it is not very difficult if you understand the pipeline.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.