torchaudio 0.2.1 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9ed4c14921f1eee18f5e08ddabfae51e09a9b5a7ef408f1dd67fdf7bfe9622fe
4
- data.tar.gz: 1e37d5b9abed9cab7bf56a8c30a769bc8ff8f8a3e15e78bbb772847c444571b2
3
+ metadata.gz: 40ba5316b924f832befcf352c040528b48da458f53e0a5087530c06604bf7f48
4
+ data.tar.gz: 6235bf05e51dcb4ec1f63596085243e97ed02cde73a5504c5ced1b03a4679434
5
5
  SHA512:
6
- metadata.gz: 9ca5436d7e4309dd9659fdce7ee893b122e9da96e9f7b15bf00de5dea32c635e2828a99939f04ef5bf0d9494ab89957829a65002dc3e855fa8a66f54abbbd181
7
- data.tar.gz: d62b2a137c19d3b24facb11eda5c1b81be5841120b505877b8617bee2b9f183dbe4b4d42a95af27447346a3d48476d7faec48b57cd89b88c0ddc9709f1b5d51b
6
+ metadata.gz: c2ec8ae3f0a4fbfb242cf718624828bec8d8b1b741ff119836e7087ea98de43498377c9838eddcb73337db7a56c0d612232aaf7f95d65b7ea05173e93dfae7b8
7
+ data.tar.gz: 02c22f6eeb6bb037ff1d69d781861a60c29bd6f35e4ef76d1793cfb5b9f1696f6309208ec748f6736dd61239f820c65b1a02859c950cff3b2fd97d3fa96bd2f3
data/CHANGELOG.md CHANGED
@@ -1,3 +1,12 @@
1
+ ## 0.3.1 (2023-01-29)
2
+
3
+ - Added `format` option
4
+
5
+ ## 0.3.0 (2022-07-06)
6
+
7
+ - Added `center`, `pad_mode`, and `onesided` options to `Spectogram` transform
8
+ - Dropped support for Ruby < 2.7
9
+
1
10
  ## 0.2.1 (2021-07-16)
2
11
 
3
12
  - Added `create_dct` method
data/LICENSE.txt CHANGED
@@ -1,7 +1,7 @@
1
1
  BSD 2-Clause License
2
2
 
3
3
  Copyright (c) 2017 Facebook Inc. (Soumith Chintala),
4
- Copyright (c) 2020-2021 Andrew Kane,
4
+ Copyright (c) 2020-2022 Andrew Kane,
5
5
  All rights reserved.
6
6
 
7
7
  Redistribution and use in source and binary forms, with or without
data/README.md CHANGED
@@ -1,8 +1,8 @@
1
- # TorchAudio
1
+ # TorchAudio Ruby
2
2
 
3
3
  :fire: An audio library for Torch.rb
4
4
 
