GokseninYuksel commited on
Commit
92d37f3
·
verified ·
1 Parent(s): 52e8777

Upload feature extractor

Browse files
feature_extraction_gramt_ambisonics.py CHANGED
@@ -106,6 +106,9 @@ class FeatureExtractor(torch.nn.Module):
106
  foa_aiv = self._get_foa_intensity_vectors(spec)
107
  return torch.cat([mel_spec, foa_aiv], dim = 1)
108
 
 
 
 
109
 
110
  class AmbisonicsFeatureExtractor(SequenceFeatureExtractor):
111
  r"""
@@ -162,6 +165,8 @@ class AmbisonicsFeatureExtractor(SequenceFeatureExtractor):
162
  )
163
 
164
  waveform = torch.tensor(waveform.clone().detach())
 
 
165
  # If waveform has two channels, but the channel information is not the first dimension, transpose.
166
  if (waveform.ndim == 2) and (waveform.shape[0] > 100):
167
  waveform = waveform.transpose(1, 0)
@@ -184,16 +189,6 @@ class AmbisonicsFeatureExtractor(SequenceFeatureExtractor):
184
  raise Exception("Unknowm channel count")
185
 
186
 
187
- def _normalize_audio(self, audio_data, target_dBFS=-14.0):
188
- rms = torch.sqrt(torch.mean(audio_data**2)) # Calculate the RMS of the audio
189
- if rms == 0: # Avoid division by zero in case of a completely silent audio
190
- return audio_data
191
- current_dBFS = 20 * torch.log10(rms) # Convert RMS to dBFS
192
- gain_dB = target_dBFS - current_dBFS # Calculate the required gain in dB
193
- gain_linear = 10 ** (gain_dB / 20) # Convert gain from dB to linear scale
194
- normalized_audio = audio_data * gain_linear # Apply the gain to the audio data
195
- return normalized_audio
196
-
197
  def __call__(
198
  self,
199
  raw_speech: Union[np.ndarray, list[float], list[np.ndarray], list[list[float]]],
 
106
  foa_aiv = self._get_foa_intensity_vectors(spec)
107
  return torch.cat([mel_spec, foa_aiv], dim = 1)
108
 
109
+ def put_to_device(self, device):
110
+ self.spectrogram.to(device)
111
+
112
 
113
  class AmbisonicsFeatureExtractor(SequenceFeatureExtractor):
114
  r"""
 
165
  )
166
 
167
  waveform = torch.tensor(waveform.clone().detach())
168
+ melspec.to(waveform.device)
169
+ melspec.put_to_device(waveform.device)
170
  # If waveform has two channels, but the channel information is not the first dimension, transpose.
171
  if (waveform.ndim == 2) and (waveform.shape[0] > 100):
172
  waveform = waveform.transpose(1, 0)
 
189
  raise Exception("Unknowm channel count")
190
 
191
 
 
 
 
 
 
 
 
 
 
 
192
  def __call__(
193
  self,
194
  raw_speech: Union[np.ndarray, list[float], list[np.ndarray], list[list[float]]],