torchaudio.load
将音频文件转化为tensor
函数输出两个值:音频信号和采样率,函数输入如下:
torchaudio.backend.sox_io_backend.load(filepath: str, frame_offset: int = 0, num_frames: int = -1, normalize: bool = True, channels_first: bool = True, format: Optional[str] = None) → Tuple[Tensor, int]
其中channels_first为True时,音频信号tensor的shape为[channel, time],channel为声道数,time为各个时间点的信号值。如果channels_first为False,tensor的shape为[time, channels]
noirmalize参数并不执行音量的归一化,而是把采样点的数据类型从原来的类型转化为torch.float32
。当输入格式为WAV的整数类型,比如32bit带符号整型,16bit带符号整型,24bit带符号整型,8bit无符号整型,参数normalize=False
会返回整型的tensor。对于32bit浮点型WAV和其他格式,比如flac和mp3,normalize参数没有作用。
torchaudio.Resample类
将一个信号从一个频率(frequency)resample到另一个频率。
CLASStorchaudio.transforms.Resample(orig_freq: int = 16000, new_freq: int = 16000, resampling_method: str = 'sinc_interpolation', lowpass_filter_width: int = 6, rolloff: float = 0.99, beta: Optional[float] = None, *, dtype: Optional[dtype] = None)