-
Notifications
You must be signed in to change notification settings - Fork 3
/
stt_google.py
64 lines (56 loc) · 1.83 KB
/
stt_google.py
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import pyttsx3
import speech_recognition as sr
import datetime
import os
import time
from google_images_search import GoogleImagesSearch
from PIL import Image
import creds
a = pyttsx3.init()
voices = a.getProperty('voices')
a.setProperty('voice', voices[1].id)
gis = GoogleImagesSearch(
creds.api_key, creds.api_token)
hour = int(datetime.datetime.now().hour)
if hour >= 0 and hour < 12:
a.say("Good Morning!!")
elif hour >= 12 and hour < 18:
a.say("Good afternoon!")
else:
a.say("Good evening!")
a.say("Hello, what do you want to communicate?")
#a.say("Hello there! I am Edith! What can I do for you today?")
a.runAndWait()
r = sr.Recognizer()
x = 1
while x > 0:
with sr.Microphone() as source:
r.adjust_for_ambient_noise(source)
r.pause_threshold = 1
print("Listening....")
audio = r.listen(source, timeout=5)
try:
text = r.recognize_google(audio)
query = text.lower()
print(query)
#qu = 'friend'
que = query + ' sign language'
print(query)
print(que)
_search_params = {
'q': que,
'num': 1,
'fileType': 'jpg',
'rights': 'cc_publicdomain|cc_attribute|cc_sharealike|cc_noncommercial|cc_nonderived'}
gis.search(search_params=_search_params,
path_to_dir='C:\\Users\\DELL\\Desktop\\New folder\\', custom_image_name=query)
#p = 'C:\\Users\\DELL\\Desktop\\New folder\\hello.jpg'
im = Image.open(
r"C:\\Users\\DELL\\Desktop\\New folder\\{}.jpg".format(query))
im.show()
# time.sleep(10)
#os.remove("C:\\Users\\DELL\\Desktop\\New folder\\hello.jpg")
except:
pyttsx3.speak(
"Sorry I am unable to understand. Can you please repeat.")
print("Sorry I am unable to understand. Can you please repeat.")