示例#1
0
文件: weather.py 项目: KoalaV2/K.A.I
def weather(city_name):
    api_key = "886705b4c1182eb1c69f28eb8c520e20" # if you're curious about this being public, don't worry i found it online somewhere :p

    base_url = "http://api.openweathermap.org/data/2.5/weather?"

    complete_url = base_url + "appid=" + api_key + "&q=" + ''.join(city_name) + "&units=metric"

    response = requests.get(complete_url)

    x = response.json()

    if x["cod"] != "404":


        y = x["main"]


        current_temperature = y["temp"]

        #current_pressure = y["pressure"]

        #current_humidiy = y["humidity"]

        z = x["weather"]


        weather_description = z[0]["description"]
        say("It is " + str(current_temperature) + " Celsius in " + city_name + " with " + str(weather_description))

    else:
        print(" City Not Found ")
示例#2
0
def youtube():
    with sr.Microphone() as source:
        say("What is the title of the youtube video?")
        print("What is the title of the youtube video?")
        title_listen = r.listen(source)
        title = r.recognize_google(title_listen)
        say("What name do you want the file to have?")
        print("What name do you want the file to have?")
        file_listen = r.listen(source)
        file_name = r.recognize_google(file_listen)
        print("Searching and downloading:" + title)
        say("searching and downloading" + title)
        subprocess.call(
            f'youtube-dl "ytsearch1:{title}" --output "{file_name}"',
            shell=True)
        say(title + "has successfully been downloaded.")
        print(title + "has successfully been downloaded. \n")
        say("Do you want to play the file?")
        print("Do you want to play the file?")
        play_file_listen = r.listen(source)
        play_file = r.recognize_google(play_file_listen)
        if play_file == "yes" or "Yes":
            webbrowser.open(f"{file_name}.mkv")

        elif play_file == "no":
            pass
示例#3
0
def chat():
    while 1:
        if listen() == trigger or input() == trigger:
            try:
                print("speak with the bot")
                say("Speak with the bot")
                while True:
                    with sr.Microphone() as source:
                        #inp = input("You: ")
                        #if inp.lower() == "quit":
                        #    break
                        inp_listen = r.listen(source)
                        inp = r.recognize_google(inp_listen)
                        results = model.predict([bag_of_words(inp, words)])
                        results_index = numpy.argmax(results)
                        tag = labels[results_index]

                        for tg in data["intents"]:
                            if tg['tag'] == tag:
                                responses = tg['responses']
                        print("You: " + inp)
                        print(random.choice(responses))
                        say(random.choice(responses))
            except sr.UnknownValueError as err:
                print("Encountered an error: ", err)
示例#4
0
文件: time.py 项目: anna328p/K.A.I
def time():
    now = datetime.utcnow()
    
    current_time = now.strftime("%H:%M")

    say("The current time is " + current_time)
    print("The current time is:", current_time)
示例#5
0
def wikipedia_summary():
    with sr.Microphone() as source:
        say("What do you want to search for?")
        print("What do you want to search for?")
        wikipedia_article_listen = r.listen(source)
        wikipedia_article = r.recognize_google(wikipedia_article_listen)
        print(wikipedia.summary(wikipedia_article))
        say(wikipedia.summary(wikipedia_article))
示例#6
0
def youtube(title):
    with sr.Microphone() as source:
        say("What name do you want the file to have?")
        print("What name do you want the file to have?")
        file_listen = r.listen(source)
        file_name = r.recognize_google(file_listen)
        print("Searching and downloading:" + ' '.join(title))
        say("searching and downloading" + ' '.join(title))
        subprocess.call(
            f'youtube-dl "ytsearch1:{title}" --output "{file_name}"',
            shell=True)
        say(' '.join(title) + "has successfully been downloaded.")
        print(' '.join(title) + "has successfully been downloaded. \n")
        say("Do you want to play the file?")
        print("Do you want to play the file?")
        play_file_listen = r.listen(source)
        play_file = r.recognize_google(play_file_listen)
        if play_file == "yes" or "Yes":
            cap = cv2.VideoCapture(f"{file_name}.mkv")
            ret, frame = cap.read()
            while (1):
                ret, frame = cap.read()
                cv2.namedWindow("window", cv2.WND_PROP_FULLSCREEN)
                cv2.setWindowProperty("window", cv2.WND_PROP_FULLSCREEN,
                                      cv2.WINDOW_FULLSCREEN)
                cv2.imshow("window", frame)
                if cv2.waitKey(1) & 0xFF == ord('q') or ret == False:
                    cap.release()
                    cv2.destroyAllWindows()
                    break
                cv2.imshow('frame', frame)

        else:
            pass
