forked from parshant-balwaria/Python_hacktoberfest
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSpeech_recognition.py
More file actions
44 lines (33 loc) · 1.29 KB
/
Speech_recognition.py
File metadata and controls
44 lines (33 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import speech_recognition as sr
import googlesearch
import webbrowser
import time
#INITIATING RECOGNIZER
recognizer=sr.Recognizer()
while True:
#WE HAVE TO SPECIFY THE SOURCE. HERE WE USE MICORPHONE AS THE SOURCE FILE
# IF WE WANT A RECORDED FILE AS SOURCE THEN WE WILL USE
# with sr.AudioFile(filename) as source:
with sr.Microphone() as source:
#CLEARING SOUND OF VOICE
print('Adjusting voice')
recognizer.adjust_for_ambient_noise(source, duration=1)
print('recording audio')
#RECORDING THE AUDIO
audio=recognizer.listen(source,timeout=4)
try:
#GETTING THE TEXT USING GOOGLE API
text=recognizer.recognize_google(audio,language='en-US')
print(text)
print("Start searching")
#SEARCHING ON GOOGLE USING GOOLESEARCH LIBRABRY
search=googlesearch.search(text,tld='com',lang='en',num=1,start=0,stop=1,pause=1.5)
for j in search:
print(j)
#OPENING WEB BROWSER TO OPEN WITH URL OF TOP RESULT
browser=webbrowser.open_new(j)
except sr.UnknownValueError:
print('Error')
except sr.RequestError:
print('request error')
time.sleep(10)