Spaces:
Runtime error
Runtime error
File size: 1,599 Bytes
a992697 46c3d84 f0ffae0 46c3d84 85763a6 f0ffae0 46c3d84 f0ffae0 a992697 67436ec a992697 f0ffae0 a992697 f0ffae0 a992697 |
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 |
import gradio as gr
from transformers import pipeline
# Initialize Hugging Face pipelines
speech_to_text = pipeline("automatic-speech-recognition", model="openai/whisper-large")
# Use a compatible TTS model for text-to-speech (FastSpeech2)
text_to_speech = pipeline("text-to-speech", model="facebook/fastspeech2-en-ljspeech", device=0) # Use CPU or GPU (cuda)
# Function to process speech to text and text to speech
def process_audio(input_audio):
# Convert the audio to text using Whisper model (speech-to-text)
recognized_text = speech_to_text(input_audio)["text"]
print(f"Recognized text: {recognized_text}")
# Process the text to speech using the TTS model
audio_response = text_to_speech(recognized_text)
return audio_response, recognized_text
# Gradio Interface for the app
def create_gradio_interface():
with gr.Blocks() as demo:
gr.Markdown("## AI Voice Bot for Food Ordering")
# Audio Input: User speaks into microphone or uploads a file (filepath)
audio_input = gr.Audio(type="filepath", label="Speak to the bot (Upload or Record Audio)")
# Display the bot's response after recognition
output_audio = gr.Audio(label="Bot Response", type="numpy")
output_text = gr.Textbox(label="Bot Response (Text)")
# Define the button to process the audio input
audio_input.change(fn=process_audio, inputs=audio_input, outputs=[output_audio, output_text])
return demo
# Create and launch the Gradio app
if __name__ == "__main__":
app = create_gradio_interface()
app.launch(share=True)
|