Anita-19 commited on
Commit
df98826
Β·
verified Β·
1 Parent(s): a95975f

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +21 -21
main.py CHANGED
@@ -53,6 +53,27 @@ def generate_emotional_speech(text, emotion):
53
  "shame": {"pitch": 0.8, "speed": 0.85}, # Quiet, subdued tone
54
 
55
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
56
 
57
  # Retrieve pitch and speed based on detected emotion
58
  settings = emotion_settings.get(emotion, {"pitch": 1.0, "speed": 1.0})
@@ -250,27 +271,6 @@ save_path = "/content/drive/My Drive/fine_tuned_tacotron2.pth"
250
  # Save the model's state dictionary using torch.save
251
  torch.save(model.state_dict(), save_path)
252
 
253
- import librosa
254
- import soundfile as sf
255
-
256
- def adjust_pitch(audio_path, pitch_factor):
257
- # Load audio
258
- y, sr = librosa.load(audio_path)
259
- # Adjust pitch
260
- y_shifted = librosa.effects.pitch_shift(y, sr, n_steps=pitch_factor)
261
- # Save adjusted audio
262
- sf.write(audio_path, y_shifted, sr)
263
-
264
- def adjust_speed(audio_path, speed_factor):
265
- # Load the audio file
266
- y, sr = librosa.load(audio_path)
267
-
268
- # Adjust the speed (this alters the duration of the audio)
269
- y_speeded = librosa.effects.time_stretch(y, speed_factor)
270
-
271
- # Save the adjusted audio
272
- sf.write(audio_path, y_speeded, sr)
273
-
274
 
275
  """Set up the Gradio interface"""
276
 
 
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})
 
271
  # Save the model's state dictionary using torch.save
272
  torch.save(model.state_dict(), save_path)
273
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
274
 
275
  """Set up the Gradio interface"""
276