how to create alexa in python code example
Example 1: Alexa skill development using python tutorial
171sb = SkillBuilder()
172
173sb.add_request_handler(LaunchRequestHandler())
174sb.add_request_handler(JokeIntentHandler())
175sb.add_request_handler(HelloWorldIntentHandler())
176sb.add_request_handler(HelpIntentHandler())
177sb.add_request_handler(CancelOrStopIntentHandler())
178sb.add_request_handler(SessionEndedRequestHandler())
179
180
181
182sb.add_request_handler(IntentReflectorHandler())
183
184sb.add_exception_handler(CatchAllExceptionHandler())
185
186...
Example 2: alexa in python
import wolframalpha
import pyttsx3
import speech_recognition as sr
"""
here you need to have an API key on wolframealpha.com
"""
client = wolframalpha.Client(API-Key)
res = client.query("a")
r = sr.Recognizer()
r = sr.Recognizer()
engine = pyttsx3.init()
def talk(speak):
engine.say(str(speak))
engine.runAndWait()
run = True
while True:
try:
with sr.Microphone() as source2:
print("I am listening...")
r.adjust_for_ambient_noise(source2, duration=0.2)
audio2 = r.listen(source2)
MyText = r.recognize_google(audio2)
MyText = MyText.lower()
if MyText == "bye":
run = False
break
if run:
res = client.query(MyText)
print(next(res.results).text)
talk(next(res.results).text)
except:
engine.say("An error occurred...")
engine.runAndWait()
engine.say("Bye...")
engine.runAndWait()