replace gtts with macos tts

This commit is contained in:
Wlad
2023-04-10 04:21:23 +02:00
parent 816dc14d82
commit 3456090117

View File

@@ -3,11 +3,12 @@ from playsound import playsound
import requests
from config import Config
cfg = Config()
import gtts
# Remove the import of gtts
# import gtts
# TODO: Nicer names for these ids
voices = ["ErXwobaYiN019PkySvjV", "EXAVITQu4vr4xnSDxMaL"]
# Change voices to macOS voice identifiers
voices = ["com.apple.speech.synthesis.voice.siri_female", "com.apple.speech.synthesis.voice.siri_male"]
tts_headers = {
"Content-Type": "application/json",
@@ -32,17 +33,14 @@ def eleven_labs_speech(text, voice_index=0):
print("Response content:", response.content)
return False
def gtts_speech(text):
tts = gtts.gTTS(text)
tts.save("speech.mp3")
playsound("speech.mp3")
os.remove("speech.mp3")
# Use macOS built-in TTS instead of gtts
def macos_tts_speech(text, voice_index=1):
os.system(f'say "{text}"')
def say_text(text, voice_index=0):
if not cfg.elevenlabs_api_key:
gtts_speech(text)
macos_tts_speech(text, voice_index)
else:
success = eleven_labs_speech(text, voice_index)
if not success:
gtts_speech(text)
macos_tts_speech(text, voice_index)