Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| import whisper | |
| from groq import Groq | |
| from gtts import gTTS | |
| import os | |
| # Load Whisper model | |
| model = whisper.load_model("base") | |
| # Groq API | |
| client = Groq(api_key=os.getenv("Voice")) | |
| def voice_chat(audio): | |
| # Step 1: Speech to Text | |
| result = model.transcribe(audio) | |
| user_text = result["text"] | |
| # Step 2: Send to Groq LLM | |
| completion = client.chat.completions.create( | |
| model="llama-3.1-8b-instant", | |
| messages=[ | |
| {"role": "user", "content": user_text} | |
| ] | |
| ) | |
| bot_text = completion.choices[0].message.content | |
| # Step 3: Text to Speech | |
| tts = gTTS(bot_text) | |
| tts.save("response.mp3") | |
| return user_text, bot_text, "response.mp3" | |
| interface = gr.Interface( | |
| fn=voice_chat, | |
| inputs=gr.Audio(type="filepath", label="Speak Here"), | |
| outputs=[ | |
| gr.Textbox(label="Your Speech (Text)"), | |
| gr.Textbox(label="Bot Response (Text)"), | |
| gr.Audio(label="Bot Voice Response") | |
| ], | |
| title="AI Voice Chatbot", | |
| description="Speak to the AI. It will reply in text and voice." | |
| ) | |
| interface.launch() |