forked from PracticalHarware/Speranza-Cieca
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMainRunner.py
85 lines (77 loc) · 2.74 KB
/
MainRunner.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
81
82
83
84
import speech_recognition as sr;
from time import ctime;
import time;
import webbrowser;
from sys import exit;
import playsound
import os
import random
from gtts import gTTS
import VolumeControlModule as VCM;
import PeopleRecognitionModule as PRM;
import VehicleTracking as VT;
import ReadTextFromCamera as OCR;
def speak(audio_string):
tts = gTTS(text = audio_string, lang = 'en');
r = random.randint(1, 10000000)
audio_file = 'audio-'+ str(r) + '.mp3';
tts.save(audio_file)
playsound.playsound(audio_file)
print(audio_string)
os.remove(audio_file);
r = sr.Recognizer();
def record_audio(ask = False):
if ask:
speak(ask);
with sr.Microphone() as source:
audio = r.listen(source);
voice_data = '';
try:
voice_data = r.recognize_google(audio)
except sr.UnknownValueError:
speak("Sorry I didnt get that")
except sr.RequestError:
speak("Sorry, My Speech service is down")
return voice_data;
def respond(voice_data):
if "what is your name" in voice_data:
speak("My name is Helen");
if "what is the time" in voice_data:
speak(ctime());
if 'search' in voice_data:
search_data = record_audio('What are you looking for?');
url = 'https://google.com/search?q='+search_data;
webbrowser.get().open(url);
speak("Here is what I found for"+search_data);
if 'find location' in voice_data:
location_data = record_audio('What is the location?');
location_data.replace(' ', ',+');
url = 'https://google.nl/maps/place/'+ location_data + '/&';
webbrowser.get().open(url);
speak("Here is the location of " + location_data);
if ('give directions' in voice_data) or ('get directions' in voice_data) :
start_data = record_audio('What is the start location');
destination_data = record_audio('What is the end location');
start_data.replace(' ', ',+');
destination_data.replace(' ', ',+');
url = 'https://www.google.nl/maps/dir/'+ start_data + '/'+destination_data;
webbrowser.get().open(url);
speak("Here are the directions from " + start_data + ' to ' + destination_data);
if 'control volume' in voice_data:
VCM.control_volume();
speak('Volume set');
if 'recognize people' in voice_data:
PRM.peopleRecognition();
speak('Done with people recognition');
if 'detect cars around me' in voice_data:
VT.trackMultipleObjects()
if 'read for me' in voice_data:
OCR.scan_read();
if 'exit' in voice_data:
exit();
time.sleep(1);
speak("Hello, How can i help you")
while True:
voice_data = record_audio();
speak(voice_data)
respond(voice_data);