You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
chat-savant/chat_savant/elevenlabs.py

41 lines
996 B
Python

"""
Uses the Eleven Labs Python library and API to stream audio.
"""
from elevenlabs import Voice, generate, set_api_key, stream, voices
from .settings import savant_settings
set_api_key(savant_settings.eleven_labs_api_key.get_secret_value())
voices = voices()
drew_voice = voices[-1]
drew_voice.settings.stability = 0.3
drew_voice.settings.similarity_boost = 0.9
def get_voice_model(model_name: str, voices: list[Voice]) -> Voice:
target_voice = None
for v in voices:
if v.name == model_name:
target_voice = v
if target_voice is None:
raise ValueError(f"Voice Model: {model_name} not found.")
return target_voice
def generate_audio(input_text: str = "") -> None:
audio_stream = generate(text=input_text, voice=voices[-1], stream=True)
stream(audio_stream)
def main():
while True:
input_text = input("Say something in Drew's voice: ")
generate_audio(input_text=input_text)
if __name__ == "__main__":
main()