Skip to content

Commit 418c3cc

Browse files
committed
feat: add e2e tests
1 parent 0a282eb commit 418c3cc

File tree

8 files changed

+100
-1
lines changed

8 files changed

+100
-1
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ dist/
33
__pycache__/
44
poetry.toml
55
.ruff_cache/
6+
.DS_Store

tests/fixtures/voice_sample.mp3

24.5 KB
Binary file not shown.

tests/test_audio_isolation.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
from elevenlabs import play
2+
from elevenlabs.client import ElevenLabs
3+
4+
from .utils import IN_GITHUB, DEFAULT_VOICE_FILE
5+
6+
7+
def test_audio_isolation() -> None:
8+
"""Test basic audio isolation."""
9+
client = ElevenLabs()
10+
audio_file = open(DEFAULT_VOICE_FILE, "rb")
11+
try:
12+
audio_stream = client.audio_isolation.audio_isolation(audio=audio_file)
13+
audio = b"".join(chunk for chunk in audio_stream)
14+
assert isinstance(audio, bytes), "Combined audio should be bytes"
15+
if not IN_GITHUB:
16+
play(audio)
17+
finally:
18+
audio_file.close()
19+
20+
21+
def test_audio_isolation_as_stream():
22+
"""Test audio isolation with streaming."""
23+
client = ElevenLabs()
24+
audio_file = open(DEFAULT_VOICE_FILE, "rb")
25+
try:
26+
audio_stream = client.audio_isolation.audio_isolation_stream(audio=audio_file)
27+
audio = b"".join(chunk for chunk in audio_stream)
28+
assert isinstance(audio, bytes), "Combined audio should be bytes"
29+
if not IN_GITHUB:
30+
play(audio)
31+
finally:
32+
audio_file.close()

tests/test_models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from elevenlabs.client import ElevenLabs
33

44

5-
def test_models():
5+
def test_models_get_all():
66
client = ElevenLabs()
77
models = client.models.get_all()
88
assert len(models) > 0

tests/test_sts.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
from elevenlabs import play
2+
from elevenlabs.client import ElevenLabs
3+
4+
from .utils import IN_GITHUB, DEFAULT_VOICE, DEFAULT_VOICE_FILE
5+
6+
7+
def test_sts() -> None:
8+
"""Test basic speech-to-speech generation."""
9+
client = ElevenLabs()
10+
audio_file = open(DEFAULT_VOICE_FILE, "rb")
11+
try:
12+
audio_stream = client.speech_to_speech.convert(voice_id=DEFAULT_VOICE, audio=audio_file)
13+
audio = b"".join(chunk for chunk in audio_stream)
14+
assert isinstance(audio, bytes), "Combined audio should be bytes"
15+
if not IN_GITHUB:
16+
play(audio)
17+
finally:
18+
audio_file.close()
19+
20+
21+
def test_sts_as_stream():
22+
client = ElevenLabs()
23+
audio_file = open(DEFAULT_VOICE_FILE, "rb")
24+
try:
25+
audio_stream = client.speech_to_speech.convert_as_stream(voice_id=DEFAULT_VOICE, audio=audio_file)
26+
audio = b"".join(chunk for chunk in audio_stream)
27+
assert isinstance(audio, bytes), "Combined audio should be bytes"
28+
if not IN_GITHUB:
29+
play(audio)
30+
finally:
31+
audio_file.close()

tests/test_ttsfx.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from elevenlabs import play
2+
from elevenlabs.client import ElevenLabs
3+
4+
from .utils import IN_GITHUB
5+
6+
7+
def test_text_to_sound_effects_convert() -> None:
8+
"""Test basic sound-effect generation."""
9+
client = ElevenLabs()
10+
audio_generator = client.text_to_sound_effects.convert(
11+
text="Hypnotic throbbing sound effect. Increases in imtensity.",
12+
duration_seconds=2,
13+
)
14+
audio = b"".join(audio_generator)
15+
assert isinstance(audio, bytes), "TTS should return bytes"
16+
if not IN_GITHUB:
17+
play(audio)

tests/test_ttv.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from elevenlabs.client import ElevenLabs
2+
3+
4+
def test_voice_preview_generation():
5+
"""Test generating voice previews from description."""
6+
client = ElevenLabs()
7+
8+
# Test parameters
9+
description = "A warm and friendly female voice with a slight British accent, speaking clearly and professionally"
10+
sample_text = "This is a test message that needs to be at least one hundred characters long to meet the API requirements. Here it is."
11+
12+
previews = client.text_to_voice.create_previews(voice_description=description, text=sample_text)
13+
14+
assert hasattr(previews, "previews"), "Response should have 'previews' attribute"
15+
assert len(previews.previews) > 0, "Should receive at least one preview"
16+
assert hasattr(previews.previews[0], "generated_voice_id"), "Preview should contain generated_voice_id"
17+
assert hasattr(previews.previews[0], "audio_base_64"), "Preview should contain audio_base_64"

tests/utils.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
DEFAULT_VOICE = "21m00Tcm4TlvDq8ikWAM"
1010
DEFAULT_TEXT = "Hello"
1111
DEFAULT_MODEL = "eleven_multilingual_v2"
12+
DEFAULT_VOICE_FILE = "tests/fixtures/voice_sample.mp3"
1213

1314

1415
def as_local_files(urls: Sequence[str]) -> Generator[str, None, None]:

0 commit comments

Comments
 (0)