mirror of
https://github.com/aljazceru/Auto-GPT.git
synced 2026-01-16 12:34:20 +01:00
Gives Auto-GPT a voice!
The AI now spesks it's thoughts every turn.
This commit is contained in:
@@ -56,6 +56,7 @@ RESPONSE FORMAT:
|
||||
"reasoning": "reasoning",
|
||||
"plan": "short bulleted long-term plan",
|
||||
"criticism": "constructive self-criticism"
|
||||
"speak": "thoughts summary to say to user"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ import chat
|
||||
from colorama import Fore, Style
|
||||
from spinner import Spinner
|
||||
import time
|
||||
import speak
|
||||
|
||||
def print_to_console(title, title_color, content, min_typing_speed=0.05, max_typing_speed=0.01):
|
||||
print(title_color + title + " " + Style.RESET_ALL, end="")
|
||||
@@ -35,11 +36,13 @@ def print_assistant_thoughts(assistant_reply):
|
||||
assistant_thoughts_reasoning = assistant_thoughts.get("reasoning")
|
||||
assistant_thoughts_plan = assistant_thoughts.get("plan")
|
||||
assistant_thoughts_criticism = assistant_thoughts.get("criticism")
|
||||
assistant_thoughts_speak = assistant_thoughts.get("speak")
|
||||
else:
|
||||
assistant_thoughts_text = None
|
||||
assistant_thoughts_reasoning = None
|
||||
assistant_thoughts_plan = None
|
||||
assistant_thoughts_criticism = None
|
||||
assistant_thoughts_speak = None
|
||||
|
||||
print_to_console(f"{ai_name.upper()} THOUGHTS:", Fore.YELLOW, assistant_thoughts_text)
|
||||
print_to_console("REASONING:", Fore.YELLOW, assistant_thoughts_reasoning)
|
||||
@@ -57,6 +60,10 @@ def print_assistant_thoughts(assistant_reply):
|
||||
print_to_console("- ", Fore.GREEN, line.strip())
|
||||
print_to_console("CRITICISM:", Fore.YELLOW, assistant_thoughts_criticism)
|
||||
|
||||
# Speak the assistant's thoughts
|
||||
if assistant_thoughts_speak:
|
||||
speak.say_text(assistant_thoughts_speak)
|
||||
|
||||
except json.decoder.JSONDecodeError:
|
||||
print_to_console("Error: Invalid JSON\n", Fore.RED, assistant_reply)
|
||||
# All other errors, return "Error: + error message"
|
||||
|
||||
29
AutonomousAI/speak.py
Normal file
29
AutonomousAI/speak.py
Normal file
@@ -0,0 +1,29 @@
|
||||
import os
|
||||
from playsound import playsound
|
||||
import requests
|
||||
import keys
|
||||
|
||||
voice_id = "ErXwobaYiN019PkySvjV"
|
||||
tts_url = "https://api.elevenlabs.io/v1/text-to-speech/{voice_id}".format(voice_id=voice_id)
|
||||
|
||||
tts_headers = {
|
||||
"Content-Type": "application/json",
|
||||
"xi-api-key": keys.ELEVENLABS_API_KEY
|
||||
}
|
||||
|
||||
|
||||
def say_text(text):
|
||||
formatted_message = {"text": text}
|
||||
response = requests.post(
|
||||
tts_url, headers=tts_headers, json=formatted_message)
|
||||
|
||||
if response.status_code == 200:
|
||||
with open("speech.mpeg", "wb") as f:
|
||||
f.write(response.content)
|
||||
playsound("speech.mpeg")
|
||||
# Delete audio file
|
||||
os.remove("speech.mpeg")
|
||||
else:
|
||||
print("Request failed with status code:", response.status_code)
|
||||
print("Response content:", response.content)
|
||||
|
||||
Reference in New Issue
Block a user