示例#7
0
文件: weather.py 项目: anna328p/K.A.I
def weather():
    with sr.Microphone() as source:
        api_key = "886705b4c1182eb1c69f28eb8c520e20"

        base_url = "http://api.openweathermap.org/data/2.5/weather?"

        say("What is the city name?")
        print("What is the city name?")
        city_name_listen = r.listen(source)
        city_name = r.recognize_google(city_name_listen) 

        complete_url = base_url + "appid=" + api_key + "&q=" + city_name + "&units=metric"

        response = requests.get(complete_url) 
        
        x = response.json() 

        if x["cod"] != "404": 
        

            y = x["main"] 
        

            current_temperature = y["temp"] 
        
            #current_pressure = y["pressure"] 
        
            #current_humidiy = y["humidity"] 
        
            z = x["weather"] 
        

            weather_description = z[0]["description"] 
            print("It is " + str(current_temperature) + " Celsius in " + city_name + " with " + str(weather_description)) 
            say("It is " + str(current_temperature) + " Celsius in " + city_name + " with " + str(weather_description))

        else: 
            print(" City Not Found ")
示例#8
0
def youtube():
    with sr.Microphone() as source:
        say("What is the title of the youtube video?")
        print("What is the title of the youtube video?")
        title_listen = r.listen(source)
        title = r.recognize_google(title_listen)
        print("Searching and downloading:" + title)
        say("searching and downloading" + title)
        subprocess.call(f'youtube-dl "ytsearch1:{title}"', shell=True)
        say(title + "has successfully been downloaded.")
        print(title + "has successfully been downloaded. \n")
示例#9
0
def calculator():
    with sr.Microphone() as source:
        say("please enter the first number")
        print("Please enter the first number: ")
        first_numer_listen = r.listen(source)
        first_number = float(r.recognize_google(first_numer_listen))
        print(first_number)
        say("What operation shall be used?")
        print("What operation shall be used? ")
        operation_listen = r.listen(source)
        operation = r.recognize_google(operation_listen)
        print(operation)
        say("Please enter the second number")
        print("Please enter the second number: ")
        second_number_listen = r.listen(source)
        second_number = float(r.recognize_google(second_number_listen))
        print(second_number)

        if operation == "+" or operation == "add":
            result = first_number + second_number
            operand = "+"
        elif operation == "-" or operation == "subtract":
            result = first_number - second_number
            operand = "-"
        elif operation == "*" or operation == "multiply":
            result = first_number * second_number
            operand = "*"
        elif operation == "/" or operation == "divide":
            result = first_number / second_number
            operand = "/"
        elif operation == "pow" or operation == "power":
            result = first_number**second_number
            operand = "to the power of"
        else:
            print("Operation not recognized, exiting to main menu...")
            return
        print("\n{} {} {} is {}".format(first_number, operand, second_number,
                                        result))
        say("\n{} {} {} is {}".format(first_number, operand, second_number,
                                      result))
示例#10
0
def wikipedia_summary(wikipedia_article):
    print(wikipedia.summary(wikipedia_article))
    say(wikipedia.summary(wikipedia_article))
示例#11
0
文件: main.py 项目: KoalaV2/K.A.I
adjust()
while 1:
    if listen() == trigger:
        try:
            #sound = AudioSegment.from_mp3('library/sounds/wake_up_noise.mp3')
            #play(sound)
            if main_settings["face_rec_toggle"] == True:
                print("identifying face....")
                face_rec.face_rec()
                username = face_rec.global_name
            else:
                print("Face recognition disabled, skipping...")
                username = "******"
            greeting = time.greeting
            say(
                greeting(time.now.hour) +
                f" {username}, what can I do for you?")
            while True:
                #adjust()
                print("Speak now..")
                #inp_listen = r.listen(source)
                #inp = r.recognize_google(inp_listen)
                inp = listen()
                results = model.predict([bag_of_words(inp, words)])
                results_index = numpy.argmax(results)
                tag = labels[results_index]
                for tg in data["intents"]:
                    if tg['tag'] == tag:
                        responses = tg['responses']
                resp = random.choice(responses)
                print("You said: " + inp + "\n")
示例#12
0
from library import time
from library.utils import say
import library.youtube_dl as youtube
from library import wikipedia_summary
import os
import subprocess
from gtts import gTTS
import playsound
import speech_recognition as sr

r = sr.Recognizer()


try:
    print("What do you want me to do?")
    say("What do you want me to do?")
    while True:
        with sr.Microphone() as source:
            command_listen = r.listen(source)
            command = r.recognize_google(command_listen)
            print("You said: " + command + "\n")
            if command in ('open calculator', 'calculator', 'calc'):
                print("Opening calculator now!")
                say("Opening calculator now! Hold on...")
                calculator.calculator()

            elif command in ('show current time','local time', 'current time', 'time'):
                time.time()

            elif command in ('ssh info', 'ssh information'):
                subprocess.call("library/ssh.sh")
示例#13
0
文件: kai.py 项目: anna328p/K.A.I
from library import calculator
from library import time
from library.utils import say
import library.youtube_dl as youtube
from library import wikipedia_summary
from library import weather
import os
import subprocess
from gtts import gTTS
import playsound
import speech_recognition as sr
import playsound
trigger = "wake up"
r = sr.Recognizer()

say("Beginning to listen")
print("Beginning to listen...")

def listen():
        with sr.Microphone() as source:
                r.adjust_for_ambient_noise(source)
                audio = r.listen(source)
        try:
                return r.recognize_google(audio)
        except sr.UnknownValueError:
            return ""

while 1:
    if listen() == trigger:
        try:
            playsound.playsound('library/wake_up_noise.wav', True)