Create a Voice Assistant with ChatGPT API (Python Tutorial) - Super Easy !

preview_player
Показать описание
Welcome to the ultimate tutorial for programming your very own ChatGPT-powered voice assistant inspired by the Friday of Iron Man movie. In this video, I'll guide you through the process of building an intelligent AI assistant using Python that leaves Siri's limitations behind and embraces the prowess of ChatGPT.

Even if you're new to Python and AI, don't worry ?! I got you covered! I'll take you through each step of the process, explaining every line of code so you can follow along and learn with ease. This project offers a fantastic opportunity for anyone interested in diving into the world of ChatGPT, Python, and Artificial Intelligence.

By the end of this tutorial, you'll have your own personal Friday-style voice assistant, making your AI chatting experience more engaging than ever.

Don't miss out on this chance to expand your AI skills and create a voice assistant that brings a touch of the Marvel Universe into your daily life.

Watch the tutorial now, and embark on the exciting journey of building your AI-powered personal assistant! And while you're at it, don't forget to like, comment, and subscribe for more amazing tech content. Thank you !

00:00 Introduction
00:36 Installation
17:14 Testing
Рекомендации по теме
Комментарии
Автор

Made my first working AI assistant. Thanks to your beautiful video. Good job. Keep learning and sharing

randomstuffs
Автор

import openai
import pyttsx3
import speech_recognition as sr
import random

# Set OpenAI API key
openai.api_key = insert your api
model_id = 'gpt-3.5-turbo'

# Initialize the text-to-speech engine
engine = pyttsx3.init()

# Change speech rate
engine.setProperty('rate', 180)

# Get the avaiable voice
voices = engine.getProperty('voices')

# Choose a voice based on the voice id
engine.setProperty('voice', voices[0].id)

# Counter just for interacting purposes
interaction_counter = 0


def
recognizer = sr.Recognizer()
with sr.AudioFile(filename) as source:
audio = recognizer.record(source)
try:
return
except:
print("")
#print('Skipping unknown error')


def
response =
model=model_id,
messages=conversation
)
api_usage = response['usage']
print('Total token consumed:
conversation.append({'role': response.choices[0].message.role, 'content':
return conversation


def speak_text(text):
engine.say(text)
engine.runAndWait()


# Starting conversation
conversation = []
conversation.append({'role': 'user', 'content': 'chat with me as you be Friday AI from Iron Man, please make a one sentence phrase introducing yourself without saying something that sounds like this chat its already started'})
conversation =
print('{0}: {1}\n'.format(conversation[-1]['role'].strip(),



def activate_assistant():
starting_chat_phrases = ["Yes sir, how may I assist you?",
"Yes, What can I do for you?",
"How can I help you, sir?",
"Friday at your service, what do you need?",
"Friday here, how can I help you today?",
"Yes, what can I do for you today?",
"Yes sir, what's on your mind?",
"Friday ready to assist, what can I do for you?",
"At your command, sir. How may I help you today?",
"Yes, sir. How may I be of assistance to you right now?",
"Yes boss, I'm here to help. What do you need from me?",
"Yes, I'm listening. What can I do for you, sir?",
"How can I assist you today, sir?",
"Friday here, ready and eager to help. What can I do for you?",
"Yes, sir. How can I make your day easier?",
"Yes boss, what's the plan? How can I assist you today?",
"Yes, I'm here and ready to assist. What's on your mind, sir?"]

continued_chat_phrases = ["yes", "yes, sir", "yes, boss", "I'm all ears"]

random_chat = ""
if(interaction_counter == 1):
random_chat =
else:
random_chat =

return random_chat


def append_to_log(text):
with open("chat_log.txt", "a") as f:
f.write(text + "\n")


while True:

#wait for users to say "Friday"
print("Say 'Friday' to start...")
recognizer = sr.Recognizer()

with sr.Microphone() as source:
audio = recognizer.listen(source)
try:
transcription =
if "friday" in transcription.lower():
interaction_counter += 1
# Record audio
filename = "input.wav"
readyToWork = activate_assistant()
speak_text(readyToWork)
print(readyToWork)
recognizer = sr.Recognizer()
with sr.Microphone() as source:
source.pause_threshold = 1
audio = recognizer.listen(source, phrase_time_limit=None, timeout=None)
with open(filename, "wb") as f:


# Transcribe audio to text
text =
if text:
print(f"You said: {text}")
append_to_log(f"You: {text}\n")

# Generate response using chatGPT
print(f"Friday says: {conversation}")

prompt = text
conversation.append({'role': 'user', 'content': prompt})
conversation =

print('{0}: {1}\n'.format(conversation[-1]['role'].strip(),

append_to_log(f"Friday:

# Read response using text-to-speech


# In future maybe a conversation.clear to decrease input tokens as the conversation evolves ...

except Exception as e:
continue
#print("An error occurred: {}".format(e))

ee
Автор

i was making my own ai and was stuck on the hotword detection part....thank god i saw this vid...thanks bro..

theweirdboy
Автор

Hi, great stuff! Nice. But this only runs when we open python, is there any video in future that you''ll do...to show how can make it work on simple web-based?

shawnmckenzie
Автор

Hey nice vid, easy to follow. Sadly I tried both following the vid and using your github code, but once I run the assistant it gets stuck.
"Say 'Friday' to start...", when I do I know the program hears me because it creates a loop of "Say 'Friday' to start..." when I say anything, but the code does not go any further. Any advice?

jkrekels
Автор

hey im having an issue after writing the code when i run code it gives error for openai it says open ai has migrated can you help me to fix this issue?

RaghuShukla
Автор

Hey nice vid, easy to follow. Sadly I tried both following the vid and using your github code, but once I run the assistant it gets stuck.
"Say 'Friday' to start...", when I do I know the program hears me because it creates a loop of "Say 'Friday' to start..." when I say anything, but the code does not go any further. check the code and update it .

fnzdtus
Автор

Hi sifu,
Works fine in localhost environment. But when uploaded in server side, it cannot function as it is...anything I missing?

shawnmckenzie_offcial
Автор

it cant hear me, i tested other stt programs and they work fine, any tips?

human-ebjp
Автор

It looks like you're encountering a RateLimitError again, indicating that you've exceeded your current quota for API requests. This error occurs when your application makes too many requests within a given time period, exceeding the usage limits defined by your plan.
how to reslove this error

vinay
Автор

Why doesn't this have a repo ? :D such a good project

FeelingLike
Автор

What about the memory problem? I want a personalized AI bot on my PC that could run offline an has long term memory of past conversations, me as a user etc. Using an API key, as I understand, you are still dependant on their servers and limited in conversation length right? How to get around that?

stonaraptor
Автор

Sir, I am getting error as You exceeded your current quota, please check your plan and billing details. I don't have active ChatGPT plan, cant I run it, without any paid plan

chethansprabhu
Автор

Hello i completed all the process a the end say me this Process finished with exit code 0 lookin in internet found “Process finished with exit code 0” message, that means that the code ran correctly, but nothing else does that.

yutsudark
Автор

bro help me im getting this error "openai.error.RateLimitError: You exceeded your current quota, please check your plan and billing details.'"

believeitsreal
Автор

Hey super project have been looking for incredibly long for such a video that can explain that well but I wanted to ask how I can change the language to German and then I want to change the name of the assistant the next problem is that the voice output of the Ai sounds very strange not at all like in your video if you could help me would be that really nice :)

pbxoovo
Автор

can you make this assistant reproduce some tasks, like: open YouTube, see calendar, see weather, connect with data base?

danielfernandow
Автор

thanks for the tutorial but how do i change the voice to a males voice and how do i change the name from Friday to my name haven't started designing the project but soon i want to start it and another thing how do i generate an apk file to install my finished app on mobile devices, ,,thank you in advance

sympson
Автор

Hi I try use your code sometimes its worked when i say " Friday" but sometimes its not give any respond. Can anyone tell me what is the problem? because its does not have any errors.

amirulmukminin
Автор

After wasting 2-3 hrs figuring out how to make this asssistant, i realised you need to purchase gpt api to make this work

ara_vind_.