-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit.py
59 lines (46 loc) · 1.59 KB
/
init.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
import speech_recognition
from win32com.client import Dispatch
import os
import requests
from playsound import playsound
def TtS(audio):
for line in audio.splitlines():
Dispatch('SAPI.SpVoice').Speak(audio)
#To check internet connection
def connected_to_internet(url='https://www.google.com/'):
try:
_ = requests.get(url, timeout = 1)
return True
except requests.ConnectionError:
return False
if connected_to_internet():
pass
else:
TtS('Check internet connection!')
TtS('Turning OFF, Goodbye!')
playsound('close.wav')
sys.exit()
#Speech-to-Text Initial Processes
with speech_recognition.Microphone() as source:
speech_recognition.Recognizer().pause_threshold = 0.8
speech_recognition.Recognizer().adjust_for_ambient_noise(source, duration = 1)
speech_recognition.Recognizer().dynamic_energy_threshold = True
TtS('Running')
playsound('listen.wav')
def StT():
with speech_recognition.Microphone() as source:
audio = speech_recognition.Recognizer().listen(source)
try:
command = speech_recognition.Recognizer().recognize_google(audio, language = 'en-US').lower()
except:
command = StT()
return command
#This function will open 'engine.py' script when command is spoken
def assistant(command):
if 'hey alex' in command or 'listen alex' in command or 'alex' in command:
os.system('gui.py')
TtS('Initializing')
else:
pass
while True:
assistant(StT())