Opera8 commited on
Commit
619d3cc
·
verified ·
1 Parent(s): e43ceb5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -9
app.py CHANGED
@@ -154,7 +154,25 @@ if os.path.dirname(os.path.abspath("Amphion")) not in sys.path:
154
  os.makedirs("wav", exist_ok=True)
155
  os.makedirs("ckpts/Vevo", exist_ok=True)
156
 
157
- from models.vc.vevo.vevo_utils import VevoInferencePipeline, save_audio, load_wav
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
158
 
159
  # Download and setup config files
160
  def setup_configs():
@@ -623,8 +641,8 @@ def vevo_style(content_wav, style_wav):
623
 
624
  print(f"Generated audio shape: {gen_audio.shape}, max: {torch.max(gen_audio)}, min: {torch.min(gen_audio)}")
625
 
626
- # Save generated audio
627
- save_audio(gen_audio, output_path=output_path)
628
 
629
  return output_path
630
  except Exception as e:
@@ -717,8 +735,8 @@ def vevo_timbre(content_wav, reference_wav):
717
 
718
  print(f"Generated audio shape: {gen_audio.shape}, max: {torch.max(gen_audio)}, min: {torch.min(gen_audio)}")
719
 
720
- # Save generated audio
721
- save_audio(gen_audio, output_path=output_path)
722
 
723
  return output_path
724
  except Exception as e:
@@ -839,8 +857,8 @@ def vevo_voice(content_wav, style_reference_wav, timbre_reference_wav):
839
 
840
  print(f"Generated audio shape: {gen_audio.shape}, max: {torch.max(gen_audio)}, min: {torch.min(gen_audio)}")
841
 
842
- # Save generated audio
843
- save_audio(gen_audio, output_path=output_path)
844
 
845
  return output_path
846
  except Exception as e:
@@ -942,8 +960,8 @@ def vevo_tts(text, ref_wav, timbre_ref_wav=None, style_ref_text=None, src_langua
942
 
943
  print(f"Generated audio shape: {gen_audio.shape}, max: {torch.max(gen_audio)}, min: {torch.min(gen_audio)}")
944
 
945
- # Save generated audio
946
- save_audio(gen_audio, output_path=output_path)
947
 
948
  return output_path
949
  except Exception as e:
 
154
  os.makedirs("wav", exist_ok=True)
155
  os.makedirs("ckpts/Vevo", exist_ok=True)
156
 
157
+ # IMPORTANT: Do NOT import save_audio from vevo_utils because it uses torchaudio.save which crashes
158
+ from models.vc.vevo.vevo_utils import VevoInferencePipeline, load_wav
159
+
160
+ # Define a custom save_audio function using soundfile directly to avoid TorchCodec errors
161
+ def my_save_audio(waveform, output_path, sample_rate=24000):
162
+ try:
163
+ # Move to CPU and detach
164
+ if isinstance(waveform, torch.Tensor):
165
+ waveform = waveform.detach().cpu()
166
+ # Handle shapes [1, T] -> [T]
167
+ if waveform.dim() == 2 and waveform.shape[0] == 1:
168
+ waveform = waveform.squeeze(0)
169
+ waveform = waveform.numpy()
170
+
171
+ sf.write(output_path, waveform, sample_rate)
172
+ print(f"Audio saved successfully to {output_path}")
173
+ except Exception as e:
174
+ print(f"Failed to save audio with soundfile: {e}")
175
+ raise e
176
 
177
  # Download and setup config files
178
  def setup_configs():
 
641
 
642
  print(f"Generated audio shape: {gen_audio.shape}, max: {torch.max(gen_audio)}, min: {torch.min(gen_audio)}")
643
 
644
+ # Save generated audio using custom function
645
+ my_save_audio(gen_audio, output_path=output_path)
646
 
647
  return output_path
648
  except Exception as e:
 
735
 
736
  print(f"Generated audio shape: {gen_audio.shape}, max: {torch.max(gen_audio)}, min: {torch.min(gen_audio)}")
737
 
738
+ # Save generated audio using custom function
739
+ my_save_audio(gen_audio, output_path=output_path)
740
 
741
  return output_path
742
  except Exception as e:
 
857
 
858
  print(f"Generated audio shape: {gen_audio.shape}, max: {torch.max(gen_audio)}, min: {torch.min(gen_audio)}")
859
 
860
+ # Save generated audio using custom function
861
+ my_save_audio(gen_audio, output_path=output_path)
862
 
863
  return output_path
864
  except Exception as e:
 
960
 
961
  print(f"Generated audio shape: {gen_audio.shape}, max: {torch.max(gen_audio)}, min: {torch.min(gen_audio)}")
962
 
963
+ # Save generated audio using custom function
964
+ my_save_audio(gen_audio, output_path=output_path)
965
 
966
  return output_path
967
  except Exception as e: