[Bug]:
Geneticscrol opened this issue · comments
Is there an existing issue for this?
- I have searched the existing issues and checked the recent builds/commits
What happened?
i was following an online tutorial about using edgegpt from youtube and i copied this code
import openai
import asyncio
import re
import whisper
import boto3
import pydub
from pydub import playback
import speech_recognition as sr
from EdgeGPT import Chatbot, ConversationStyle
# Initialize the OpenAI API
openai.api_key = "..."
# Create a recognizer object and wake word variables
recognizer = sr.Recognizer()
BING_WAKE_WORD = "bing"
GPT_WAKE_WORD = "gpt"
def get_wake_word(phrase):
if BING_WAKE_WORD in phrase.lower():
return BING_WAKE_WORD
elif GPT_WAKE_WORD in phrase.lower():
return GPT_WAKE_WORD
else:
return None
def synthesize_speech(text, output_filename):
polly = boto3.client("polly", region_name="us-west-2")
response = polly.synthesize_speech(
Text=text, OutputFormat="mp3", VoiceId="Salli", Engine="neural"
)
with open(output_filename, "wb") as f:
f.write(response["AudioStream"].read())
def play_audio(file):
sound = pydub.AudioSegment.from_file(file, format="mp3")
playback.play(sound)
async def main():
while True:
with sr.Microphone() as source:
recognizer.adjust_for_ambient_noise(source)
print(f"Waiting for wake words 'ok bing' or 'ok chat'...")
while True:
audio = recognizer.listen(source)
try:
with open("audio.wav", "wb") as f:
f.write(audio.get_wav_data())
# Use the preloaded tiny_model
model = whisper.load_model("tiny")
result = model.transcribe("audio.wav")
phrase = result["text"]
print(f"You said: {phrase}")
wake_word = get_wake_word(phrase)
if wake_word is not None:
break
else:
print("Not a wake word. Try again.")
except Exception as e:
print("Error transcribing audio: {0}".format(e))
continue
print("Speak a prompt...")
synthesize_speech("What can I help you with?", "response.mp3")
play_audio("response.mp3")
audio = recognizer.listen(source)
try:
with open("audio_prompt.wav", "wb") as f:
f.write(audio.get_wav_data())
model = whisper.load_model("base")
result = model.transcribe("audio_prompt.wav")
user_input = result["text"]
print(f"You said: {user_input}")
except Exception as e:
print("Error transcribing audio: {0}".format(e))
continue
if wake_word == BING_WAKE_WORD:
bot = Chatbot(cookie_path="cookies.json")
response = await bot.ask(
prompt=user_input, conversation_style=ConversationStyle.precise
)
# Select only the bot response from the response dictionary
for message in response["item"]["messages"]:
if message["author"] == "bot":
bot_response = message["text"]
# Remove [^#^] citations in response
bot_response = re.sub("\[\^\d+\^\]", "", bot_response)
else:
# Send prompt to GPT-3.5-turbo API
response = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": user_input},
],
temperature=0.5,
max_tokens=150,
top_p=1,
frequency_penalty=0,
presence_penalty=0,
n=1,
stop=["\nUser:"],
)
bot_response = response["choices"][0]["message"]["content"]
print("Bot's response:", bot_response)
synthesize_speech(bot_response, "response.mp3")
play_audio("response.mp3")
await bot.close()
if __name__ == "__main__":
asyncio.run(main())
after running i get this error
Traceback (most recent call last):
File "c:\Users\saksh\Development\personal-ai\main.py", line 9, in <module>
from EdgeGPT import Chatbot, ConversationStyle
ImportError: cannot import name 'Chatbot' from 'EdgeGPT' (C:\Users\saksh\scoop\apps\python\current\Lib\site-packages\EdgeGPT\__init__.py)
Steps to reproduce the problem
visit this repo
youtube video
What should have happened?
it should have worked normally and listened for the wakeword.
Version where the problem happens
boto3==1.26.114
EdgeGPT==0.1.23
EdgeGPT==0.1.23
openai==0.27.4
openai_whisper==20230314
pydub==0.25.1
SpeechRecognition==3.10.0
PyAudio==0.2.13
What Python version are you running this with?
3.11.4
What is your operating system ?
Windows
Command Line Arguments
No
Console logs
Traceback (most recent call last):
File "c:\Users\saksh\Development\personal-ai\main.py", line 9, in <module>
from EdgeGPT import Chatbot, ConversationStyle
ImportError: cannot import name 'Chatbot' from 'EdgeGPT' (C:\Users\saksh\scoop\apps\python\current\Lib\site-packages\EdgeGPT\__init__.py)
Additional information
No response
Hey brother you should not provide you openai api key to any one please edit the response quickly or delete the api you provided in this area, any one can use it and your credits will be used up by them
Hey, By the way is this code the same one written by the youtuber called ai austin
from EdgeGPT.EdgeGPT import Chatbot, ConversationStyle
Refer to readme