diff --git a/samples/jfk.wav b/samples/jfk.wav new file mode 100644 index 0000000..3184d37 Binary files /dev/null and b/samples/jfk.wav differ diff --git a/tests/integration/test_asr_integration.py b/tests/integration/test_asr_integration.py index 7e2602e..7e89554 100644 --- a/tests/integration/test_asr_integration.py +++ b/tests/integration/test_asr_integration.py @@ -1,9 +1,13 @@ """Integration tests for ASR functionality.""" +from pathlib import Path + import pytest from fishaudio.types import ASRResponse, TTSConfig +SAMPLES_DIR = Path(__file__).resolve().parents[2] / "samples" + class TestASRIntegration: """Test ASR with real API.""" @@ -45,6 +49,61 @@ def test_asr_without_timestamps(self, client, sample_audio): # Segments might still be present but potentially empty or without timing +class TestASRFromFileIntegration: + """Test ASR using a sample audio file with known content.""" + + @pytest.fixture + def jfk_audio(self): + """Load the JFK sample audio file.""" + return (SAMPLES_DIR / "jfk.wav").read_bytes() + + def test_asr_from_file(self, client, jfk_audio): + """Test transcription of a known audio file.""" + result = client.asr.transcribe(audio=jfk_audio, language="en") + + assert isinstance(result, ASRResponse) + assert result.duration > 0 + # JFK's famous quote + text = result.text.lower() + assert "ask not what your country can do for you" in text + + def test_asr_from_file_with_timestamps(self, client, jfk_audio): + """Test transcription with timestamps from a known audio file.""" + result = client.asr.transcribe(audio=jfk_audio, language="en") + + assert len(result.segments) > 0 + for segment in result.segments: + assert segment.text + assert segment.start >= 0 + assert segment.end > segment.start + + def test_asr_from_file_without_timestamps(self, client, jfk_audio): + """Test transcription without timestamps from a known audio file.""" + result = client.asr.transcribe(audio=jfk_audio, include_timestamps=False) + + assert isinstance(result, ASRResponse) + assert result.text + + +class TestAsyncASRFromFileIntegration: + """Test async ASR using a sample audio file.""" + + @pytest.fixture + def jfk_audio(self): + """Load the JFK sample audio file.""" + return (SAMPLES_DIR / "jfk.wav").read_bytes() + + @pytest.mark.asyncio + async def test_async_asr_from_file(self, async_client, jfk_audio): + """Test async transcription of a known audio file.""" + result = await async_client.asr.transcribe(audio=jfk_audio, language="en") + + assert isinstance(result, ASRResponse) + assert result.text + assert result.duration > 0 + assert "ask not what your country can do for you" in result.text.lower() + + class TestAsyncASRIntegration: """Test async ASR with real API."""