“Alexa di Python” Kode Jawaban

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

Jawaban yang mirip dengan “Alexa di Python”

Pertanyaan yang mirip dengan “Alexa di Python”

Lebih banyak jawaban terkait untuk “Alexa di Python” di Python

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya