import gradio as gr import speech_recognition as sr def transcribe_speech(): # Initialize the Recognizer object r = sr.Recognizer() # Open a Microphone source with sr.Microphone() as source: # Set the recording length (in seconds) print("Listening...") # Adjust for ambient noise r.adjust_for_ambient_noise(source) # Record the sound audio = r.listen(source) try: # Use Google's web-based speech-to-text algorithm to convert the audio to text text = r.recognize_google(audio, language='en-US') return text except sr.UnknownValueError: print("Sorry, I can't understand you.") return "Sorry, I can't understand you." except sr.RequestError as e: print(f"Error: {e}") return f"Error: {e}" # Define a simple greeting function for demonstration def greet(name): return "Hello " + name + "!!" # Create a Gradio interface for the transcription function demo = gr.Interface(fn=transcribe_speech, inputs="text", outputs="text") demo.launch()