-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtts_engine.py
More file actions
27 lines (24 loc) · 748 Bytes
/
tts_engine.py
File metadata and controls
27 lines (24 loc) · 748 Bytes
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
import asyncio
import edge_tts
import os
import tempfile
import uuid
import playsound
VOICE = "en-US-AriaNeural"
RATE = "+0%"
async def speak_async(text: str):
# Use a unique temporary file to avoid conflicts
temp_file = os.path.join(tempfile.gettempdir(), f"jarvis_tts_{uuid.uuid4().hex}.mp3")
try:
communicate = edge_tts.Communicate(text, voice=VOICE, rate=RATE)
await communicate.save(temp_file)
playsound.playsound(temp_file)
finally:
try:
if os.path.exists(temp_file):
os.remove(temp_file)
except Exception:
pass # ignore rare Windows file-lock race
def speak(text: str):
print(f"🗣️ Jarvis: {text}")
asyncio.run(speak_async(text))