This task involves creating a Python script that converts spoken words into text using the speech_recognition library. The program will use a microphone to capture audio, process it, and display the recognized text. This feature is useful for voice commands, note-taking, and accessibility purposes. The script will continuously listen until the user stops speaking. If the speech is not recognized, it will return an error message.
Speech to Text Converter in Python
First, install the required library.in this task we used speechrecognition library which we required ti install in environment .for installment use this formate “pip install speechrecognition”.Now, use this script to convert speech to text.
import speech_recognition as sr def st(): recognizer = sr.Recognizer() with sr.Microphone() as s: print("Speak something...") recognizer.adjust_for_ambient_noise(s) audio = recognizer.listen(s) try: text = recognizer.recognize_google(audio) print("You said:", text) except sr.UnknownValueError: print("Sorry, could not understand the audio") except sr.RequestError: print("Could not request results, please check your internet connection") st()
Output: Example 1 :(Successful Recognition) Speak something... (You say: "Hello, how are you?") You said: Hello, how are you? Example 2 :(Unclear Speech) Speak something... Sorry, could not understand the audio
This simple task allows users to convert their voice into text, making it useful for various applications like voice assistants, transcriptions, or hands-free typing.