1import wolframalpha
2# pip install wolframalpha
3import pyttsx3
4# Pip install pyttsx3
5import speech_recognition as sr
6# pip install speech_rocognition
7
8
9
10#API key
11"""
12here you need to have an API key on wolframealpha.com
13"""
14client = wolframalpha.Client(API-Key)
15
16# Result
17res = client.query("a")
18r = sr.Recognizer()
19
20# recognition bot
21r = sr.Recognizer()
22
23# init pyttsx3
24engine = pyttsx3.init()
25
26
27# def
28def talk(speak):
29 engine.say(str(speak))
30 engine.runAndWait()
31
32
33# Main
34run = True
35while True:
36 try:
37 with sr.Microphone() as source2:
38 print("I am listening...")
39 r.adjust_for_ambient_noise(source2, duration=0.2)
40 audio2 = r.listen(source2)
41 MyText = r.recognize_google(audio2)
42 MyText = MyText.lower()
43 if MyText == "bye":
44 run = False
45 break
46 if run:
47 res = client.query(MyText)
48 print(next(res.results).text)
49 talk(next(res.results).text)
50
51 except:
52 engine.say("An error occurred...")
53 engine.runAndWait()
54
55
56engine.say("Bye...")
57engine.runAndWait()
1def speak(audio):
2 engine.say(audio)
3 engine.runAndWait()
4
5def wishme():
6 hour = int(datetime.datetime.now().hour)
7 if hour>=0 and hour<12:
8 speak("good morning sir!")
9
10 elif hour>=12 and hour<18:
11 speak("good aternoon sir!")
12
13 else:
14 speak("Good Evening sir!")
15
16 speak("i am jarvis. how may i help you")
1def takecommand():
2 r = sr.Recognizer()
3 with sr.Microphone() as source:
4 print("Listening...")
5 r.pause_threshold = 1
6 audio = r.listen(source)
7
8 try:
9 print("Recongnizing...")
10 query = r.recognize_google(audio, language='en-in')
11 print("User Said:", query)
12 except Exception as e:
13 # print(e)
14
15 print("say that again please...")
16 return "None"
17 return query
1import pyttsx3
2import speech_recognition as sr
3import datetime
4import wikipedia
5import webbrowser
6import os
7import random
8
9from wikipedia import exceptions
10
11
12engine = pyttsx3.init('sapi5')
13voices = engine.getProperty('voices')
14# print(voices[0].id)
15engine.setProperty('voice', voices[1].id)
16
1if __name__ == "__main__":
2 wishme()
3 while 1:
4 query = takecommand().lower()
5
6 if 'wikipedia' in query:
7 speak('searching wikipedia...')
8 query = query.replace("wikipedia", "")
9 results = wikipedia.summary(query, sentences=2)
10 speak("According to wikipedia")
11 print("results")
12 speak(results)
13
14 elif 'open youtube' in query:
15 print("opening youtube...")
16 webbrowser.open("youtube.com")
17
18 elif 'open google' in query:
19 print("opening google...")
20 webbrowser.open("https://google.com")
1171sb = SkillBuilder()
2172
3173sb.add_request_handler(LaunchRequestHandler())
4174sb.add_request_handler(JokeIntentHandler())
5175sb.add_request_handler(HelloWorldIntentHandler())
6176sb.add_request_handler(HelpIntentHandler())
7177sb.add_request_handler(CancelOrStopIntentHandler())
8178sb.add_request_handler(SessionEndedRequestHandler())
9179
10180# Make sure IntentReflectorHandler is last so it
11181# Doesn't override your custom intent handlers
12182sb.add_request_handler(IntentReflectorHandler())
13183
14184sb.add_exception_handler(CatchAllExceptionHandler())
15185
16186...
17