-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
69 lines (57 loc) · 3.05 KB
/
main.py
File metadata and controls
69 lines (57 loc) · 3.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
"""
UltraAgent is an AI agent with real-world powers to control many applications.
Copyright (C) 2024 Olav "Olavorw" Sharma - 4934 Tech
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
from src.audio.recognizer import recognize_speech
from src.audio.elevenlabs_tts import speak_with_elevenlabs
from src.conversation.conversation_runner import run_conversation
from src.config.env import OPENAI_API_KEY, GOVEE_API_KEY, ELEVENLABS_API_KEY, SPOTIFY_CLIENT_ID, SPOTIFY_CLIENT_SECRET, SPOTIFY_REDIRECT_URI
from src.api.openai_client import create_openai_client
from src.audio.tts_controller import play_tts_with_interruption
def run_voice_conversation(voice_id):
# Initialize OpenAI client
client = create_openai_client(OPENAI_API_KEY)
# Create API keys dictionary
api_keys = {
"OPENAI_API_KEY": OPENAI_API_KEY,
"GOVEE_API_KEY": GOVEE_API_KEY,
"ELEVENLABS_API_KEY": ELEVENLABS_API_KEY,
"SPOTIFY_CLIENT_ID": SPOTIFY_CLIENT_ID,
"SPOTIFY_CLIENT_SECRET": SPOTIFY_CLIENT_SECRET,
"SPOTIFY_REDIRECT_URI": SPOTIFY_REDIRECT_URI
}
print("Voice assistant initialized. Say 'exit' to end the session.")
speak_with_elevenlabs(ELEVENLABS_API_KEY, "Phoenix listening in.", voice_id)
messages = []
while True:
user_message = recognize_speech()
if not user_message:
continue
print(f"You: {user_message}")
if user_message.lower() == "exit":
speak_with_elevenlabs(ELEVENLABS_API_KEY, "Phoenix out.", voice_id)
break
response = run_conversation(user_message, client, api_keys, messages)
print(f"Assistant: {response}")
interruption = play_tts_with_interruption(ELEVENLABS_API_KEY, response, voice_id)
while interruption:
print(f"You (interruption): {interruption}")
response = run_conversation(interruption, client, api_keys, messages)
print(f"Assistant: {response}")
interruption = play_tts_with_interruption(ELEVENLABS_API_KEY, response, voice_id)
if __name__ == "__main__":
print("UltraAgent Copyright (C) 2024 Olav Sharma - 4934.tech")
print("This program comes with ABSOLUTELY NO WARRANTY.")
print("This is free software, and you are welcome to redistribute it")
print("under certain conditions. To learn more, go to: <https://github.com/4934tech/UltraAgent/blob/master/license.md> for details.\n")
run_voice_conversation("uIOPHXRRaPBHQzb3tDcx")