Merge pull request #754 from meta-fx/added-new-voice
Added new env variable and speech function for alternative TTS voicepull/1326/head
commit
aca16dbc5d
|
@ -102,6 +102,10 @@ CUSTOM_SEARCH_ENGINE_ID=your-custom-search-engine-id
|
|||
# USE_MAC_OS_TTS - Use Mac OS TTS or not (Default: False)
|
||||
USE_MAC_OS_TTS=False
|
||||
|
||||
### STREAMELEMENTS
|
||||
# USE_BRIAN_TTS - Use Brian TTS or not (Default: False)
|
||||
USE_BRIAN_TTS=False
|
||||
|
||||
### ELEVENLABS
|
||||
# ELEVENLABS_API_KEY - Eleven Labs API key (Example: my-elevenlabs-api-key)
|
||||
# ELEVENLABS_VOICE_1_ID - Eleven Labs voice 1 ID (Example: my-voice-id-1)
|
||||
|
|
|
@ -62,6 +62,9 @@ class Config(metaclass=Singleton):
|
|||
self.use_mac_os_tts = False
|
||||
self.use_mac_os_tts = os.getenv("USE_MAC_OS_TTS")
|
||||
|
||||
self.use_brian_tts = False
|
||||
self.use_brian_tts = os.getenv("USE_BRIAN_TTS")
|
||||
|
||||
self.google_api_key = os.getenv("GOOGLE_API_KEY")
|
||||
self.custom_search_engine_id = os.getenv("CUSTOM_SEARCH_ENGINE_ID")
|
||||
|
||||
|
|
|
@ -53,6 +53,24 @@ def eleven_labs_speech(text, voice_index=0):
|
|||
return False
|
||||
|
||||
|
||||
def brian_speech(text):
|
||||
"""Speak text using Brian with the streamelements API"""
|
||||
tts_url = f"https://api.streamelements.com/kappa/v2/speech?voice=Brian&text={text}"
|
||||
response = requests.get(tts_url)
|
||||
|
||||
if response.status_code == 200:
|
||||
with mutex_lock:
|
||||
with open("speech.mp3", "wb") as f:
|
||||
f.write(response.content)
|
||||
playsound("speech.mp3")
|
||||
os.remove("speech.mp3")
|
||||
return True
|
||||
else:
|
||||
print("Request failed with status code:", response.status_code)
|
||||
print("Response content:", response.content)
|
||||
return False
|
||||
|
||||
|
||||
def gtts_speech(text):
|
||||
tts = gtts.gTTS(text)
|
||||
with mutex_lock:
|
||||
|
@ -76,7 +94,11 @@ def say_text(text, voice_index=0):
|
|||
def speak():
|
||||
if not cfg.elevenlabs_api_key:
|
||||
if cfg.use_mac_os_tts == 'True':
|
||||
macos_tts_speech(text, voice_index)
|
||||
macos_tts_speech(text)
|
||||
elif cfg.use_brian_tts == 'True':
|
||||
success = brian_speech(text)
|
||||
if not success:
|
||||
gtts_speech(text)
|
||||
else:
|
||||
gtts_speech(text)
|
||||
else:
|
||||
|
|
Loading…
Reference in New Issue