feat: enable diarization by default with an opt-out
Request speaker diarization through OpenRouter's Azure provider options for all transcription uploads. Add --no-diarization to explicitly disable it for both plain text and SRT output; returned speaker labels let existing SRT cue generation split at speaker changes. Default to 10-minute chunks when diarization is enabled because Microsoft reports failures around 15 minutes and longer. Preserve the 30-minute default with the opt-out and honor explicit --chunk-minutes values in both modes. Document the options, duration limits, and output behavior. Test Plan: - python3 -B -m unittest -v: all 32 tests passed, including request options, default upload limits, opt-out combinations, and SRT speaker boundaries. - bash -n transcribe: passed. - ./transcribe --help: verified the new option and chunk defaults. - git diff --cached --check: passed. - Provider responses were mocked; no live API request was made.
This commit is contained in:
1 parent
a5c535cfb9
commit
24b1030776
4 files changed
+121
-10
No files matched your search
+15
-2
@@ -32,10 +32,15 @@ info = json.loads(subprocess.check_output([
|
||||
"format=duration:stream=codec_name,sample_rate,channels", "-of", "json", str(audio),
|
||||
], text=True))
|
||||
assert info["streams"][0] == {"codec_name": "mp3", "sample_rate": "16000", "channels": 1}
|
||||
assert float(info["format"]["duration"]) <= 60
|
||||
assert abs(float(info["format"]["duration"]) - (chunk["end"] - chunk["start"])) < 0.1
|
||||
with open(os.environ["TRANSCRIBE_TEST_LOG"], "a") as log:
|
||||
log.write(json.dumps({"index": index, "chunk": chunk, "staging": str(output.parent)}) + "\n")
|
||||
log.write(json.dumps({
|
||||
"index": index, "chunk": chunk, "staging": str(output.parent),
|
||||
"upload_duration": float(info["format"]["duration"]),
|
||||
"provider": request.get("provider"),
|
||||
"response_format": request.get("response_format"),
|
||||
"timestamp_granularities": request.get("timestamp_granularities"),
|
||||
}) + "\n")
|
||||
|
||||
mode = os.environ.get("TRANSCRIBE_TEST_MODE", "ok")
|
||||
if index == 1:
|
||||
@@ -62,5 +67,13 @@ else:
|
||||
("continues.", 57.4, 57.8), ("Last.", 65, 65.4),
|
||||
] if start >= chunk["start"] and end <= chunk["end"]
|
||||
]
|
||||
if mode == "speakers":
|
||||
words = [
|
||||
{"word": "Hello", "start": 1, "end": 1.4},
|
||||
{"word": "there", "start": 1.5, "end": 1.9},
|
||||
]
|
||||
if request["provider"]["options"]["azure"]["diarization"]["enabled"]:
|
||||
for speaker, word in enumerate(words):
|
||||
word["speaker"] = speaker
|
||||
response = {"text": " ".join(w["word"] for w in words), "words": words}
|
||||
output.write_text(json.dumps(response))
|
||||
Reference in new issue
Block a user