Compare commits
2 Commits
drew/stabl
...
master
Author | SHA1 | Date |
---|---|---|
Drew Bednar | f3ab9b454b | 2 years ago |
Drew Bednar | 3c5c80624c | 2 years ago |
@ -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()
|
@ -0,0 +1,32 @@
|
||||
from pydantic import BaseSettings, Field, SecretStr
|
||||
|
||||
|
||||
class SavantSettings(BaseSettings):
|
||||
"""Savant Application Settings.
|
||||
|
||||
All environment varaibles supplied should be prefixed with "SAVANT_".
|
||||
"""
|
||||
|
||||
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."
|
||||
)
|
||||
openai_api_key: SecretStr = Field(
|
||||
default="EMPTY", description="An OPEN_API_KEY or an empty value if using FastChat replacement server"
|
||||
)
|
||||
openai_api_base: str = Field(
|
||||
default="http://localhost:8000/v1",
|
||||
description="The base url to an OpenAI API compliant endpoint. \
|
||||
Defaulted to FastChat replacement server defaults.",
|
||||
)
|
||||
|
||||
class Config:
|
||||
env_prefix = "SAVANT_"
|
||||
|
||||
|
||||
savant_settings = SavantSettings()
|
@ -0,0 +1 @@
|
||||
pydantic>=1.6.2,<2.0.0
|
@ -1,6 +1,10 @@
|
||||
#
|
||||
# This file is autogenerated by pip-compile with Python 3.11
|
||||
# This file is autogenerated by pip-compile with Python 3.10
|
||||
# by the following command:
|
||||
#
|
||||
# pip-compile --output-file=requirements.txt requirements.in
|
||||
# pip-compile requirements.in
|
||||
#
|
||||
pydantic==1.10.8
|
||||
# via -r requirements.in
|
||||
typing-extensions==4.6.2
|
||||
# via pydantic
|
||||
|
@ -0,0 +1,33 @@
|
||||
import os
|
||||
from unittest.mock import patch
|
||||
|
||||
from pydantic.types import SecretStr
|
||||
|
||||
from chat_savant.settings import SavantSettings
|
||||
|
||||
SETTING_DEFAULTS = {
|
||||
"OPENAI_API_KEY": "EMPTY",
|
||||
"OPENAI_API_BASE": "http://localhost:8000/v1",
|
||||
"LLM_MODEL_NAME": "eachadea_vicuna-7b-1.1",
|
||||
"ELEVEN_LABS_API_KEY": "",
|
||||
"ELEVEN_LABS_MODEL": "",
|
||||
}
|
||||
|
||||
|
||||
def test_setting_defaults():
|
||||
"""Regression test for settings schema."""
|
||||
with patch.dict(os.environ, {}, clear=True):
|
||||
savant_settings = SavantSettings()
|
||||
assert len(savant_settings.dict()) == len(SETTING_DEFAULTS)
|
||||
for k, v in SETTING_DEFAULTS.items():
|
||||
_setting_value = getattr(savant_settings, k.lower())
|
||||
unmasked_setting = (
|
||||
_setting_value.get_secret_value() if isinstance(_setting_value, SecretStr) else _setting_value
|
||||
)
|
||||
unmasked_setting == v
|
||||
|
||||
|
||||
def test_with_envvar_prefix():
|
||||
with patch.dict(os.environ, {"SAVANT_ELEVEN_LABS_API_KEY": "thisisnotreal"}, clear=True):
|
||||
savant_settings = SavantSettings()
|
||||
assert savant_settings.eleven_labs_api_key.get_secret_value() == "thisisnotreal"
|
Loading…
Reference in New Issue