Skip to content

Commit

Permalink
Refactor, ran poetry lock
Browse files Browse the repository at this point in the history
  • Loading branch information
osolmaz committed Feb 25, 2024
1 parent 6b337f5 commit 65c1201
Show file tree
Hide file tree
Showing 3 changed files with 308 additions and 314 deletions.
24 changes: 11 additions & 13 deletions examples/elevenlabs-example.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,28 @@
from manim import *

from manim_voiceover import VoiceoverScene
from manim_voiceover.services.eleven_labs import ElevenlabsService
from manim_voiceover.services.elevenlabs import ElevenLabsService


class ElevenlabsExample(VoiceoverScene):
def construct(self):
# set speech service using defaults, without voice_name or voice_id
# if none of voice_name or voice_id is passed, it defaults to the
# Set speech service using defaults, without voice_name or voice_id
# If none of voice_name or voice_id is passed, it defaults to the
# first voice in the list returned by `voices()`
#
# self.set_speech_service(ElevenlabsService())

# set speech service using voice_name
#
# Set speech service using voice_name
#
# self.set_speech_service(ElevenlabsService(voice_name="Adam"))

# set speech service using voice_id
#
# Set speech service using voice_id
#
# self.set_speech_service(ElevenlabsService(voice_id="29vD33N1CtxCmqQRPOHJ"))

# customise voice by passing voice_settings
self.set_speech_service(
ElevenlabsService(
ElevenLabsService(
voice_name="Adam",
voice_settings={"stability": 0.001, "similarity_boost": 0.25},
)
Expand All @@ -36,11 +39,6 @@ def construct(self):
with self.voiceover(text="Now, let's transform it into a square.") as tracker:
self.play(Transform(circle, square), run_time=tracker.duration)

with self.voiceover(
text="This is a very very very very very very very very very very very very very very very very very long sentence."
):
pass

with self.voiceover(text="Thank you for watching."):
self.play(Uncreate(circle))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
import elevenlabs
except ImportError:
logger.error(
'Missing packages. Run `pip install "manim-voiceover[elevenlabs]"` to use Elevenlabs API.'
'Missing packages. Run `pip install "manim-voiceover[elevenlabs]"` '
"to use Elevenlabs API."
)

from elevenlabs import Voice, VoiceSettings, generate, save, voices
Expand All @@ -25,14 +26,16 @@

def create_dotenv_elevenlabs():
logger.info(
"Check out https://voiceover.manim.community/en/stable/services.html#elevenlabs to learn how to create an account and get your subscription key."
"Check out https://voiceover.manim.community/en/stable/services.html#elevenlabs"
" to learn how to create an account and get your subscription key."
)
try:
os.environ["ELEVEN_API_KEY"]
except KeyError:
if not create_dotenv_file(["ELEVEN_API_KEY"]):
raise Exception(
"The environment variables ELEVEN_API_KEY are not set. Please set them or create a .env file with the variables."
"The environment variables ELEVEN_API_KEY are not set. "
"Please set them or create a .env file with the variables."
)
logger.info("The .env file has been created. Please run Manim again.")
sys.exit()
Expand All @@ -41,7 +44,7 @@ def create_dotenv_elevenlabs():
create_dotenv_elevenlabs()


class ElevenlabsService(SpeechService):
class ElevenLabsService(SpeechService):
"""Speech service for Elevenlabs API."""

def __init__(
Expand All @@ -54,10 +57,29 @@ def __init__(
):
"""
Args:
voice_name (str, optional): The name of the voice to use. See the `API page <https://elevenlabs.io/docs/api-reference/text-to-speech>` for reference. Defaults to `None`. If none of `voice_name` or `voice_id` is be provided, it uses default available voice.
voice_id (str, Optional): The id of the voice to use. See the `API page <https://elevenlabs.io/docs/api-reference/text-to-speech>` for reference. Defaults to `None`. If none of `voice_name` or `voice_id` must be provided, it uses default available voice.
model (str, optional): The name of the model to use. See the `API page: <https://elevenlabs.io/docs/api-reference/text-to-speech>` for reference. Defaults to `eleven_monolingual_v1`
voice_settings (Union[VoiceSettings, dict], optional): The voice settings to use. See the `Docs: <https://elevenlabs.io/docs/speech-synthesis/voice-settings>` for reference. It is a dictionary, with keys: `stability` (Required, number), `similarity_boost` (Required, number), `style` (Optional, number, default 0), `use_speaker_boost` (Optional, boolean, True).
voice_name (str, optional): The name of the voice to use.
See the
`API page <https://elevenlabs.io/docs/api-reference/text-to-speech>`
for reference. Defaults to `None`.
If none of `voice_name` or `voice_id` is be provided,
it uses default available voice.
voice_id (str, Optional): The id of the voice to use.
See the
`API page <https://elevenlabs.io/docs/api-reference/text-to-speech>`
for reference. Defaults to `None`. If none of `voice_name`
or `voice_id` must be provided, it uses default available voice.
model (str, optional): The name of the model to use. See the `API
page: <https://elevenlabs.io/docs/api-reference/text-to-speech>`
for reference. Defaults to `eleven_monolingual_v1`
voice_settings (Union[VoiceSettings, dict], optional): The voice
settings to use.
See the
`Docs: <https://elevenlabs.io/docs/speech-synthesis/voice-settings>`
for reference.
It is a dictionary, with keys: `stability` (Required, number),
`similarity_boost` (Required, number),
`style` (Optional, number, default 0), `use_speaker_boost`
(Optional, boolean, True).
"""
if not voice_name and not voice_id:
logger.warn(
Expand Down Expand Up @@ -86,7 +108,8 @@ def __init__(
"similarity_boost"
):
raise KeyError(
"Missing required keys: 'stability' and 'similarity_boost'. Required for setting voice setting"
"Missing required keys: 'stability' and 'similarity_boost'. "
"Required for setting voice setting"
)
self.voice_settings = VoiceSettings(
stability=voice_settings["stability"],
Expand Down
Loading

0 comments on commit 65c1201

Please sign in to comment.