yunusajib commited on
Commit
0513e21
·
verified ·
1 Parent(s): aa86df9
Files changed (1) hide show
  1. app.py +18 -4
app.py CHANGED
@@ -9,6 +9,8 @@ import scipy.io.wavfile as wavfile
9
  from sklearn.preprocessing import StandardScaler
10
  import time
11
  import os
 
 
12
 
13
  # ------------------- Speech Emotion Recognition Model -------------------
14
  class SpeechEmotionRecognizer:
@@ -47,11 +49,23 @@ class FacialEmotionRecognizer:
47
  return self.labels[emotion_idx]
48
 
49
  # ------------------- Utility Functions -------------------
 
 
50
  def speak(text):
51
- engine = pyttsx3.init()
52
- engine.setProperty('rate', 150)
53
- engine.say(text)
54
- engine.runAndWait()
 
 
 
 
 
 
 
 
 
 
55
 
56
  def record_audio(duration=3, fs=22050):
57
  print("Recording audio...")
 
9
  from sklearn.preprocessing import StandardScaler
10
  import time
11
  import os
12
+ from gtts import gTTS
13
+ import gradio as gr
14
 
15
  # ------------------- Speech Emotion Recognition Model -------------------
16
  class SpeechEmotionRecognizer:
 
49
  return self.labels[emotion_idx]
50
 
51
  # ------------------- Utility Functions -------------------
52
+
53
+
54
  def speak(text):
55
+ if not text.strip():
56
+ return None
57
+ tts = gTTS(text)
58
+ tts.save("output.mp3")
59
+ return "output.mp3"
60
+
61
+ iface = gr.Interface(
62
+ fn=speak,
63
+ inputs=gr.Textbox(lines=2, label="Enter text"),
64
+ outputs=gr.Audio(type="filepath", label="Speech Output"),
65
+ title="Text to Speech"
66
+ )
67
+
68
+ iface.launch()
69
 
70
  def record_audio(duration=3, fs=22050):
71
  print("Recording audio...")