Module: TorchAudio
- Defined in:
- lib/torchaudio.rb,
lib/torchaudio/version.rb,
lib/torchaudio/datasets/utils.rb,
lib/torchaudio/datasets/yesno.rb
Defined Under Namespace
Modules: Datasets Classes: Error
Constant Summary collapse
- VERSION =
"0.1.0"
Class Method Summary collapse
- .load(filepath, out: nil, normalization: true, channels_first: true, num_frames: 0, offset: 0, signalinfo: nil, encodinginfo: nil, filetype: nil) ⇒ Object
- .load_wav(filepath, **kwargs) ⇒ Object
Class Method Details
.load(filepath, out: nil, normalization: true, channels_first: true, num_frames: 0, offset: 0, signalinfo: nil, encodinginfo: nil, filetype: nil) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/torchaudio.rb', line 23 def load( filepath, out: nil, normalization: true, channels_first: true, num_frames: 0, offset: 0, signalinfo: nil, encodinginfo: nil, filetype: nil ) filepath = filepath.to_s # check if valid file unless File.exist?(filepath) raise ArgumentError, "#{filepath} not found or is a directory" end # initialize output tensor if !out.nil? check_input(out) else out = Torch::FloatTensor.new end if num_frames < -1 raise ArgumentError, "Expected value for num_samples -1 (entire file) or >=0" end if offset < 0 raise ArgumentError, "Expected positive offset value" end # same logic as C++ # could also make read_audio_file work with nil filetype ||= File.extname(filepath)[1..-1] sample_rate = Ext.read_audio_file( filepath, out, channels_first, num_frames, offset, signalinfo, encodinginfo, filetype ) # normalize if needed normalize_audio(out, normalization) [out, sample_rate] end |
.load_wav(filepath, **kwargs) ⇒ Object
71 72 73 74 |
# File 'lib/torchaudio.rb', line 71 def load_wav(filepath, **kwargs) kwargs[:normalization] = 1 << 16 load(filepath, **kwargs) end |