-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
61 lines (53 loc) · 1.41 KB
/
app.py
File metadata and controls
61 lines (53 loc) · 1.41 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
60
61
import webbrowser
import speech_recognition as sr
from gtts import gTTS
import os
import datetime
import playsound
import pyjokes
import wikipedia
import pyaudio
# gets audio from mic
def get_audio():
r = sr.Recognizer()
with sr.Microphone() as source:
audio = r.listen(source)
said = ""
try:
said = r.recognize_google(audio)
print(said)
except sr.UnknownValueError:
speak("Sorry, I did not get that.")
except sr.RequestError:
print("Sorry, this service is not available.")
return said.lower()
# converts the said to speech using gtts
def speak(text):
tts = gTTS(text=text, lang='en')
filename = "voice.mp3"
try:
os.remove(filename)
except OSError:
pass
tts.save(filename)
playsound.playsound(filename)
# debugging
# text = get_audio()
# speak(text)
while True:
text = get_audio().lower()
if 'youtube' in text:
speak("Opening Youtube")
webbrowser.open_new_tab("https://www.youtube.com")
elif 'search' in text:
speak("Searching Wikipedia...")
query = text.replace("search", "")
result = wikipedia.summary(query, sentences=3)
speak("According to Wikipedia")
print(result)
speak(result)
elif 'joke' in text:
speak(pyjokes.get_joke())
elif 'exit' in text:
speak("Goodbye, till next time")
exit()