File size: 1,364 Bytes
f69f330
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# Import libraries
import whisper
from gtts import gTTS
from groq import Groq
import os
import gradio as gr

# Load Whisper model
model = whisper.load_model("base")

GROQ_API_KEY = "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"
client = Groq(api_key=GROQ_API_KEY)

# Function to process audio
def process_audio(audio_path):
    # Transcribe input audio
    transcription = model.transcribe(audio_path)["text"]
    
    # Interact with the GROQ model
    chat_completion = client.chat.completions.create(
        messages=[{"role": "user", "content": transcription}],
        model="llama3-8b-8192"
    )
    response_text = chat_completion.choices[0].message.content
    
    # Convert LLM response to audio
    tts = gTTS(response_text)
    response_audio_path = "response.mp3"
    tts.save(response_audio_path)
    
    return response_text, response_audio_path

# Gradio UI
with gr.Blocks() as demo:
    gr.Markdown("### Real Voice-to-Voice Chatbot")
    with gr.Row():
        input_audio = gr.Audio(type="filepath", label="Record Your Voice")
        output_text = gr.Textbox(label="LLM Response", lines=4)
        output_audio = gr.Audio(label="Response Audio")
    submit_button = gr.Button("Submit")
    submit_button.click(
        process_audio,
        inputs=[input_audio],
        outputs=[output_text, output_audio],
    )

demo.launch()