-
Notifications
You must be signed in to change notification settings - Fork 0
/
speech.py
80 lines (62 loc) · 2.01 KB
/
speech.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import speech_recognition as sr
import pyaudio
import pywhatkit
import pyttsx3
import datetime
import wikipedia
import pyjokes
import subprocess
recorder = sr.Recognizer()
engine = pyttsx3.init()
voices = engine.getProperty('voices')
engine.setProperty('voice', voices[1].id)
def talk(text):
engine.say(text)
engine.runAndWait()
def take_cmd():
try:
with sr.Microphone() as source:
audio = recorder.listen(source)
audio_cmd = recorder.recognize_google(audio)
audio_cmd = audio_cmd.lower()
audio_cmd1 = audio_cmd
if (audio_cmd=='hi melody'):
talk('ummm hmmm.....')
print('ummm hmmm.....')
elif 'hi melody' in audio_cmd:
talk(audio_cmd1.replace('hi melody',''))
print(audio_cmd1)
elif (audio_cmd=='hi melody i love you'):
talk('i love you too sid')
print('i love you too sid')
except:
pass
return audio_cmd
def main():
command = take_cmd()
print(command)
if 'play' in command:
song = command.replace('play','')
talk('playing' + song)
pywhatkit.playonyt(song)
elif 'time' in command:
time = datetime.datetime.now().strftime('%I:%M %p')
print(time)
talk('Current time is ' + time )
elif 'joke' in command:
talk(pyjokes.get_joke())
elif 'what' in command:
info = wikipedia.summary(command,2)
talk(info)
pywhatkit.search(command)
elif 'open calculator' in command:
command= command.replace('open',"")
subprocess.Popen("C:\Windows\System32\calc.exe")
elif 'open notepad' in command:
command=command.replace('open notepad and type',"")
# subprocess.Popen("C:\Windows\System32\notepad.exe")
with open('new.txt','w') as g:
g.write(command)
else:
talk('how can i help you')
main()