Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
import os
|
2 |
import google.generativeai as genai
|
3 |
import speech_recognition as sr
|
4 |
-
import pyttsx3
|
5 |
from dotenv import load_dotenv
|
6 |
import gradio as gr
|
7 |
import tempfile
|
@@ -9,15 +9,12 @@ import tempfile
|
|
9 |
# Load environment variables
|
10 |
load_dotenv()
|
11 |
|
12 |
-
# Initialize text-to-speech engine
|
13 |
-
engine = pyttsx3.init()
|
14 |
-
|
15 |
def speak_and_save(text):
|
16 |
-
"""Use
|
17 |
-
|
|
|
18 |
audio_path = fp.name
|
19 |
-
|
20 |
-
engine.runAndWait()
|
21 |
return audio_path
|
22 |
|
23 |
def recognize_speech_from_audio(audio_file):
|
@@ -86,6 +83,6 @@ def assistant(audio):
|
|
86 |
gr.Interface(
|
87 |
fn=assistant, # Function to call when the interface is run
|
88 |
inputs=gr.Audio(type="filepath"), # Audio input, expecting a file path from the microphone
|
89 |
-
outputs=[gr.Textbox(), gr.Audio(type="filepath")], # Outputs text and the response audio
|
90 |
title="Sema Voice Assistant"
|
91 |
).launch()
|
|
|
1 |
import os
|
2 |
import google.generativeai as genai
|
3 |
import speech_recognition as sr
|
4 |
+
from gtts import gTTS # Replacing pyttsx3 with gTTS for text-to-speech
|
5 |
from dotenv import load_dotenv
|
6 |
import gradio as gr
|
7 |
import tempfile
|
|
|
9 |
# Load environment variables
|
10 |
load_dotenv()
|
11 |
|
|
|
|
|
|
|
12 |
def speak_and_save(text):
|
13 |
+
"""Use gTTS to speak the given text and save it as an audio file."""
|
14 |
+
tts = gTTS(text)
|
15 |
+
with tempfile.NamedTemporaryFile(delete=False, suffix=".mp3") as fp:
|
16 |
audio_path = fp.name
|
17 |
+
tts.save(audio_path)
|
|
|
18 |
return audio_path
|
19 |
|
20 |
def recognize_speech_from_audio(audio_file):
|
|
|
83 |
gr.Interface(
|
84 |
fn=assistant, # Function to call when the interface is run
|
85 |
inputs=gr.Audio(type="filepath"), # Audio input, expecting a file path from the microphone
|
86 |
+
outputs=[gr.Textbox(), gr.Audio(type="filepath", label="Response Audio")], # Outputs text and the response audio
|
87 |
title="Sema Voice Assistant"
|
88 |
).launch()
|