Merge pull request #754 from meta-fx/added-new-voice

Added new env variable and speech function for alternative TTS voice
pull/1326/head
Pi 2023-04-14 14:45:11 +01:00 committed by GitHub
commit aca16dbc5d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 30 additions and 1 deletions

View File

@ -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 - Use Mac OS TTS or not (Default: False)
USE_MAC_OS_TTS=False USE_MAC_OS_TTS=False
### STREAMELEMENTS
# USE_BRIAN_TTS - Use Brian TTS or not (Default: False)
USE_BRIAN_TTS=False
### ELEVENLABS ### ELEVENLABS
# ELEVENLABS_API_KEY - Eleven Labs API key (Example: my-elevenlabs-api-key) # 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) # ELEVENLABS_VOICE_1_ID - Eleven Labs voice 1 ID (Example: my-voice-id-1)

View File

@ -62,6 +62,9 @@ class Config(metaclass=Singleton):
self.use_mac_os_tts = False self.use_mac_os_tts = False
self.use_mac_os_tts = os.getenv("USE_MAC_OS_TTS") 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.google_api_key = os.getenv("GOOGLE_API_KEY")
self.custom_search_engine_id = os.getenv("CUSTOM_SEARCH_ENGINE_ID") self.custom_search_engine_id = os.getenv("CUSTOM_SEARCH_ENGINE_ID")

View File

@ -53,6 +53,24 @@ def eleven_labs_speech(text, voice_index=0):
return False 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): def gtts_speech(text):
tts = gtts.gTTS(text) tts = gtts.gTTS(text)
with mutex_lock: with mutex_lock:
@ -76,7 +94,11 @@ def say_text(text, voice_index=0):
def speak(): def speak():
if not cfg.elevenlabs_api_key: if not cfg.elevenlabs_api_key:
if cfg.use_mac_os_tts == 'True': 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: else:
gtts_speech(text) gtts_speech(text)
else: else: