|
1 | 1 | """Integration tests for ASR functionality.""" |
2 | 2 |
|
| 3 | +from pathlib import Path |
| 4 | + |
3 | 5 | import pytest |
4 | 6 |
|
5 | 7 | from fishaudio.types import ASRResponse, TTSConfig |
6 | 8 |
|
| 9 | +SAMPLES_DIR = Path(__file__).resolve().parents[2] / "samples" |
| 10 | + |
7 | 11 |
|
8 | 12 | class TestASRIntegration: |
9 | 13 | """Test ASR with real API.""" |
@@ -45,6 +49,61 @@ def test_asr_without_timestamps(self, client, sample_audio): |
45 | 49 | # Segments might still be present but potentially empty or without timing |
46 | 50 |
|
47 | 51 |
|
| 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 | + |
48 | 107 | class TestAsyncASRIntegration: |
49 | 108 | """Test async ASR with real API.""" |
50 | 109 |
|
|
0 commit comments