Skip to content

Commit 42de811

Browse files
committed
feat: add ASR test
1 parent a65c22a commit 42de811

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

tests/test_stt.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import pytest
2+
from elevenlabs.client import AsyncElevenLabs, ElevenLabs
3+
4+
from .utils import DEFAULT_VOICE_FILE
5+
6+
DEFAULT_EXT_AUDIO = "https://storage.googleapis.com/eleven-public-cdn/audio/marketing/nicole.mp3"
7+
8+
9+
10+
@pytest.mark.asyncio
11+
async def test_stt_convert():
12+
"""Test basic speech-to-text conversion."""
13+
client = ElevenLabs()
14+
15+
audio_file = open(DEFAULT_VOICE_FILE, "rb")
16+
17+
transcription = client.speech_to_text.convert(
18+
file=audio_file,
19+
model_id="scribe_v1"
20+
)
21+
22+
assert isinstance(transcription.text, str)
23+
assert len(transcription.text) > 0
24+
assert isinstance(transcription.words, list)
25+
assert len(transcription.words) > 0
26+
27+
@pytest.mark.asyncio
28+
async def test_stt_convert_as_stream():
29+
"""Test speech-to-text conversion as stream."""
30+
client = AsyncElevenLabs()
31+
32+
audio_file = open(DEFAULT_VOICE_FILE, "rb")
33+
34+
stream = client.speech_to_text.convert_as_stream(
35+
file=audio_file,
36+
model_id="scribe_v1"
37+
)
38+
39+
transcription_text = ""
40+
async for chunk in stream:
41+
assert isinstance(chunk.text, str)
42+
transcription_text += chunk.text
43+
44+
assert len(transcription_text) > 0

0 commit comments

Comments
 (0)