Answers for "alexa in python"

-1

alexa in python

import wolframalpha
# pip install wolframalpha
import pyttsx3
# Pip install pyttsx3
import speech_recognition as sr
# pip install speech_rocognition



#API key
"""
here you need to have an API key on wolframealpha.com
"""
client = wolframalpha.Client(API-Key)

# Result
res = client.query("a")
r = sr.Recognizer()

# recognition bot
r = sr.Recognizer()

# init pyttsx3
engine = pyttsx3.init()


# def
def talk(speak):
    engine.say(str(speak))
    engine.runAndWait()


# Main
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()
Posted by: Guest on January-25-2021
0

alexa in python

def takecommand():
    r = sr.Recognizer()
    with sr.Microphone() as source:
        print("Listening...")
        r.pause_threshold = 1
        audio = r.listen(source)

    try:
        print("Recongnizing...")
        query = r.recognize_google(audio, language='en-in')
        print("User Said:", query)
    except Exception as e:
        # print(e)

        print("say that again please...")
        return "None"
    return query
Posted by: Guest on July-21-2021
0

alexa in python

import pyttsx3 
import speech_recognition as sr
import datetime
import wikipedia
import webbrowser
import os
import random

from wikipedia import exceptions


engine = pyttsx3.init('sapi5')
voices = engine.getProperty('voices')
# print(voices[0].id)
engine.setProperty('voice', voices[1].id)
Posted by: Guest on July-21-2021
0

alexa in python

if __name__ == "__main__":
   wishme()
   while 1:
     query = takecommand().lower()

     if 'wikipedia' in query:
       speak('searching wikipedia...')
       query = query.replace("wikipedia", "")
       results = wikipedia.summary(query, sentences=2)
       speak("According to wikipedia")
       print("results")
       speak(results)

     elif 'open youtube' in query:
         print("opening youtube...")
         webbrowser.open("youtube.com")

     elif 'open google' in query:
         print("opening google...")
         webbrowser.open("https://google.com")
Posted by: Guest on July-21-2021
0

alexa in python

def  speak(audio):
    engine.say(audio)
    engine.runAndWait()

def wishme():
    hour = int(datetime.datetime.now().hour)
    if hour>=0 and hour<12:
        speak("good morning sir!")

    elif hour>=12 and hour<18:
        speak("good aternoon sir!")

    else:
        speak("Good Evening sir!")  

    speak("i am jarvis. how may i help you")
Posted by: Guest on July-21-2021
-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# Make sure IntentReflectorHandler is last so it
181# Doesn't override your custom intent handlers
182sb.add_request_handler(IntentReflectorHandler())
183
184sb.add_exception_handler(CatchAllExceptionHandler())
185
186...
Posted by: Guest on January-12-2021

Python Answers by Framework

Browse Popular Code Answers by Language