“Alexa à Python” Réponses codées

Alexa à 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 à 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 à 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 à 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

Réponses similaires à “Alexa à Python”

Questions similaires à “Alexa à Python”

Plus de réponses similaires à “Alexa à Python” dans Python

Parcourir les réponses de code populaires par langue

Parcourir d'autres langages de code