diff --git a/chat_savant/elevenlabs.py b/chat_savant/elevenlabs.py index e69de29..c2f4603 100644 --- a/chat_savant/elevenlabs.py +++ b/chat_savant/elevenlabs.py @@ -0,0 +1,40 @@ +""" +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() diff --git a/chat_savant/settings.py b/chat_savant/settings.py index 665333a..0952440 100644 --- a/chat_savant/settings.py +++ b/chat_savant/settings.py @@ -10,6 +10,9 @@ class SavantSettings(BaseSettings): eleven_labs_api_key: SecretStr = Field( default="", description="An optional Eleven Labs API key for text to speech." ) + eleven_labs_model: str = Field( + default="Arnold", description="The text-to-speech model name used in eleven labs audio generation." + ) llm_model_name: str = Field( default="eachadea_vicuna-7b-1.1", description="The large language model name used in API requests." ) diff --git a/pyproject.toml b/pyproject.toml index 9f863f7..416b499 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -22,7 +22,7 @@ savant-cli = "chat_savant.cli:main" [project.optional-dependencies] whisper = ["openai-whisper"] -elevenlabs = ["elevenlabs", "mpv"] +elevenlabs = ["elevenlabs>=0.2.16,<=0.3.0", "mpv"] [tool.setuptools] packages = ["chat_savant"] diff --git a/tests/unit/test_settings.py b/tests/unit/test_settings.py index eb2d2bf..d1eef67 100644 --- a/tests/unit/test_settings.py +++ b/tests/unit/test_settings.py @@ -10,6 +10,7 @@ SETTING_DEFAULTS = { "OPENAI_API_BASE": "http://localhost:8000/v1", "LLM_MODEL_NAME": "eachadea_vicuna-7b-1.1", "ELEVEN_LABS_API_KEY": "", + "ELEVEN_LABS_MODEL": "", }