torchaudio.load() 和 librosa.load() 的区别

librosa.load() 参数如下:(得到的音频序列是numpy序列)

"""音频路径"""
path : string, int, pathlib.Path or file-like object
        path to the input file.

        Any codec supported by `soundfile` or `audioread` will work.

        Any string file paths, or any object implementing Python's
        file interface (e.g. `pathlib.Path`) are supported as `path`.

        If the codec is supported by `soundfile`, then `path` can also be
        an open file descriptor (int).

"""采样率"""
sr   : number > 0 [scalar]
        target sampling rate

        'None' uses the native sampling rate

"""是否设置为单声道或者多声道"""
mono : bool
        convert signal to mono


"""音频的起始点(单位是秒)"""
offset : float
        start reading after this time (in seconds)


""""读取音频的时长(单位为秒)"""
duration : float
        only load up to this much audio (in seconds)


"""设置音频序列的类型"""
dtype : numeric type
        data type of `y`


"""设置重采样类型"""
res_type : str
        resample type (see note)

        .. note::
            By default, this uses `resampy`'s high-quality mode ('kaiser_best').

            For alternative resampling modes, see `resample`

        .. note::
           `audioread` may truncate the precision of the audio data to 16 bits.

           See https://librosa.github.io/librosa/ioformats.html for alternate
           loading methods.


"""返回值两个值(前为音频序列,后为采样率)"""
Returns
    -------
    y    : np.ndarray [shape=(n,) or (2, n)]
        audio time series

    sr   : number > 0 [scalar]
        sampling rate of `y`

torchaudio.load(): 下载的得到的音频序列是tensor类型

常见用法:

clean_s, fs = torchaudio.load( filepath, frame_offset, num_frames)

filepath 是音频文件路径;

frame_offset 是音频起始点,和librosa不同的是,这里的起始点是采样点数;

num_frames 是音频的帧数;计算公式(wav_length - frame_len)/ frame_hop +1 = num_frames

  • 4
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值