Skip to content

Commit

Permalink
chore: add generate test, bump to 1.50.0 & change default model
Browse files Browse the repository at this point in the history
  • Loading branch information
louisjoecodes committed Dec 14, 2024
1 parent f88124c commit 6d4f625
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/elevenlabs/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def generate(
text: Union[str, Iterator[str]],
voice: Union[VoiceId, VoiceName, Voice] = DEFAULT_VOICE,
voice_settings: typing.Optional[VoiceSettings] = DEFAULT_VOICE.settings,
model: Union[ModelId, Model] = "eleven_monolingual_v1",
model: Union[ModelId, Model] = "eleven_multilingual_v2",
optimize_streaming_latency: typing.Optional[int] = 0,
stream: bool = False,
output_format: Optional[OutputFormat] = "mp3_44100_128",
Expand Down Expand Up @@ -302,7 +302,7 @@ async def generate(
text: str,
voice: Union[VoiceId, VoiceName, Voice] = DEFAULT_VOICE,
voice_settings: typing.Optional[VoiceSettings] = DEFAULT_VOICE.settings,
model: Union[ModelId, Model] = "eleven_monolingual_v1",
model: Union[ModelId, Model] = "eleven_multilingual_v2",
optimize_streaming_latency: typing.Optional[int] = 0,
stream: bool = False,
output_format: Optional[OutputFormat] = "mp3_44100_128",
Expand Down
29 changes: 28 additions & 1 deletion tests/test_tts.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import asyncio

from elevenlabs import VoiceSettings, play
from elevenlabs import VoiceSettings, play, Voice
from elevenlabs.client import AsyncElevenLabs, ElevenLabs

from .utils import IN_GITHUB, DEFAULT_TEXT, DEFAULT_VOICE, DEFAULT_MODEL
Expand All @@ -17,6 +17,33 @@ def test_tts_convert() -> None:
play(audio)


def test_tts_generate() -> None:
"""Test basic text-to-speech generation w/ custom generate."""
client = ElevenLabs()
audio_generator = client.generate(text=DEFAULT_TEXT, voice="Brian", model=DEFAULT_MODEL)
audio = b"".join(audio_generator)
assert isinstance(audio, bytes), "TTS should return bytes"
if not IN_GITHUB:
play(audio)


def test_tts_generate_with_voice_settings() -> None:
"""Test basic text-to-speech generation."""
client = ElevenLabs()
audio_generator = client.generate(
text=DEFAULT_TEXT,
model=DEFAULT_MODEL,
voice=Voice(
voice_id="nPczCjzI2devNBz1zQrb",
settings=VoiceSettings(stability=0.71, similarity_boost=0.5, style=0.0, use_speaker_boost=True),
),
)
audio = b"".join(audio_generator)
assert isinstance(audio, bytes), "TTS should return bytes"
if not IN_GITHUB:
play(audio)


def test_tts_convert_with_voice_settings() -> None:
"""Test TTS with custom voice settings."""
client = ElevenLabs()
Expand Down

0 comments on commit 6d4f625

Please sign in to comment.