cnph001 commited on
Commit
c411b7a
·
verified ·
1 Parent(s): ed3d5af

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -8
app.py CHANGED
@@ -10,6 +10,9 @@ from pydub import AudioSegment
10
  import librosa
11
  import soundfile as sf
12
  import numpy as np
 
 
 
13
 
14
  def get_silence(duration_ms=1000):
15
  # Create silent audio segment with specified parameters
@@ -110,15 +113,14 @@ async def generate_audio_with_voice_prefix(text_segment, default_voice, rate, pi
110
  if speed_factor > 0:
111
  if speed_factor < 1.0:
112
  speed_factor = 1.0
113
- y, sr = librosa.load(audio_path, sr=None)
114
 
115
- # Apply phase vocoder to stretch the audio
116
- hop_length = 512 # Hop length, you can experiment with this
117
- y_stretched = librosa.phase_vocoder(y, rate=speed_factor, hop_length=hop_length)
118
- # Reconstruct the audio using ISTFT
119
- y_reconstructed = librosa.istft(y_stretched, hop_length=hop_length)
120
- # Save the stretched audio back to a file
121
- sf.write(audio_path, y_reconstructed, sr)
122
 
123
  #y_stretched = librosa.effects.time_stretch(y, rate=speed_factor)
124
  #sf.write(audio_path, y_stretched, sr)
 
10
  import librosa
11
  import soundfile as sf
12
  import numpy as np
13
+ from pydub import AudioSegment
14
+ from pydub.playback import play
15
+
16
 
17
  def get_silence(duration_ms=1000):
18
  # Create silent audio segment with specified parameters
 
113
  if speed_factor > 0:
114
  if speed_factor < 1.0:
115
  speed_factor = 1.0
116
+ #y, sr = librosa.load(audio_path, sr=None)
117
 
118
+ # Load audio file
119
+ audio = AudioSegment.from_file(audio_path)
120
+ # Apply time-stretching
121
+ audio_stretched = audio.speedup(playback_speed=speed_factor)
122
+ # Save the stretched audio
123
+ audio_stretched.export(audio_path, format="mp3")
 
124
 
125
  #y_stretched = librosa.effects.time_stretch(y, rate=speed_factor)
126
  #sf.write(audio_path, y_stretched, sr)