cnph001 commited on
Commit
d358db3
·
verified ·
1 Parent(s): 26d60e8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -2
app.py CHANGED
@@ -120,15 +120,33 @@ async def generate_audio_with_voice_prefix(text_segment, default_voice, rate, pi
120
  if speed_factor > 0:
121
  if speed_factor < 1.0:
122
  speed_factor = 1.0
 
 
123
  y, sr = librosa.load(audio_path, sr=None)
124
 
 
 
 
 
125
  # Use the phase vocoder for time stretching without pitch change
126
  hop_length = 512 # You can adjust this parameter
127
  phase_vocoder_output = librosa.phase_vocoder(y, rate=speed_factor, hop_length=hop_length)
128
 
129
- # Reconstruct the audio signal from the phase vocoder output
130
- y_stretched = librosa.istft(phase_vocoder_output, hop_length=hop_length, length=len(y) if speed_factor < 1 else None)
 
131
 
 
 
 
 
 
 
 
 
 
 
 
132
  sf.write(audio_path, y_stretched, sr)
133
 
134
  else:
 
120
  if speed_factor > 0:
121
  if speed_factor < 1.0:
122
  speed_factor = 1.0
123
+
124
+ # Load the audio file
125
  y, sr = librosa.load(audio_path, sr=None)
126
 
127
+ # Check if audio loading was successful
128
+ if y is None or sr is None:
129
+ raise ValueError(f"Error loading audio file: {audio_path}")
130
+
131
  # Use the phase vocoder for time stretching without pitch change
132
  hop_length = 512 # You can adjust this parameter
133
  phase_vocoder_output = librosa.phase_vocoder(y, rate=speed_factor, hop_length=hop_length)
134
 
135
+ # Check the shape of the phase vocoder output
136
+ if phase_vocoder_output is None or len(phase_vocoder_output) == 0:
137
+ raise ValueError("Phase vocoder output is empty or None.")
138
 
139
+ # Reconstruct the audio signal from the phase vocoder output
140
+ try:
141
+ # Check if length is properly handled, based on speed_factor
142
+ if speed_factor < 1:
143
+ y_stretched = librosa.istft(phase_vocoder_output, hop_length=hop_length, length=len(y))
144
+ else:
145
+ y_stretched = librosa.istft(phase_vocoder_output, hop_length=hop_length)
146
+ except Exception as e:
147
+ raise ValueError(f"Error during istft: {e}")
148
+
149
+ # Save the time-stretched audio to the file
150
  sf.write(audio_path, y_stretched, sr)
151
 
152
  else: