Anita-19 commited on
Commit
4fd5ac6
Β·
verified Β·
1 Parent(s): 20dae0d

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +22 -20
main.py CHANGED
@@ -53,27 +53,7 @@ def generate_emotional_speech(text, emotion):
53
  "shame": {"pitch": 0.8, "speed": 0.85}, # Quiet, subdued tone
54
 
55
  }
56
-
57
- import librosa
58
- import soundfile as sf
59
 
60
- def adjust_pitch(audio_path, pitch_factor):
61
- # Load audio
62
- y, sr = librosa.load(audio_path)
63
- # Adjust pitch
64
- y_shifted = librosa.effects.pitch_shift(y, sr, n_steps=pitch_factor)
65
- # Save adjusted audio
66
- sf.write(audio_path, y_shifted, sr)
67
-
68
- def adjust_speed(audio_path, speed_factor):
69
- # Load the audio file
70
- y, sr = librosa.load(audio_path)
71
-
72
- # Adjust the speed (this alters the duration of the audio)
73
- y_speeded = librosa.effects.time_stretch(y, speed_factor)
74
-
75
- # Save the adjusted audio
76
- sf.write(audio_path, y_speeded, sr)
77
 
78
  # Retrieve pitch and speed based on detected emotion
79
  settings = emotion_settings.get(emotion, {"pitch": 1.0, "speed": 1.0})
@@ -272,6 +252,28 @@ save_path = "/content/drive/My Drive/fine_tuned_tacotron2.pth"
272
  torch.save(model.state_dict(), save_path)
273
 
274
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
275
  """Set up the Gradio interface"""
276
 
277
  import gradio as gr
 
53
  "shame": {"pitch": 0.8, "speed": 0.85}, # Quiet, subdued tone
54
 
55
  }
 
 
 
56
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
57
 
58
  # Retrieve pitch and speed based on detected emotion
59
  settings = emotion_settings.get(emotion, {"pitch": 1.0, "speed": 1.0})
 
252
  torch.save(model.state_dict(), save_path)
253
 
254
 
255
+ import librosa
256
+ import soundfile as sf
257
+
258
+ def adjust_pitch(audio_path, pitch_factor):
259
+ # Load audio
260
+ y, sr = librosa.load(audio_path)
261
+ # Adjust pitch
262
+ y_shifted = librosa.effects.pitch_shift(y, sr, n_steps=pitch_factor)
263
+ # Save adjusted audio
264
+ sf.write(audio_path, y_shifted, sr)
265
+
266
+ def adjust_speed(audio_path, speed_factor):
267
+ # Load the audio file
268
+ y, sr = librosa.load(audio_path)
269
+
270
+ # Adjust the speed (this alters the duration of the audio)
271
+ y_speeded = librosa.effects.time_stretch(y, speed_factor)
272
+
273
+ # Save the adjusted audio
274
+ sf.write(audio_path, y_speeded, sr)
275
+
276
+
277
  """Set up the Gradio interface"""
278
 
279
  import gradio as gr