5
- [![Build Status](https://github.com/ankane/torchaudio/workflows/build/badge.svg?branch=master)](https://github.com/ankane/torchaudio/actions)
5
+ [![Build Status](https://github.com/ankane/torchaudio-ruby/workflows/build/badge.svg?branch=master)](https://github.com/ankane/torchaudio-ruby/actions)
6
6
 
7
7
  ## Installation
8
8
 
@@ -15,7 +15,7 @@ brew install sox
15
15
  Add this line to your application’s Gemfile:
16
16
 
17
17
  ```ruby
18
- gem 'torchaudio'
18
+ gem "torchaudio"
19
19
  ```
20
20
 
21
21
  ## Getting Started
@@ -134,22 +134,22 @@ addons:
134
134
 
135
135
  ## History
136
136
 
137
- View the [changelog](https://github.com/ankane/torchaudio/blob/master/CHANGELOG.md)
137
+ View the [changelog](https://github.com/ankane/torchaudio-ruby/blob/master/CHANGELOG.md)
138
138
 
139
139
  ## Contributing
140
140
 
141
141
  Everyone is encouraged to help improve this project. Here are a few ways you can help:
142
142
 
143
- - [Report bugs](https://github.com/ankane/torchaudio/issues)
144
- - Fix bugs and [submit pull requests](https://github.com/ankane/torchaudio/pulls)
143
+ - [Report bugs](https://github.com/ankane/torchaudio-ruby/issues)
144
+ - Fix bugs and [submit pull requests](https://github.com/ankane/torchaudio-ruby/pulls)
145
145
  - Write, clarify, or fix documentation
146
146
  - Suggest or add new features
147
147
 
148
148
  To get started with development:
149
149
 
150
150
  ```sh
151
- git clone https://github.com/ankane/torchaudio.git
152
- cd torchaudio
151
+ git clone https://github.com/ankane/torchaudio-ruby.git
152
+ cd torchaudio-ruby
153
153
  bundle install
154
154
  bundle exec rake compile
155
155
  bundle exec rake test
@@ -20,18 +20,9 @@ $CXXFLAGS += " -D_GLIBCXX_USE_CXX11_ABI=1"
20
20
 
21
21
  apple_clang = RbConfig::CONFIG["CC_VERSION_MESSAGE"] =~ /apple clang/i
22
22
 
23
- # check omp first
24
- if have_library("omp") || have_library("gomp")
25
- $CXXFLAGS += " -Xclang" if apple_clang
26
- $CXXFLAGS += " -fopenmp"
27
- end
28
-
29
23
  if apple_clang
30
- # silence ruby/intern.h warning
31
- $CXXFLAGS += " -Wno-deprecated-register"
32
-
33
24
  # silence torch warnings
34
- $CXXFLAGS += " -Wno-shorten-64-to-32 -Wno-missing-noreturn"
25
+ $CXXFLAGS += " -Wno-deprecated-declarations"
35
26
  else
36
27
  # silence rice warnings
37
28
  $CXXFLAGS += " -Wno-noexcept-type"
@@ -15,7 +15,9 @@ module TorchAudio
15
15
  end
16
16
 
17
17
  # follows redirects
18
- def download_url_to_file(url, dst, hash_value, hash_type)
18
+ def download_url_to_file(url, dst, hash_value, hash_type, redirects = 0)
19
+ raise "Too many redirects" if redirects > 10
20
+
19
21
  uri = URI(url)
20
22
  tmp = nil
21
23
  location = nil
@@ -41,7 +43,7 @@ module TorchAudio
41
43
  end
42
44
 
43
45
  if location
44
- download_url_to_file(location, dst)
46
+ download_url_to_file(location, dst, hash_value, hash_type, redirects + 1)
45
47
  else
46
48
  # check hash
47
49
  # TODO use hash_type
@@ -1,7 +1,7 @@
1
1
  module TorchAudio
2
2
  module Functional
3
3
  class << self
4
- def spectrogram(waveform, pad, window, n_fft, hop_length, win_length, power, normalized)
4
+ def spectrogram(waveform, pad, window, n_fft, hop_length, win_length, power, normalized, center: true, pad_mode: "reflect", onesided: true)
5
5
  if pad > 0
6
6
  # TODO add "with torch.no_grad():" back when JIT supports it
7
7
  waveform = Torch::NN::Functional.pad(waveform, [pad, pad], "constant")
@@ -19,22 +19,25 @@ module TorchAudio
19
19
  hop_length: hop_length,
20
20
  win_length: win_length,
21
21
  window: window,
22
- center: true,
23
- pad_mode: "reflect",
22
+ center: center,
23
+ pad_mode: pad_mode,
24
24
  normalized: false,
25
- onesided: true
25
+ onesided: onesided,
26
+ return_complex: true
26
27
  )
27
28
 
28
29
  # unpack batch
29
- spec_f = spec_f.reshape(shape[0..-2] + spec_f.shape[-3..-1])
30
+ spec_f = spec_f.reshape(shape[0..-2] + spec_f.shape[-2..-1])
30
31
 
31
32
  if normalized
32
- spec_f.div!(window.pow(2.0).sum.sqrt)
33
+ spec_f /= window.pow(2.0).sum.sqrt
33
34
  end
34
- if power
35
- spec_f = complex_norm(spec_f, power: power)
35
+ if !power.nil?
36
+ if power == 1
37
+ return spec_f.abs
38
+ end
39
+ return spec_f.abs.pow(power)
36
40
  end
37
-
38
41
  spec_f
39
42
  end
40
43
 
@@ -3,7 +3,8 @@ module TorchAudio
3
3
  class Spectrogram < Torch::NN::Module
4
4
  def initialize(
5
5
  n_fft: 400, win_length: nil, hop_length: nil, pad: 0,
6
- window_fn: Torch.method(:hann_window), power: 2.0, normalized: false, wkwargs: nil
6
+ window_fn: Torch.method(:hann_window), power: 2.0, normalized: false, wkwargs: nil,
7
+ center: true, pad_mode: "reflect", onesided: true
7
8
  )
8
9
 
9
10
  super()
@@ -17,10 +18,16 @@ module TorchAudio
17
18
  @pad = pad
18
19
  @power = power
19
20
  @normalized = normalized
21
+ @center = center
22
+ @pad_mode = pad_mode
23
+ @onesided = onesided
20
24
  end
21
25
 
22
26
  def forward(waveform)
23
- F.spectrogram(waveform, @pad, @window, @n_fft, @hop_length, @win_length, @power, @normalized)
27
+ F.spectrogram(
28
+ waveform, @pad, @window, @n_fft, @hop_length, @win_length, @power, @normalized,
29
+ center: @center, pad_mode: @pad_mode, onesided: @onesided
30
+ )
24
31
  end
25
32
  end
26
33
  end
@@ -1,3 +1,3 @@
1
1
  module TorchAudio
2
- VERSION = "0.2.1"
2
+ VERSION = "0.3.1"
3
3
  end
data/lib/torchaudio.rb CHANGED
@@ -31,9 +31,10 @@ module TorchAudio
31
31
  class Error < StandardError; end
32
32
 
33
33
  class << self
34
+ # TODO remove filetype in 0.4.0
34
35
  def load(
35
36
  filepath, out: nil, normalization: true, channels_first: true, num_frames: 0,
36
- offset: 0, signalinfo: nil, encodinginfo: nil, filetype: nil
37
+ offset: 0, signalinfo: nil, encodinginfo: nil, filetype: nil, format: nil
37
38
  )
38
39
 
39
40
  filepath = filepath.to_s
@@ -59,7 +60,7 @@ module TorchAudio
59
60
 
60
61
  # same logic as C++
61
62
  # could also make read_audio_file work with nil
62
- filetype ||= File.extname(filepath)[1..-1]
63
+ format ||= filetype || File.extname(filepath)[1..-1]
63
64
 
64
65
  sample_rate =
65
66
  Ext.read_audio_file(
@@ -70,7 +71,7 @@ module TorchAudio
70
71
  offset,
71
72
  signalinfo,
72
73
  encodinginfo,
73
- filetype
74
+ format
74
75
  )
75
76
 
76
77
  # normalize if needed
@@ -95,7 +96,7 @@ module TorchAudio
95
96
  end
96
97
 
97
98
  def save_encinfo(filepath, src, channels_first: true, signalinfo: nil, encodinginfo: nil, filetype: nil)
98
- ch_idx, len_idx = channels_first ? [0, 1] : [1, 0]
99
+ ch_idx, _len_idx = channels_first ? [0, 1] : [1, 0]
99
100
 
100
101
  # check if save directory exists
101
102
  abs_dirpath = File.dirname(File.expand_path(filepath))
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: torchaudio
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Kane
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-07-16 00:00:00.000000000 Z
11
+ date: 2023-01-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: torch-rb
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 0.7.0
19
+ version: 0.11.1
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 0.7.0
26
+ version: 0.11.1
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rice
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -74,7 +74,7 @@ files:
74
74
  - lib/torchaudio/transforms/spectrogram.rb
75
75
  - lib/torchaudio/transforms/vol.rb
76
76
  - lib/torchaudio/version.rb
77
- homepage: https://github.com/ankane/torchaudio
77
+ homepage: https://github.com/ankane/torchaudio-ruby
78
78
  licenses:
79
79
  - BSD-2-Clause
80
80
  metadata: {}
@@ -86,14 +86,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - ">="
88
88
  - !ruby/object:Gem::Version
89
- version: '2.6'
89
+ version: '2.7'
90
90
  required_rubygems_version: !ruby/object:Gem::Requirement
91
91
  requirements:
92
92
  - - ">="
93
93
  - !ruby/object:Gem::Version
94
94
  version: '0'
95
95
  requirements: []
96
- rubygems_version: 3.2.22
96
+ rubygems_version: 3.4.1
97
97
  signing_key:
98
98
  specification_version: 4
99
99
  summary: Data manipulation and transformation for audio signal processing