Update tts_module.py
Browse files- tts_module.py +15 -8
tts_module.py
CHANGED
@@ -1,8 +1,15 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import pyttsx3
|
2 |
+
import tempfile
|
3 |
+
|
4 |
+
async def get_voices():
|
5 |
+
engine = pyttsx3.init()
|
6 |
+
voices = engine.getProperty('voices')
|
7 |
+
return {f"{v.name} - {v.languages[0]} ({v.gender})": v.id for v in voices}
|
8 |
+
|
9 |
+
async def text_to_speech(text, voice_id):
|
10 |
+
engine = pyttsx3.init()
|
11 |
+
engine.setProperty('voice', voice_id)
|
12 |
+
with tempfile.NamedTemporaryFile(delete=False, suffix=".mp3") as tmp_file:
|
13 |
+
engine.save_to_file(text, tmp_file.name)
|
14 |
+
engine.runAndWait()
|
15 |
+
return tmp_file.name
|