torchaudio
程序包由 I / O,常用數(shù)據(jù)集和常見(jiàn)音頻轉(zhuǎn)換組成。
torchaudio.get_sox_bool(i=0)?
獲取 sox_bool 枚舉以獲取 sox encodinginfo 選項(xiàng)。
參數(shù)
i (int , 可選)–選擇類(lèi)型或獲取具有所有可能選項(xiàng)的字典,請(qǐng)使用__members__
查看未指定的所有選項(xiàng)。 (默認(rèn):sox_false
或0
)
退貨
sox_bool 類(lèi)型
返回類(lèi)型
sox_bool
torchaudio.get_sox_encoding_t(i=None)?
獲取 sox 編碼的 sox_encoding_t 枚舉。
Parameters
i (int , 可選)–選擇類(lèi)型或獲取具有所有可能選項(xiàng)的字典,請(qǐng)使用__members__
查看未指定的所有選項(xiàng)。 (默認(rèn):None
)
Returns
用于輸出編碼的 sox_encoding_t 類(lèi)型
Return type
sox_encoding_t
torchaudio.get_sox_option_t(i=2)?
獲取 sox encodinginfo 選項(xiàng)的 sox_option_t 枚舉。
Parameters
i (int , 可選)–選擇類(lèi)型或獲取具有所有可能選項(xiàng)的字典,請(qǐng)使用__members__
查看未指定的所有選項(xiàng)。 (默認(rèn):sox_option_default
或2
)
Returns
sox_option_t 類(lèi)型
Return type
sox_option_t
torchaudio.info(filepath)?
從音頻文件獲取元數(shù)據(jù),而不加載信號(hào)。
Parameters
文件路徑 (str)–音頻文件的路徑
Returns
si(sox_signalinfo_t)信號(hào)信息作為 python 對(duì)象。 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 以與效果鏈一起使用。 對(duì)于簡(jiǎn)單加載,這不是必需的。 重要的是,只運(yùn)行一次 <cite>initialize_sox</cite> ,并且不要在每個(gè)效果鏈之后都關(guān)閉,而是在完成所有效果鏈后才關(guān)閉。
torchaudio.load(filepath, out=None, normalization=True, channels_first=True, num_frames=0, offset=0, signalinfo=None, encodinginfo=None, filetype=None)?
將音頻文件從磁盤(pán)加載到張量
Parameters
None
)True
)True
)0
)0
)None
)None
)None
)Returns
大小為 <cite>[C x L]</cite> 或 <cite>[L x C]</cite> 的輸出張量,其中 L 是音頻幀數(shù),C 是聲道數(shù)。 一個(gè)整數(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 文件每個(gè)樣本使用 16 位,需要通過(guò)將輸入右移 16 位來(lái)進(jìn)行歸一化。
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)?
將音頻信號(hào)的張量以 mp3,wav 等標(biāo)準(zhǔn)格式保存到磁盤(pán)。
Parameters
True
)None
)None
)None
)Example
>>> data, sample_rate = torchaudio.load('foo.mp3')
>>> torchaudio.save('foo.wav', data, sample_rate)
torchaudio.shutdown_sox()?
攤牌襪效果鏈。 簡(jiǎn)單加載不需要。 重要的是,只能撥打一次。 嘗試重新初始化 sox 將導(dǎo)致段錯(cuò)誤。
torchaudio.sox_encodinginfo_t()?
創(chuàng)建一個(gè) sox_encodinginfo_t 對(duì)象。 該對(duì)象可用于設(shè)置編碼類(lèi)型,位精度,壓縮系數(shù),反向字節(jié),反向半字節(jié),反向位和字節(jié)序。 可以在效果鏈中使用它來(lái)對(duì)最終輸出進(jìn)行編碼或使用特定編碼保存文件。 例如,可以使用 sox ulaw 編碼進(jìn)行 8 位 ulaw 編碼。 請(qǐng)注意,在張量輸出中,結(jié)果將是 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)建一個(gè) sox_signalinfo_t 對(duì)象。 該對(duì)象可用于設(shè)置效果的采樣率,通道數(shù),長(zhǎng)度,位精度和凈空倍數(shù)
Returns: sox_signalinfo_t(object)
None
無(wú)乘數(shù)Example
>>> si = torchaudio.sox_signalinfo_t()
>>> si.channels = 1
>>> si.rate = 16000.
>>> si.precision = 16
>>> si.length = 0
更多建議: