#youtube #SpeechToText
Speech to text using Audio File:-
import speech_recognition as sr
filename = r"E:\4.wav"
initialize the recognizer
r = sr.Recognizer()
open the file
with sr.AudioFile(filename) as source:
listen for the data (load audio to memory)
audio_data = r.record(source)
recognize (convert from speech to text)
try:
text = r.recognize_google(audio_data)
print(text)
except:
print("Sorry, I didn't get it")
Speech To Text Using Microphone:-
#pip install pyaudio
import speech_recognition as sr
import pyaudio
r = sr.Recognizer()
with sr.Microphone() as source:
print("Talk")
audio_text = r.listen(source)
print("Time over, thanks")
try:
using google speech recognition
print("Text: "+r.recognize_google(audio_text))
except:
print("Sorry, I did not get that")