-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest.py
More file actions
59 lines (54 loc) · 2.17 KB
/
test.py
File metadata and controls
59 lines (54 loc) · 2.17 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import speech_recognition as sr
import os
import subprocess
import pyfiglet
from termcolor import colored
from gtts import gTTS
import time
tts=gTTS(text="Hello I am back to your service sir",lang='en-us')
tts.save("Initial.mp3")
os.system("mpg321 Initial.mp3 -quiet")
def listenToMe():
while True:
r=sr.Recognizer()
with sr.Microphone() as source:
subprocess.call('clear')
banner=pyfiglet.figlet_format('Virtual Assistant')
color=colored(banner,color='red')
print(color)
print("Give your command sir")
r.adjust_for_ambient_noise(source,duration=1)
audio=r.listen(source)
try:
command=r.recognize_google(audio)
print(command)
if 'Google' in command:
print("Opening google")
tts2=gTTS(text="Opening Google Chrome sir",lang='en-us')
tts2.save("command.mp3")
os.system("mpg123 command.mp3")
os.system('google-chrome')
if 'media' in command:
print("opeing vlc media player")
tts4=gTTS(text="Opening VLC media player sir",lang='en-us')
tts4.save('command.mp3')
os.system('mpg123 command.mp3')
os.system('vlc')
if 'Visual' in command:
print("opening visual studio code")
tts5=gTTS(text="Opening visual studio code sir",lang='en-us')
tts5.save('command.mp3')
os.system('mpg123 command.mp3')
os.system('code')
if 'Jarvis' in command:
tts3=gTTS(text='Hello Sir',lang='en-us')
tts3.save('command.mp3')
os.system('mpg123 command.mp3')
else:
ttsf=gTTS(text="Sorry I cannot perform this task sir",lang='en-us')
ttsf.save('command.mp3')
os.system('mpg123 command.mp3')
except sr.UnknownValueError as msg:
print(msg)
listenToMe()
listenToMe()