Skip to content

Agent Zero AI framework

Microsoft Edge TTS - FREE with HF

evrardt78d1920c21d2
diff --git a/main.py b/main.py
index 368a96fa1..3b7a32b72 100644
--- a/main.py
+++ b/main.py
@@ -1,4 +1,4 @@
-import threading, time, models, os
+import threading, time, models, os, sys, argparse, asyncio
from ansio import application_keypad, mouse_input, raw_input
from ansio.input import InputEvent, get_input_event
from agent import Agent, AgentConfig
@@ -6,11 +6,18 @@ from python.helpers.print_style import PrintStyle
from python.helpers.files import read_file
from python.helpers import files
import python.helpers.timed_input as timed_input
-
+from tts import TTS
input_lock = threading.Lock()
os.chdir(files.get_abs_path("./work_dir")) #change CWD to work_dir
+# args parser
+parser = argparse.ArgumentParser()
+parser.add_argument('-v', '--voice')
+args = parser.parse_args()
+
+# init tts (text to speech)
+tts = TTS(args.voice)
def initialize():
@@ -108,8 +115,8 @@ def chat(agent:Agent):
# print agent0 response
PrintStyle(font_color="white",background_color="#1D8348", bold=True, padding=True).print(f"{agent.agent_name}: reponse:")
- PrintStyle(font_color="white").print(f"{assistant_response}")
-
+ PrintStyle(font_color="white").print(f"{assistant_response}")
+ tts.speech(assistant_response)
# User intervention during agent streaming
def intervention():
diff --git a/requirements.txt b/requirements.txt
index a1f1a2f25..90e293e9b 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -12,4 +12,6 @@ sentence-transformers==3.0.1
docker==7.1.0
paramiko==3.4.0
duckduckgo_search==6.1.12
-inputimeout==1.0.4
\ No newline at end of file
+inputimeout==1.0.4
+gradio_client==1.2.0
+pygame==2.6.0
\ No newline at end of file
diff --git a/tts.py b/tts.py
new file mode 100644
index 000000000..86aeadf5b
--- /dev/null
+++ b/tts.py
@@ -0,0 +1,30 @@
+from gradio_client import Client
+import os
+import pygame.mixer
+
+client = Client("innoai/Edge-TTS-Text-to-Speech")
+pygame.mixer.init()
+lang = "en-US-AndrewMultilingualNeural"
+
+class TTS:
+ def __init__(self, lang):
+ if (lang.lower() == 'fr'):
+ lang == "fr-FR-RemyMultilingualNeural"
+ elif (lang.lower() == 'es'):
+ lang == "es-ES-AlvaroNeural"
+ elif (lang.lower() == 'de'):
+ lang == "de-DE-FlorianMultilingualNeural"
+ else:
+ lang == "en-US-AndrewMultilingualNeural"
+
+ def speech(self, text):
+ speech = client.predict(
+ text=text,
+ voice=lang,
+ rate=20,
+ pitch=0,
+ api_name="/predict"
+ )
+ pygame.mixer.music.load(speech[0]) # chargement de la musique
+ pygame.mixer.music.play() # la musique est jouée
+
\ No newline at end of file