Skip to content

Instantly share code, notes, and snippets.

@Goodnessuc
Created February 5, 2023 07:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Goodnessuc/6078bf84d42422bd22e492d6aaa72123 to your computer and use it in GitHub Desktop.
Save Goodnessuc/6078bf84d42422bd22e492d6aaa72123 to your computer and use it in GitHub Desktop.
a python file that converts audio to text using the speech recognition
import speech_recognition as sp_recog
from time import sleep
def capture_audio():
recog = sp_recog.Recognizer()
audio_file = sp_recog.AudioFile('AudioFile.wav')
with audio_file as source:
recog.pause_threshold = 1
recog.adjust_for_ambient_noise(source)
audio = recog.record(source)
print("Recognizing your speech...")
try:
audio_text = recog.recognize_google(audio, language='en-Us')
sleep(1)
print("\n")
print(audio_text)
except Exception as e:
print("An error occurred. Please ensure internet connection")
return "None"
return audio_text
audio_text = capture_audio()
sleep(10)
print("Exiting the program now")
sleep(3)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment