ChatGPT + Raspberry Pi - A ChatGPT powered Raspberry Pi chatbot

preview_player
Показать описание
A beginner-friendly way to combine Chat GPT & Raspberry Pi.

0:00 Building
5:36 Demo Chatbot
Guide:

Terminal commands:

1. Installing libraries/dependencies

sudo apt update
sudo apt upgrade

python3 -m pip install python-dotenv
pip3 install openai dotenv SpeechRecognition pyttsx3 gtts PyAudio
sudo apt install python3-pyaudio flac python3-espeak espeak python3-dotenv
pip uninstall dotenv
pip install python-dotenv

*Change audio to HDMI

2. Python script

Python script:

import os
import openai
from dotenv import load_dotenv
import time
import speech_recognition as sr
import pyttsx3
import numpy as np
from gtts import gTTS

mytext = 'Welcome to me'
language = 'en'
# ^ matplotlib is great for visualising data and for testing purposes but usually not needed for production
load_dotenv()
model = 'gpt-3.5-turbo'
# Set up the speech recognition and text-to-speech engines
r = sr.Recognizer()
name = "YOUR NAME HERE"
greetings = [f"whats up master {name}",
"yeah?",
"Well, hello there, Master of Puns and Jokes - how's it going today?",
f"Ahoy there, Captain {name}! How's the ship sailing?",
f"Bonjour, Monsieur {name}! Comment ça va? Wait, why the hell am I speaking French?" ]

# Listen for the wake word "hey pos"
def listen_for_wake_word(source):
print("Listening for 'Hey'...")

while True:
try:
print("Wake word detected.")
listen_and_respond(source)
break
except sr.UnknownValueError:
pass
# Listen for input and respond with OpenAI API
def listen_and_respond(source):
print("Listening...")

while True:
try:
print(f"You said: {text}")
if not text:
continue

# Send input to OpenAI API
print(response_text)
#myobj = gTTS(text = response_text, lang = language, slow = False)
# Speak the response
print("speaking")

if not audio:
listen_for_wake_word(source)
except sr.UnknownValueError:
print("Silence found, shutting up, listening...")
listen_for_wake_word(source)
break

except sr.RequestError as e:
print(f"Could not request results; {e}")
listen_for_wake_word(source)
break

# Use the default microphone as the audio source
with sr.Microphone() as source:
listen_for_wake_word(source)
Рекомендации по теме
Комментарии
Автор

I tried to install all the libraries. Only with PyAudio did this go wrong. Eventually, I got it to work. By the following commands:

sudo apt install libasound-dev portaudio19-dev
libportaudio2 libportaudiocpp0

After that sudo apt install ffmpeg and than run

python3 -m pip install pyaudio

Everything works great

geoffreygeo
Автор

Just came across, a totally amazing project. Perhaps the ultimate stage of this would be a bot that activates only on a certain voice command so what you chat in a room does not get sent to gpt unless you ask for this, and a real non-robotic voice of your choice. I am impressed, thank you!

alexpapou
Автор

Amazing work dude. Also congrats on accomplishing 100 subs. Have a great day!
- your 100th subscriber

JohnDoe-ogkz
Автор

Thanks this worked well i can now use chatgpt as a voice command to turn on the laser

Skibidioo
Автор

The first time I saw this video, I was intrigued, but now ChatGPT has its own speech conversation function.

lzcell
Автор

GENIUS! This is exactly what I was looking for, thanks!

WINTERMUTE_AI
Автор

ill start my project with yours as guidance to make my own, awesome and simple. Thank you!

charlesmarchand
Автор

Thx this is so cool your 1000th subscriber

betrayedsoul
Автор

Great ChatGPT chatbot! Awesome! Hi Thomas I have a Raspberry PI 5, a ollama with tinyollama setup on my system with an ollama webui as frontend. It works and the responses are good enough as far as speed is concerned. I already installed piper and the voice sounds natural and perhaps add whisper next for an all out local project. Do you know a way on how I can this all integrated together. I'll be looking forward to your next video.🌟🌟👍

jtr
Автор

I have been thinking of this for a few days now ! Thanks Thomas !!

mercy
Автор

Perfect, now it needs to be also a media player for spotify and other stream and be able to control home assistant devices :) Thanks

jacquesdupontd
Автор

thank you it very interesting to see somone of your age do a project like this

pilqpj
Автор

That’s amazing! Bravo👏🏻 congrats… but is possible change the chatbot voice? For example my voice?

davyponte
Автор

Wow incredible work here!! Very inspiring!!!

Kataroobungaloo
Автор

Wow, thanks for this video man.
I was windering, once installed, how can you install this on a rc car?
Have the system roam around with comouter vision, lidar, and other systems for obstacle avoidance, roaming around my property?
Thanks again for this informative video.

drewski
Автор

Superb project. Just what i was looking for.

markboweringphotography
Автор

When I copy and paste the libraries/dependencies code I get a error then I go into a virtual environment then do it again it works but then I get more errors stating that it can't find dotenv idk what I'm doing wrong but I followed this video to a T and nothing's working

TheCryptoCollective
Автор

most interesting project! didn't know raspberry pi can run chatgpt

elvenkim
Автор

this is awesome ive been trying to do the same project over the last week. i set up your code to use as an example for mine, but its running slow do you have any suggestions on how to speed it up? im running it on a rasp pi 4 8gb btw.

johnmatheson
Автор

Not running well, it keeps saying command not found when I type in python 3. gpt.py and I just can’t get it to run

carterkraber