Spaces:
				
			
			
	
			
			
		Sleeping
		
	
	
	
			
			
	
	
	
	
		
		
		Sleeping
		
	Create app.py
Browse files
    	
        app.py
    ADDED
    
    | 
         @@ -0,0 +1,30 @@ 
     | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
|
| 
         | 
| 
         | 
|
| 1 | 
         
            +
            import gradio as gr
         
     | 
| 2 | 
         
            +
            import speech_recognition as sr
         
     | 
| 3 | 
         
            +
             
     | 
| 4 | 
         
            +
            def transcribe_audio(audio_file):
         
     | 
| 5 | 
         
            +
                recognizer = sr.Recognizer()
         
     | 
| 6 | 
         
            +
                
         
     | 
| 7 | 
         
            +
                # Load the audio file
         
     | 
| 8 | 
         
            +
                with sr.AudioFile(audio_file) as source:
         
     | 
| 9 | 
         
            +
                    audio_data = recognizer.record(source)
         
     | 
| 10 | 
         
            +
                    
         
     | 
| 11 | 
         
            +
                try:
         
     | 
| 12 | 
         
            +
                    # Transcribe the audio data
         
     | 
| 13 | 
         
            +
                    text = recognizer.recognize_google(audio_data)
         
     | 
| 14 | 
         
            +
                    return text
         
     | 
| 15 | 
         
            +
                except sr.UnknownValueError:
         
     | 
| 16 | 
         
            +
                    return "Google Speech Recognition could not understand audio"
         
     | 
| 17 | 
         
            +
                except sr.RequestError as e:
         
     | 
| 18 | 
         
            +
                    return f"Could not request results from Google Speech Recognition service; {e}"
         
     | 
| 19 | 
         
            +
             
     | 
| 20 | 
         
            +
            # Create the Gradio interface
         
     | 
| 21 | 
         
            +
            iface = gr.Interface(
         
     | 
| 22 | 
         
            +
                fn=transcribe_audio,
         
     | 
| 23 | 
         
            +
                inputs="audio",
         
     | 
| 24 | 
         
            +
                outputs="text",
         
     | 
| 25 | 
         
            +
                title="Voice to Text Converter",
         
     | 
| 26 | 
         
            +
                description="Upload an audio file and get the transcribed text."
         
     | 
| 27 | 
         
            +
            )
         
     | 
| 28 | 
         
            +
             
     | 
| 29 | 
         
            +
            # Launch the interface
         
     | 
| 30 | 
         
            +
            iface.launch()
         
     |