mrfakename commited on
Commit
0408757
1 Parent(s): bc11545

resample 22khz fix

Browse files
Files changed (1) hide show
  1. app.py +9 -9
app.py CHANGED
@@ -530,12 +530,9 @@ def doloudnorm(path):
530
  loudness = meter.integrated_loudness(data)
531
  loudness_normalized_audio = pyln.normalize.loudness(data, loudness, -12.0)
532
  sf.write(path, loudness_normalized_audio, rate)
533
- def doresample(path_to_wav):
534
- y, sr = librosa.load(path_to_wav, sr=None)
535
- if sr > 24000:
536
- y_resampled = librosa.resample(y, sr, 24000)
537
- librosa.output.write_wav(path_to_wav, y_resampled, 24000)
538
 
 
 
539
  ##########################
540
  # 2x speedup (hopefully) #
541
  ##########################
@@ -570,13 +567,16 @@ def synthandreturn(text):
570
  except:
571
  raise gr.Error('Unable to call API, please try again :)')
572
  print('Done with', model)
573
- try:
574
- doresample(result)
575
- except:
576
- pass
577
  try:
578
  with tempfile.NamedTemporaryFile(suffix='.wav', delete=False) as f:
579
  audio = AudioSegment.from_file(result)
 
 
 
580
  try:
581
  print('Trying to normalize audio')
582
  audio = match_target_amplitude(audio, -20)
 
530
  loudness = meter.integrated_loudness(data)
531
  loudness_normalized_audio = pyln.normalize.loudness(data, loudness, -12.0)
532
  sf.write(path, loudness_normalized_audio, rate)
 
 
 
 
 
533
 
534
+ def doresample(path_to_wav):
535
+ pass
536
  ##########################
537
  # 2x speedup (hopefully) #
538
  ##########################
 
567
  except:
568
  raise gr.Error('Unable to call API, please try again :)')
569
  print('Done with', model)
570
+ # try:
571
+ # doresample(result)
572
+ # except:
573
+ # pass
574
  try:
575
  with tempfile.NamedTemporaryFile(suffix='.wav', delete=False) as f:
576
  audio = AudioSegment.from_file(result)
577
+ current_sr = audio.frame_rate
578
+ if current_sr > 24000:
579
+ audio = audio.set_frame_rate(24000)
580
  try:
581
  print('Trying to normalize audio')
582
  audio = match_target_amplitude(audio, -20)