Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

alias timestamp_granularities[] does not actually work #80

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/faster_whisper_server/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,8 +321,8 @@ def transcribe_file(
response_format: Annotated[ResponseFormat, Form()] = config.default_response_format,
temperature: Annotated[float, Form()] = 0.0,
timestamp_granularities: Annotated[
list[Literal["segment", "word"]],
Form(alias="timestamp_granularities[]"),
list[str],
Form(),
] = ["segment"],
stream: Annotated[bool, Form()] = False,
hotwords: Annotated[str | None, Form()] = None,
Expand Down
28 changes: 28 additions & 0 deletions tests/sse_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,31 @@ def test_transcription_srt(client: TestClient) -> None:
text = text.replace("1", "YO")
with pytest.raises(srt.SRTParseError):
list(srt.parse(text))

@pytest.mark.parametrize("timestamp_granularities", [["word"], ["word", "segment"]])
def test_transcription_verbose_json(client: TestClient, timestamp_granularities) -> None:
with open("audio.wav", "rb") as f:
data = f.read()
kwargs = {
"files": {"file": ("audio.wav", data, "audio/wav")},
"data": {"response_format": "verbose_json", "stream": False, "timestamp_granularities": timestamp_granularities},
}
response = client.post("/v1/audio/transcriptions", **kwargs)
assert response.status_code == 200
assert "application/json" in response.headers["content-type"]
output = response.json()
assert output is not None

@pytest.mark.parametrize("timestamp_granularities", [["word"], ["word", "segment"]])
def test_transcription_verbose_json_with_alias_timestamp_granularities(client: TestClient, timestamp_granularities) -> None:
with open("audio.wav", "rb") as f:
data = f.read()
kwargs = {
"files": {"file": ("audio.wav", data, "audio/wav")},
"data": {"response_format": "verbose_json", "stream": False, "timestamp_granularities[]": timestamp_granularities},
}
response = client.post("/v1/audio/transcriptions", **kwargs)
assert response.status_code == 200
assert "application/json" in response.headers["content-type"]
output = response.json()
assert output is not None