Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,8 +1,8 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import requests
|
| 3 |
import tempfile
|
| 4 |
-
import pyttsx3
|
| 5 |
from faster_whisper import WhisperModel
|
|
|
|
| 6 |
|
| 7 |
# === Config ===
|
| 8 |
GROQ_API_KEY = "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"
|
|
@@ -12,15 +12,6 @@ GROQ_API_URL = "https://api.groq.com/openai/v1/chat/completions"
|
|
| 12 |
# === Init Whisper ===
|
| 13 |
whisper = WhisperModel("base", device="cpu", compute_type="int8")
|
| 14 |
|
| 15 |
-
# === Init TTS (offline) ===
|
| 16 |
-
tts_engine = pyttsx3.init()
|
| 17 |
-
|
| 18 |
-
def speak_to_file(text, output_file="output.wav"):
|
| 19 |
-
"""Save TTS to a file using pyttsx3."""
|
| 20 |
-
tts_engine.save_to_file(text, output_file)
|
| 21 |
-
tts_engine.runAndWait()
|
| 22 |
-
return output_file
|
| 23 |
-
|
| 24 |
def process_audio(audio_file):
|
| 25 |
# 1. Speech to Text
|
| 26 |
segments, _ = whisper.transcribe(audio_file)
|
|
@@ -43,9 +34,10 @@ def process_audio(audio_file):
|
|
| 43 |
|
| 44 |
reply = response.json()["choices"][0]["message"]["content"]
|
| 45 |
|
| 46 |
-
# 3. TTS
|
| 47 |
-
|
| 48 |
-
|
|
|
|
| 49 |
|
| 50 |
return reply, audio_output.name
|
| 51 |
|
|
@@ -56,8 +48,8 @@ iface = gr.Interface(
|
|
| 56 |
gr.Textbox(label="🧠 Groq Response"),
|
| 57 |
gr.Audio(label="🔊 AI Voice Reply")
|
| 58 |
],
|
| 59 |
-
title="🗣️ Voice AI Assistant (Groq + Whisper +
|
| 60 |
-
description="
|
| 61 |
live=True
|
| 62 |
)
|
| 63 |
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import requests
|
| 3 |
import tempfile
|
|
|
|
| 4 |
from faster_whisper import WhisperModel
|
| 5 |
+
from gtts import gTTS
|
| 6 |
|
| 7 |
# === Config ===
|
| 8 |
GROQ_API_KEY = "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"
|
|
|
|
| 12 |
# === Init Whisper ===
|
| 13 |
whisper = WhisperModel("base", device="cpu", compute_type="int8")
|
| 14 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
def process_audio(audio_file):
|
| 16 |
# 1. Speech to Text
|
| 17 |
segments, _ = whisper.transcribe(audio_file)
|
|
|
|
| 34 |
|
| 35 |
reply = response.json()["choices"][0]["message"]["content"]
|
| 36 |
|
| 37 |
+
# 3. TTS using gTTS (generates .mp3)
|
| 38 |
+
tts = gTTS(reply)
|
| 39 |
+
audio_output = tempfile.NamedTemporaryFile(suffix=".mp3", delete=False)
|
| 40 |
+
tts.save(audio_output.name)
|
| 41 |
|
| 42 |
return reply, audio_output.name
|
| 43 |
|
|
|
|
| 48 |
gr.Textbox(label="🧠 Groq Response"),
|
| 49 |
gr.Audio(label="🔊 AI Voice Reply")
|
| 50 |
],
|
| 51 |
+
title="🗣️ Voice AI Assistant (Groq + Whisper + gTTS)",
|
| 52 |
+
description="🎙️ Whisper for STT, Groq for response, gTTS for voice output. Fully Hugging Face compatible.",
|
| 53 |
live=True
|
| 54 |
)
|
| 55 |
|