“Alexa en Python” Código de respuesta

Alexa en 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")
Healthy Horse

Alexa en 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")  
Healthy Horse

Alexa en 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)
Healthy Horse

Alexa en 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
Healthy Horse

Respuestas similares a “Alexa en Python”

Preguntas similares a “Alexa en Python”

Más respuestas relacionadas con “Alexa en Python” en Python

Explore las respuestas de código populares por idioma

Explorar otros lenguajes de código