-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.py
65 lines (54 loc) · 1.63 KB
/
Main.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
import speech_recognition as sr
from gtts import gTTS
import os
import time
import warnings
import wikipedia
import calendar
import random
import playsound
import webbrowser
r = sr.Recognizer()
def recognised(ask = False):
with sr.Microphone() as source:
if ask:
speak(ask)
audio = r.listen(source)
data= ''
try:
data = r.recognize_google(audio)
except sr.UnknownValueError:
speak('Sorry Couldn\'t get that :(')
except sr.RequestError:
speak('Sorry , I m Down a little :)')
return data
def speak(audio_string):
tts = gTTS(text=audio_string,lang='en')
rand = random.randint(1,1000000)
audio_file = 'audio-' + str(rand) + '.mp3'
tts.save(audio_file)
playsound.playsound(audio_file)
print(audio_string)
os.remove(audio_file)
def response(voice_data):
if 'what is your name' in voice_data:
speak('My name as boom')
if 'what is the time' in voice_data:
speak(time.ctime())
if 'search' in voice_data:
search = recognised('What you wanna Search')
url = 'https://google.com/search?q='+search
webbrowser.get().open(url)
speak('Here\'s the Stuff i got for :'+ search)
if 'find location' in voice_data:
search = recognised('What location u wanna find?')
url = 'https://google.in/maps/place/' + search
webbrowser.get().open(url)
speak('Here\'s the location u are looking for :' + search)
if 'exit' in voice_data:
exit()
time.sleep(1)
speak('May I help U ?')
while 1:
voice_data = recognised()
response(voice_data)