czyoung commited on
Commit
bc2fc31
·
verified ·
1 Parent(s): 0172dbd

Update sonogram_utility.py

Browse files
Files changed (1) hide show
  1. sonogram_utility.py +5 -0
sonogram_utility.py CHANGED
@@ -119,10 +119,13 @@ def splitIntoTimeSegments(testFile,maxDurationInSeconds=60):
119
  return audioSegments, sample_rate
120
 
121
  def audioNormalize(waveform,sampleRate,stepSizeInSeconds = 2,dbThreshold = -50,dbTarget = -5):
 
122
  copyWaveform = waveform.clone().detach()
123
  copyWaveform_db = waveform.clone().detach()
 
124
  transform = torchaudio.transforms.AmplitudeToDB(stype="amplitude", top_db=80)
125
  copyWaveform_db = transform(copyWaveform_db)
 
126
  currStart = 0
127
  currEnd = int(min(currStart + stepSizeInSeconds * sampleRate, len(copyWaveform_db[0])-1))
128
  done = False
@@ -141,10 +144,12 @@ def audioNormalize(waveform,sampleRate,stepSizeInSeconds = 2,dbThreshold = -50,d
141
  done = True
142
  else:
143
  currEnd = int(min(currStart + stepSizeInSeconds * sampleRate, len(copyWaveform_db[0])-1))
 
144
  return copyWaveform
145
 
146
  class equalizeVolume(torch.nn.Module):
147
  def forward(self, waveform,sampleRate,stepSizeInSeconds,dbThreshold,dbTarget):
 
148
  waveformDifference = audioNormalize(waveform,sampleRate,stepSizeInSeconds,dbThreshold,dbTarget)
149
  return waveformDifference
150
 
 
119
  return audioSegments, sample_rate
120
 
121
  def audioNormalize(waveform,sampleRate,stepSizeInSeconds = 2,dbThreshold = -50,dbTarget = -5):
122
+ print("In audioNormalize")
123
  copyWaveform = waveform.clone().detach()
124
  copyWaveform_db = waveform.clone().detach()
125
+ print("Copies made")
126
  transform = torchaudio.transforms.AmplitudeToDB(stype="amplitude", top_db=80)
127
  copyWaveform_db = transform(copyWaveform_db)
128
+ print("DB levels calculated")
129
  currStart = 0
130
  currEnd = int(min(currStart + stepSizeInSeconds * sampleRate, len(copyWaveform_db[0])-1))
131
  done = False
 
144
  done = True
145
  else:
146
  currEnd = int(min(currStart + stepSizeInSeconds * sampleRate, len(copyWaveform_db[0])-1))
147
+ print("Waveform enhanced")
148
  return copyWaveform
149
 
150
  class equalizeVolume(torch.nn.Module):
151
  def forward(self, waveform,sampleRate,stepSizeInSeconds,dbThreshold,dbTarget):
152
+ print("In equalizeVolume")
153
  waveformDifference = audioNormalize(waveform,sampleRate,stepSizeInSeconds,dbThreshold,dbTarget)
154
  return waveformDifference
155