Or, if you have downloaded this repository on your machine, and
you are in its directory:
$ luarocks make
Usage
audio.load
loads an audio file into a torch.Tensor
usage:
audio.load(
string -- path to file
)
returns torch.Tensor of size NSamples x NChannels, sample_rate
audio.save
saves a tensor into an audio file. The extension of the given path is used as the saving format.
usage:
audio.save(
string -- path to file
tensor -- NSamples x NChannels 2D tensor
number -- sample_rate of the audio to be saved as
)
audio.compress
Compresses a tensor in-memory and returns a CharTensor. The extension of the given path is used as the saving format. This can be decompressed using the "decompress" method
usage:
audio.compress(__
tensor -- NSamples x NChannels 2D tensor
number -- sample_rate of the audio to be saved as
extension -- format of audio to compress in. Example: mp3, ogg, flac, sox etc.
)
audio.decompress
Decompresses a tensor in-memory and returns raw audio. The extension of the given path is used as the loading format.
usage:
audio.decompress(__
CharTensor -- 1D CharTensor that was returned by .compress
extension -- format of audio used to compress. Example: mp3, ogg, flac, sox etc.
)
audio.stft
calculate the stft of an audio. returns a 3D tensor, with number_of_windows x window_size/2+1 x 2(complex number with real and complex parts)
usage:
audio.stft(
torch.Tensor -- input single-channel audio
number -- window size
string -- window type: rect, hamming, hann, bartlett
number -- stride
)
audio.spectrogram
generate the spectrogram of an audio. returns a 2D tensor, with number_of_windows x window_size/2+1, each value representing the magnitude of each frequency in dB
usage:
audio.spectrogram(
torch.Tensor -- input single-channel audio
number -- window size
string -- window type: rect, hamming, hann, bartlett
number -- stride
)
Example Usage
Generate a spectrogram
require'audio'require'image'-- to display the spectrogram
voice = audio.samplevoice()
spect = audio.spectrogram(voice, 8192, 'hann', 512)
image.display(spect)
请发表评论