Skip to content

Commit

Permalink
Merge pull request Significant-Gravitas#754 from meta-fx/added-new-voice
Browse files Browse the repository at this point in the history
Added new env variable and speech function for alternative TTS voice
  • Loading branch information
p-i- authored Apr 14, 2023
2 parents 98efd26 + 1612069 commit aca16db
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
4 changes: 4 additions & 0 deletions .env.template
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions scripts/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ def __init__(self):
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")

Expand Down
24 changes: 23 additions & 1 deletion scripts/speak.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down

0 comments on commit aca16db

Please sign in to comment.