Start of the Python AI project (unnamed as of yet)

So today marks my first day back on this website after a long extended break. Right so here is what I wanted to do. I wanted to make a simple AI system that responds. The end goal is to have a similar version of something like Alexa but not requiring the internet (Not strictly true as I want to use API’s for search when the user asks ). So today is day 1 making it. I have had a ideas of things to add over the next few days and they are:

  1. Loading the default web browser
  2. Linux support (Like shutdown for example)
  3. Try and think of a name (maybe)
  4. Get it to search Google
  5. Get it to search YouTube

There is loads more to add but for now I’m keeping the list as small as possible so the project don’t start to get overwhelming.

Here is the code so far….

startup.py

import speech
import responces

def startup_speech():
    print("Playing start up speech")
    speech.speak("Hello my name is Alpha three four, I am your new personal assistant, I am a new project by Stephen Wilde.")
    responces.responces()

main.py

import startup

def start_here() :
    startup.startup_speech()

start_here()

responses.py

import speech
import end
import datetime
import os
import calculator

def responces():
    speech.speak("Enter your name: ")
    name = input("Enter your name! ")
    speech.speak("Hello " + name)

    running = True

    while (running == True):
        speech.speak("What do you want me to do? ")
        command1 = input("What do you want to do? ")
        command1 = command1.upper()

        speech.speak = speech.speak
        if command1 == "TIME":
            speech.speak("The time is now!")
            speech.speak(datetime.datetime.now().hour)
            speech.speak(datetime.datetime.now().minute)

        elif command1 == "DATE":
            speech.speak(datetime.datetime.now().date())

        elif command1 == "WHAT":
            speech.speak("I am not repeating myself")

        elif command1 == "BYE" :
            speech.speak("Well fuck you then")

        elif command1 == "CHANGE MY NAME":
            speech.speak("Enter your new name: ")
            name = input("Enter your new name! ")
            speech.speak("Named changed successfully to: " + name)
            print("Named changed successfully to: " + name)

        elif command1 == "MY NAME":
            print("You told me your name was: " +name)
            speech.speak("You told me your name was " + name)

        elif command1 == "CONTROL":
            os.system('control')

        elif command1 == "SHUTDOWN":
            os.system("shutdown -s -t 0")

        elif command1 == "EXIT" :
            speech.speak("Good Bye!")
            end.end_program()

        elif command1 == "HELLO":
            speech.speak("Hello " + name)

        elif command1 == "CALCULATOR":
            speech.speak("Starting Calulator")
            calculator.calculator()

        elif command1 == "FUCK YOU":
            speech.speak("Fuck you too " + name)

        elif command1 == "ECHO" :
            print(command1 + " Was all in upper case")
            speech.speak(command1 + ", WAS all in upper case")

        else:
            speech.speak("Not recognised - Please try again")

calculator.py

import speech

def calculator() :

    def add(x, y):
        return x + y

    def subtract(x, y):
        return x - y

    def multiply(x, y):
        return x * y

    def divide(x, y):
        return x / y

    print("Select option.")
    print("1.Add")
    print("2.Subtract")
    print("3.Multiply")
    print("4.Divide")

    while True:
        choice = input("Enter choice(1/2/3/4): ")

        if choice in ('1', '2', '3', '4'):
            num1 = float(input("Enter first number: "))
            num2 = float(input("Enter second number: "))

            if choice == '1':
                print(num1, "+", num2, "=", add(num1, num2))

            elif choice == '2':
                print(num1, "-", num2, "=", subtract(num1, num2))

            elif choice == '3':
                print(num1, "*", num2, "=", multiply(num1, num2))

            elif choice == '4':
                print(num1, "/", num2, "=", divide(num1, num2))
                sum_complete = num1 / num2
                speech.speak(sum_complete)
            break
        else:
            print("Invalid Input")

end.py

def end_program():
    exit(0)

speech.py

import pyttsx3

engine = pyttsx3.init()
voices = engine.getProperty('voices')

#removed now as i only needed this to get the voice ID
#print(voices)
#print(voices[0])
#print(voices[1])

engine.setProperty('voice', voices[1].id)

def speak(audio) :
    engine.say(audio)
    engine.runAndWait()
    engine.stop()

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *