How to Convert Speech to Text using Python | Tested in Hindi English Sanskrit with high accuracy

Опубликовано: 23 Май 2026
на канале: Flexmind
1,980
49

This video explains how you can convert your speech into text using #python. I have used the Speech Recognizer module which needs the internet to work. Behind the scene is Google speech recognizer which recognizes even any kind of accent. Subscribe to the channel for more such useful videos.

I tried with Hindi, English, and Sanskrit and I was surprised to see its accuracy. Try it out and you will enjoy #PythonCode and #Programming Explanation.

I have tried to explain the code line by line. Still, if you face any challenges, don't hesitate to ask in the comments. And don't forget to like and Share.

Here is the code snippet:
Author: Sanjeev Jaiswal (Jassi)
From Flexmind.co
import the module
import speech_recognition as sr

create the recognizer
r = sr.Recognizer()

define the microphone
mic = sr.Microphone(device_index=0)

print("Start speaking")

record your speech
with mic as source:
audio = r.listen(source)

try:
result = r.recognize_google(audio)
except sr.RequestError:
API was unreachable or unresponsive
exit("API is unreachable")
except sr.UnknownValueError:
speech was unintelligible
exit("Unable to recognize speech! Were you speaking")

speech recognition
result = r.recognize_google(audio)

export the result
with open('my_speech.txt',mode ='w') as file:
file.write(result)