“Alexa in Python” Code-Antworten

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

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

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

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

Ähnliche Antworten wie “Alexa in Python”

Fragen ähnlich wie “Alexa in Python”

Weitere verwandte Antworten zu “Alexa in Python” auf Python

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen