gnosticdev commited on
Commit
3c0130e
·
verified ·
1 Parent(s): a722dd7

Update tts_module.py

Browse files
Files changed (1) hide show
  1. tts_module.py +15 -8
tts_module.py CHANGED
@@ -1,8 +1,15 @@
1
- gradio
2
- pyttsx3
3
- moviepy==1.0.3
4
- pydub
5
- ffmpeg-python
6
- transformers
7
- torch
8
- requests
 
 
 
 
 
 
 
 
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