import openai/whisper-large-v3-turbo from groq import Groq from gtts import gTTS import gradio as gr # Set Groq API Key (replace with your actual API key) GROQ_API_KEY = "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" # Initialize Groq client client = Groq(api_key=GROQ_API_KEY) # Initialize openai/ Whisper-large-v3-turbo model openai/whisper-large-v3-turbo = openai/whisper_large-v3-turbo load("base") # Function for real-time transcription, LLM interaction, and text-to-speech def voice_to_voice_chat(audio): # Step 1: Transcribe audio to text transcription = openai/whisper_v3-turbo.transcribe(audio)["text"] # Step 2: Interact with the LLM using Groq API chat_completion = client.chat.completions.create( messages=[{"role": "user", "content": transcription}], model="llama3-8b-8192", stream=False, ) llm_response = chat_completion.choices[0].message.content # Step 3: Convert LLM response to speech tts = gTTS(llm_response) audio_output_path = "/tmp/output.mp3" tts.save(audio_output_path) return audio_output_path, transcription, llm_response # Gradio interface interface = gr.Interface( fn=voice_to_voice_chat, inputs=gr.Audio(type="filepath"), # Input: Audio file outputs=[ gr.Audio(label="Response Audio"), # Output: Audio response gr.Textbox(label="Transcription"), # Output: Transcribed text gr.Textbox(label="LLM Response"), # Output: LLM's response ], live=True, title="Real-Time Voice-to-Voice Chatbot", description="Speak to interact with the LLM via Groq API. The response is converted back to audio." ) # Launch the Gradio interface interface.launch()