Skip to content

Commit

Permalink
feat: add ASR test
Browse files Browse the repository at this point in the history
  • Loading branch information
louisjoecodes committed Feb 11, 2025
1 parent a65c22a commit 42de811
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions tests/test_stt.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import pytest
from elevenlabs.client import AsyncElevenLabs, ElevenLabs

from .utils import DEFAULT_VOICE_FILE

DEFAULT_EXT_AUDIO = "https://storage.googleapis.com/eleven-public-cdn/audio/marketing/nicole.mp3"



@pytest.mark.asyncio
async def test_stt_convert():
"""Test basic speech-to-text conversion."""
client = ElevenLabs()

audio_file = open(DEFAULT_VOICE_FILE, "rb")

transcription = client.speech_to_text.convert(
file=audio_file,
model_id="scribe_v1"
)

assert isinstance(transcription.text, str)
assert len(transcription.text) > 0
assert isinstance(transcription.words, list)
assert len(transcription.words) > 0

@pytest.mark.asyncio
async def test_stt_convert_as_stream():
"""Test speech-to-text conversion as stream."""
client = AsyncElevenLabs()

audio_file = open(DEFAULT_VOICE_FILE, "rb")

stream = client.speech_to_text.convert_as_stream(
file=audio_file,
model_id="scribe_v1"
)

transcription_text = ""
async for chunk in stream:
assert isinstance(chunk.text, str)
transcription_text += chunk.text

assert len(transcription_text) > 0

0 comments on commit 42de811

Please sign in to comment.