Microsoft Edge TTS - FREE with HF
Free and fast multilingual edge tts from hugging face space api. Added Fr, De, En, Es. Could add more just check https://huggingface.co/spaces/innoai/Edge-TTS-Text-to-Speech api for more lang Using lower() to ensure the code lang format. Usage : python main.py --voice fr
evrardt committed
Aug 7, 2024 at 20:36 UTC
78d1920c21d20f31de236cd02602ec87a5d31780
3 files changed
+44
-5
main.py
+11
-4
@@ -1,4 +1,4 @@
1
-import threading, time, models, os
1
+import threading, time, models, os, sys, argparse, asyncio
2
from ansio import application_keypad, mouse_input, raw_input
3
from ansio.input import InputEvent, get_input_event
4
from agent import Agent, AgentConfig
@@ -6,11 +6,18 @@ from python.helpers.print_style import PrintStyle
6
from python.helpers.files import read_file
7
from python.helpers import files
8
import python.helpers.timed_input as timed_input
9
-
9
+from tts import TTS
10
11
input_lock = threading.Lock()
12
os.chdir(files.get_abs_path("./work_dir")) #change CWD to work_dir
13
14
+# args parser
15
+parser = argparse.ArgumentParser()
16
+parser.add_argument('-v', '--voice')
17
+args = parser.parse_args()
18
+
19
+# init tts (text to speech)
20
+tts = TTS(args.voice)
21
22
def initialize():
23
@@ -108,8 +115,8 @@ def chat(agent:Agent):
115
116
# print agent0 response
117
PrintStyle(font_color="white",background_color="#1D8348", bold=True, padding=True).print(f"{agent.agent_name}: reponse:")
111
- PrintStyle(font_color="white").print(f"{assistant_response}")
112
-
118
+ PrintStyle(font_color="white").print(f"{assistant_response}")
119
+ tts.speech(assistant_response)
120
121
# User intervention during agent streaming
122
def intervention():
requirements.txt
+3
-1
@@ -12,4 +12,6 @@ sentence-transformers==3.0.1
12
docker==7.1.0
13
paramiko==3.4.0
14
duckduckgo_search==6.1.12
15
-inputimeout==1.0.4
\ No newline at end of file
15
+inputimeout==1.0.4
16
+gradio_client==1.2.0
17
+pygame==2.6.0
\ No newline at end of file
tts.py
new
+30
@@ -0,0 +1,30 @@
1
+from gradio_client import Client
2
+import os
3
+import pygame.mixer
4
+
5
+client = Client("innoai/Edge-TTS-Text-to-Speech")
6
+pygame.mixer.init()
7
+lang = "en-US-AndrewMultilingualNeural"
8
+
9
+class TTS:
10
+ def __init__(self, lang):
11
+ if (lang.lower() == 'fr'):
12
+ lang == "fr-FR-RemyMultilingualNeural"
13
+ elif (lang.lower() == 'es'):
14
+ lang == "es-ES-AlvaroNeural"
15
+ elif (lang.lower() == 'de'):
16
+ lang == "de-DE-FlorianMultilingualNeural"
17
+ else:
18
+ lang == "en-US-AndrewMultilingualNeural"
19
+
20
+ def speech(self, text):
21
+ speech = client.predict(
22
+ text=text,
23
+ voice=lang,
24
+ rate=20,
25
+ pitch=0,
26
+ api_name="/predict"
27
+ )
28
+ pygame.mixer.music.load(speech[0]) # chargement de la musique
29
+ pygame.mixer.music.play() # la musique est jouée
30
+
\ No newline at end of file