torchaudio
程序包由 I / O,常用數(shù)據(jù)集和常見音頻轉換組成。
torchaudio.get_sox_bool(i=0)?
獲取 sox_bool 枚舉以獲取 sox encodinginfo 選項。
參數(shù)
i (int , 可選)–選擇類型或獲取具有所有可能選項的字典,請使用__members__
查看未指定的所有選項。 (默認:sox_false
或0
)
退貨
sox_bool 類型
返回類型
sox_bool
torchaudio.get_sox_encoding_t(i=None)?
獲取 sox 編碼的 sox_encoding_t 枚舉。
Parameters
i (int , 可選)–選擇類型或獲取具有所有可能選項的字典,請使用__members__
查看未指定的所有選項。 (默認:None
)
Returns
用于輸出編碼的 sox_encoding_t 類型
Return type
sox_encoding_t
torchaudio.get_sox_option_t(i=2)?
獲取 sox encodinginfo 選項的 sox_option_t 枚舉。
Parameters
i (int , 可選)–選擇類型或獲取具有所有可能選項的字典,請使用__members__
查看未指定的所有選項。 (默認:sox_option_default
或2
)
Returns
sox_option_t 類型
Return type
sox_option_t
torchaudio.info(filepath)?
從音頻文件獲取元數(shù)據(jù),而不加載信號。
Parameters
文件路徑 (str)–音頻文件的路徑
Returns
si(sox_signalinfo_t)信號信息作為 python 對象。 EI(sox_encodinginfo_t)編碼信息
Return type
元組[sox_signalinfo_t,sox_encodinginfo_t]
Example
>>> si, ei = torchaudio.info('foo.wav')
>>> rate, channels, encoding = si.rate, si.channels, ei.encoding
torchaudio.initialize_sox()?
初始化 sox 以與效果鏈一起使用。 對于簡單加載,這不是必需的。 重要的是,只運行一次 <cite>initialize_sox</cite> ,并且不要在每個效果鏈之后都關閉,而是在完成所有效果鏈后才關閉。
torchaudio.load(filepath, out=None, normalization=True, channels_first=True, num_frames=0, offset=0, signalinfo=None, encodinginfo=None, filetype=None)?
將音頻文件從磁盤加載到張量
Parameters
None
)True
)True
)0
)0
)None
)None
)None
)Returns
大小為 <cite>[C x L]</cite> 或 <cite>[L x C]</cite> 的輸出張量,其中 L 是音頻幀數(shù),C 是聲道數(shù)。 一個整數(shù),它是音頻的采樣率(如文件的元數(shù)據(jù)中所列)
Return type
元組[torch.張量, int ]
Example
>>> data, sample_rate = torchaudio.load('foo.mp3')
>>> print(data.size())
torch.Size([2, 278756])
>>> print(sample_rate)
44100
>>> data_vol_normalized, _ = torchaudio.load('foo.mp3', normalization=lambda x: torch.abs(x).max())
>>> print(data_vol_normalized.abs().max())
1.
torchaudio.load_wav(filepath, **kwargs)?
加載波形文件。 假定 wav 文件每個樣本使用 16 位,需要通過將輸入右移 16 位來進行歸一化。
Parameters
filepath (str or pathlib.Path) – Path to audio file
Returns
An output tensor of size <cite>[C x L]</cite> or <cite>[L x C]</cite> where L is the number of audio frames and C is the number of channels. An integer which is the sample rate of the audio (as listed in the metadata of the file)
Return type
Tuple[torch.Tensor, int]
torchaudio.save(filepath, src, sample_rate, precision=16, channels_first=True)?
<cite>save_encinfo</cite> 的便捷功能。
Parameters
16
)True
)torchaudio.save_encinfo(filepath, src, channels_first=True, signalinfo=None, encodinginfo=None, filetype=None)?
將音頻信號的張量以 mp3,wav 等標準格式保存到磁盤。
Parameters
True
)None
)None
)None
)Example
>>> data, sample_rate = torchaudio.load('foo.mp3')
>>> torchaudio.save('foo.wav', data, sample_rate)
torchaudio.shutdown_sox()?
攤牌襪效果鏈。 簡單加載不需要。 重要的是,只能撥打一次。 嘗試重新初始化 sox 將導致段錯誤。
torchaudio.sox_encodinginfo_t()?
創(chuàng)建一個 sox_encodinginfo_t 對象。 該對象可用于設置編碼類型,位精度,壓縮系數(shù),反向字節(jié),反向半字節(jié),反向位和字節(jié)序。 可以在效果鏈中使用它來對最終輸出進行編碼或使用特定編碼保存文件。 例如,可以使用 sox ulaw 編碼進行 8 位 ulaw 編碼。 請注意,在張量輸出中,結果將是 32 位數(shù)字,但是唯一值的數(shù)量將由位精度確定。
Returns: sox_encodinginfo_t(object)
Example
>>> ei = torchaudio.sox_encodinginfo_t()
>>> ei.encoding = torchaudio.get_sox_encoding_t(1)
>>> ei.bits_per_sample = 16
>>> ei.compression = 0
>>> ei.reverse_bytes = torchaudio.get_sox_option_t(2)
>>> ei.reverse_nibbles = torchaudio.get_sox_option_t(2)
>>> ei.reverse_bits = torchaudio.get_sox_option_t(2)
>>> ei.opposite_endian = torchaudio.get_sox_bool(0)
torchaudio.sox_signalinfo_t()?
創(chuàng)建一個 sox_signalinfo_t 對象。 該對象可用于設置效果的采樣率,通道數(shù),長度,位精度和凈空倍數(shù)
Returns: sox_signalinfo_t(object)
None
無乘數(shù)Example
>>> si = torchaudio.sox_signalinfo_t()
>>> si.channels = 1
>>> si.rate = 16000.
>>> si.precision = 16
>>> si.length = 0
更多建議: