filmov
tv
ChatGPT + Raspberry Pi - A ChatGPT powered Raspberry Pi chatbot

Показать описание
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)
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)
Комментарии