Skip to content

Commit cc912a6

Browse files
authored
feat: add integration tests for ASR functionality using sample audio files (#120)
1 parent 130ce8a commit cc912a6

2 files changed

Lines changed: 59 additions & 0 deletions

File tree

samples/jfk.wav

344 KB
Binary file not shown.

tests/integration/test_asr_integration.py

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
"""Integration tests for ASR functionality."""
22

3+
from pathlib import Path
4+
35
import pytest
46

57
from fishaudio.types import ASRResponse, TTSConfig
68

9+
SAMPLES_DIR = Path(__file__).resolve().parents[2] / "samples"
10+
711

812
class TestASRIntegration:
913
"""Test ASR with real API."""
@@ -45,6 +49,61 @@ def test_asr_without_timestamps(self, client, sample_audio):
4549
# Segments might still be present but potentially empty or without timing
4650

4751

52+
class TestASRFromFileIntegration:
53+
"""Test ASR using a sample audio file with known content."""
54+
55+
@pytest.fixture
56+
def jfk_audio(self):
57+
"""Load the JFK sample audio file."""
58+
return (SAMPLES_DIR / "jfk.wav").read_bytes()
59+
60+
def test_asr_from_file(self, client, jfk_audio):
61+
"""Test transcription of a known audio file."""
62+
result = client.asr.transcribe(audio=jfk_audio, language="en")
63+
64+
assert isinstance(result, ASRResponse)
65+
assert result.duration > 0
66+
# JFK's famous quote
67+
text = result.text.lower()
68+
assert "ask not what your country can do for you" in text
69+
70+
def test_asr_from_file_with_timestamps(self, client, jfk_audio):
71+
"""Test transcription with timestamps from a known audio file."""
72+
result = client.asr.transcribe(audio=jfk_audio, language="en")
73+
74+
assert len(result.segments) > 0
75+
for segment in result.segments:
76+
assert segment.text
77+
assert segment.start >= 0
78+
assert segment.end > segment.start
79+
80+
def test_asr_from_file_without_timestamps(self, client, jfk_audio):
81+
"""Test transcription without timestamps from a known audio file."""
82+
result = client.asr.transcribe(audio=jfk_audio, include_timestamps=False)
83+
84+
assert isinstance(result, ASRResponse)
85+
assert result.text
86+
87+
88+
class TestAsyncASRFromFileIntegration:
89+
"""Test async ASR using a sample audio file."""
90+
91+
@pytest.fixture
92+
def jfk_audio(self):
93+
"""Load the JFK sample audio file."""
94+
return (SAMPLES_DIR / "jfk.wav").read_bytes()
95+
96+
@pytest.mark.asyncio
97+
async def test_async_asr_from_file(self, async_client, jfk_audio):
98+
"""Test async transcription of a known audio file."""
99+
result = await async_client.asr.transcribe(audio=jfk_audio, language="en")
100+
101+
assert isinstance(result, ASRResponse)
102+
assert result.text
103+
assert result.duration > 0
104+
assert "ask not what your country can do for you" in result.text.lower()
105+
106+
48107
class TestAsyncASRIntegration:
49108
"""Test async ASR with real API."""
50109

0 commit comments

Comments
 (0)