Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -4,6 +4,7 @@ import torch
|
|
4 |
import speech_recognition as sr
|
5 |
from transformers import pipeline
|
6 |
from gtts import gTTS
|
|
|
7 |
|
8 |
app = Flask(__name__)
|
9 |
recognizer = sr.Recognizer()
|
@@ -13,7 +14,7 @@ device = "cuda" if torch.cuda.is_available() else "cpu"
|
|
13 |
speech_to_text = pipeline("automatic-speech-recognition", model="openai/whisper-base", device=0 if device == "cuda" else -1)
|
14 |
|
15 |
# Function to generate and play voice prompts
|
16 |
-
def generate_audio(text, filename
|
17 |
tts = gTTS(text=text, lang="en")
|
18 |
tts.save(filename)
|
19 |
|
@@ -21,20 +22,23 @@ def generate_audio(text, filename="static/output.mp3"):
|
|
21 |
def home():
|
22 |
return render_template("index.html")
|
23 |
|
24 |
-
@app.route("/
|
25 |
-
def
|
26 |
-
generate_audio("Welcome to Biryani Hub.
|
27 |
-
|
|
|
|
|
|
|
28 |
|
29 |
@app.route("/process_audio", methods=["POST"])
|
30 |
def process_audio():
|
31 |
if "audio" not in request.files:
|
32 |
return jsonify({"error": "No audio file"}), 400
|
33 |
-
|
34 |
audio_file = request.files["audio"]
|
35 |
audio_path = "static/temp.wav"
|
36 |
audio_file.save(audio_path)
|
37 |
-
|
38 |
try:
|
39 |
text = speech_to_text(audio_path)["text"]
|
40 |
return jsonify({"text": text})
|
|
|
4 |
import speech_recognition as sr
|
5 |
from transformers import pipeline
|
6 |
from gtts import gTTS
|
7 |
+
import time
|
8 |
|
9 |
app = Flask(__name__)
|
10 |
recognizer = sr.Recognizer()
|
|
|
14 |
speech_to_text = pipeline("automatic-speech-recognition", model="openai/whisper-base", device=0 if device == "cuda" else -1)
|
15 |
|
16 |
# Function to generate and play voice prompts
|
17 |
+
def generate_audio(text, filename):
|
18 |
tts = gTTS(text=text, lang="en")
|
19 |
tts.save(filename)
|
20 |
|
|
|
22 |
def home():
|
23 |
return render_template("index.html")
|
24 |
|
25 |
+
@app.route("/start_interaction")
|
26 |
+
def start_interaction():
|
27 |
+
generate_audio("Welcome to Biryani Hub.", "static/welcome.mp3")
|
28 |
+
generate_audio("Tell me your name.", "static/ask_name.mp3")
|
29 |
+
generate_audio("Please provide your email.", "static/ask_email.mp3")
|
30 |
+
generate_audio("Thank you for registration.", "static/thank_you.mp3")
|
31 |
+
return jsonify({"status": "Audio prompts generated"})
|
32 |
|
33 |
@app.route("/process_audio", methods=["POST"])
|
34 |
def process_audio():
|
35 |
if "audio" not in request.files:
|
36 |
return jsonify({"error": "No audio file"}), 400
|
37 |
+
|
38 |
audio_file = request.files["audio"]
|
39 |
audio_path = "static/temp.wav"
|
40 |
audio_file.save(audio_path)
|
41 |
+
|
42 |
try:
|
43 |
text = speech_to_text(audio_path)["text"]
|
44 |
return jsonify({"text": text})
|