Spaces:
Running
Running
align Whisper tests with decoding controls
Browse files
tests/test_whisper_service.py
CHANGED
|
@@ -7,7 +7,9 @@ from app.services.whisper_service import WhisperService
|
|
| 7 |
|
| 8 |
|
| 9 |
class FakeWord:
|
| 10 |
-
def __init__(
|
|
|
|
|
|
|
| 11 |
self.word = word
|
| 12 |
self.start = start
|
| 13 |
self.end = end
|
|
@@ -43,7 +45,15 @@ class FakeModel:
|
|
| 43 |
def test_transcribe_sync_includes_word_timestamps() -> None:
|
| 44 |
model = FakeModel()
|
| 45 |
segments, info = WhisperService._transcribe_sync(
|
| 46 |
-
model,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
)
|
| 48 |
|
| 49 |
assert info["language"] == "en"
|
|
@@ -61,11 +71,21 @@ def test_transcribe_sync_includes_word_timestamps() -> None:
|
|
| 61 |
def test_transcribe_sync_can_disable_word_timestamps() -> None:
|
| 62 |
model = FakeModel()
|
| 63 |
segments, _ = WhisperService._transcribe_sync(
|
| 64 |
-
model,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
)
|
| 66 |
|
| 67 |
assert "words" not in segments[0]
|
| 68 |
assert model.calls[0]["word_timestamps"] is False
|
|
|
|
|
|
|
| 69 |
|
| 70 |
|
| 71 |
async def test_json_output_preserves_words(tmp_path, settings) -> None:
|
|
@@ -87,6 +107,7 @@ async def test_json_output_preserves_words(tmp_path, settings) -> None:
|
|
| 87 |
assert payload["segments"][0]["words"][0]["word"] == " hello"
|
| 88 |
assert payload["schema_version"] == "1.0"
|
| 89 |
assert payload["language"] == "en"
|
|
|
|
| 90 |
|
| 91 |
|
| 92 |
async def test_transcript_metadata_uses_canonical_schema(tmp_path, settings) -> None:
|
|
@@ -108,3 +129,6 @@ async def test_transcript_metadata_uses_canonical_schema(tmp_path, settings) ->
|
|
| 108 |
assert transcript["task"] == "translate"
|
| 109 |
assert transcript["model"] == "tiny"
|
| 110 |
assert transcript["segments"][0]["words"][1]["end"] == 1.988
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
|
| 9 |
class FakeWord:
|
| 10 |
+
def __init__(
|
| 11 |
+
self, word: str, start: float, end: float, probability: float = 0.9876543
|
| 12 |
+
) -> None:
|
| 13 |
self.word = word
|
| 14 |
self.start = start
|
| 15 |
self.end = end
|
|
|
|
| 45 |
def test_transcribe_sync_includes_word_timestamps() -> None:
|
| 46 |
model = FakeModel()
|
| 47 |
segments, info = WhisperService._transcribe_sync(
|
| 48 |
+
model,
|
| 49 |
+
Path("sample.wav"),
|
| 50 |
+
"transcribe",
|
| 51 |
+
"en",
|
| 52 |
+
5,
|
| 53 |
+
True,
|
| 54 |
+
True,
|
| 55 |
+
True,
|
| 56 |
+
0.0,
|
| 57 |
)
|
| 58 |
|
| 59 |
assert info["language"] == "en"
|
|
|
|
| 71 |
def test_transcribe_sync_can_disable_word_timestamps() -> None:
|
| 72 |
model = FakeModel()
|
| 73 |
segments, _ = WhisperService._transcribe_sync(
|
| 74 |
+
model,
|
| 75 |
+
Path("sample.wav"),
|
| 76 |
+
"transcribe",
|
| 77 |
+
"en",
|
| 78 |
+
5,
|
| 79 |
+
True,
|
| 80 |
+
False,
|
| 81 |
+
False,
|
| 82 |
+
0.2,
|
| 83 |
)
|
| 84 |
|
| 85 |
assert "words" not in segments[0]
|
| 86 |
assert model.calls[0]["word_timestamps"] is False
|
| 87 |
+
assert model.calls[0]["condition_on_previous_text"] is False
|
| 88 |
+
assert model.calls[0]["temperature"] == 0.2
|
| 89 |
|
| 90 |
|
| 91 |
async def test_json_output_preserves_words(tmp_path, settings) -> None:
|
|
|
|
| 107 |
assert payload["segments"][0]["words"][0]["word"] == " hello"
|
| 108 |
assert payload["schema_version"] == "1.0"
|
| 109 |
assert payload["language"] == "en"
|
| 110 |
+
assert payload["model"] == "tiny"
|
| 111 |
|
| 112 |
|
| 113 |
async def test_transcript_metadata_uses_canonical_schema(tmp_path, settings) -> None:
|
|
|
|
| 129 |
assert transcript["task"] == "translate"
|
| 130 |
assert transcript["model"] == "tiny"
|
| 131 |
assert transcript["segments"][0]["words"][1]["end"] == 1.988
|
| 132 |
+
assert transcript["word_timestamps"] is True
|
| 133 |
+
assert result.metadata["condition_on_previous_text"] is True
|
| 134 |
+
assert result.metadata["temperature"] == 0.0
|