-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
64 lines (50 loc) · 1.7 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
#!/usr/bin/env python3
# Requires PyAudio and PySpeech.
import speech_recognition as sr
from time import ctime
import time
import os
from gtts import gTTS
def speak(audioString):
print(audioString)
tts = gTTS(text=audioString, lang='en')
tts.save("audio.mp3")
os.system("mpg123 audio.mp3")
def recordAudio():
# Record Audio
r = sr.Recognizer()
with sr.Microphone() as source:
print("Say something!")
audio = r.listen(source, timeout=10, phrase_time_limit=10)
# Speech recognition using Google Speech Recognition
data = ""
try:
# Uses the default API key
# To use another API key: `r.recognize_google(audio, key="GOOGLE_SPEECH_RECOGNITION_API_KEY")`
data = r.recognize_google(audio)
print("You said: " + data)
except sr.UnknownValueError:
print("Google Speech Recognition could not understand audio")
except sr.RequestError as e:
print(
"Could not request results from Google Speech Recognition service; {0}"
.format(e))
return data
def jarvis(data):
print("you said:" + data)
if "how are you" in data:
speak("I am fine")
elif "what time is it" in data:
speak(ctime())
elif "where is" in data:
data = data.replace("where is ", "")
speak("Hold on Giddy, I will show you where " + data + " is.")
os.system("chromium-browser https://www.google.nl/maps/place/" +
data.replace(" ", "+") + "/&")
else:
speak("I'm sorry i don't understand")
# initialization
time.sleep(2)
speak("Hi Giddy, what can I do for you?")
data = recordAudio()
jarvis(data)