1 import speech_recognition as sr
2
3
4 def main():
5
6 r = sr.Recognizer()
7
8 with sr.Microphone() as source:
9 r.adjust_for_ambient_noise(source)
10
11 audio = r.listen(source)
12
13 try:
14
15 print(r.recognize_google(audio))
16
17 except Exception as e:
18 print("Error : " + str(e))
19
20
21 with open("recorded.wav", "wb") as f:
22 f.write(audio.get_wav_data())
23
24
25 if __name__ == "__main__":
26 main()