Anita-19 commited on
Commit
d0ae34f
Β·
verified Β·
1 Parent(s): 200d4a2

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +5 -17
main.py CHANGED
@@ -296,18 +296,6 @@ emotion_settings = {
296
  "shame": {"pitch": 0.8, "speed": 0.85},
297
  }
298
 
299
- import librosa
300
- import soundfile as sf
301
-
302
- def adjust_audio_speed(audio_path, speed_factor):
303
- y, sr = librosa.load(audio_path)
304
- y_speeded = librosa.effects.time_stretch(y, speed_factor)
305
- sf.write(audio_path, y_speeded, sr)
306
-
307
- def adjust_audio_pitch(audio_path, pitch_factor):
308
- y, sr = librosa.load(audio_path)
309
- y_shifted = librosa.effects.pitch_shift(y, sr, n_steps=pitch_factor)
310
- sf.write(audio_path, y_shifted, sr)
311
 
312
  def emotion_aware_tts_pipeline(input_text=None, file_input=None):
313
  try:
@@ -331,11 +319,10 @@ def emotion_aware_tts_pipeline(input_text=None, file_input=None):
331
  audio_path = "output.wav"
332
  tts_model.tts_to_file(text=input_text, file_path=audio_path)
333
 
334
- # Adjust pitch and speed using librosa
335
- if pitch != 1.0:
336
- adjust_audio_pitch(audio_path, pitch)
337
- if speed != 1.0:
338
- adjust_audio_speed(audio_path, speed)
339
 
340
  return f"Detected Emotion: {emotion} (Confidence: {confidence:.2f})", audio_path
341
  else:
@@ -344,6 +331,7 @@ def emotion_aware_tts_pipeline(input_text=None, file_input=None):
344
  return f"Error: {str(e)}", None
345
 
346
 
 
347
  # Define Gradio interface
348
  iface = gr.Interface(
349
  fn=emotion_aware_tts_pipeline,
 
296
  "shame": {"pitch": 0.8, "speed": 0.85},
297
  }
298
 
 
 
 
 
 
 
 
 
 
 
 
 
299
 
300
  def emotion_aware_tts_pipeline(input_text=None, file_input=None):
301
  try:
 
319
  audio_path = "output.wav"
320
  tts_model.tts_to_file(text=input_text, file_path=audio_path)
321
 
322
+ # Adjust pitch
323
+ pitch_factor = (pitch - 1.0) * 12 # Convert to semitones for librosa
324
+ adjust_pitch(audio_path, pitch_factor)
325
+
 
326
 
327
  return f"Detected Emotion: {emotion} (Confidence: {confidence:.2f})", audio_path
328
  else:
 
331
  return f"Error: {str(e)}", None
332
 
333
 
334
+
335
  # Define Gradio interface
336
  iface = gr.Interface(
337
  fn=emotion_aware_tts_pipeline,