python-scripts/scripts/Speech_To_Text/script.py

16 lines
386 B
Python
Raw Normal View History

2022-10-09 12:03:45 +00:00
import speech_recognition as sr
import os
filename = "sample.wav"
# initialize the recognizer
recognizer = sr.Recognizer()
# open the file
with sr.AudioFile(filename) as source:
# listen for the data (load audio to memory)
audio_data = recognizer.record(source)
# recognize (convert from speech to text)
text = recognizer.recognize_google(audio_data)
print(text)