mirror of
https://github.com/yusufipk/dikte.git
synced 2026-09-11 19:06:11 +00:00
Send the audio as mp3, and stop cutting a file that fits in one request
Whisper hears in thirty second windows and decides for itself where one cue ends and the next begins. A chunk that starts in the middle of a sentence can answer with one cue per window, twenty seconds of text at a time, for the whole rest of the chunk: a twenty five minute recording was fine until 20:00, which was where the second cut fell, and ran on in paragraphs from there. Sending the same audio in one request instead of three gives cues of two and a half seconds throughout. The cuts were only ever there for the upload limit, and we were the ones walking into it: ffmpeg opened a 24 MB m4a into 48 MB of uncompressed WAV, over the 25 MB the APIs take, so the file had to be cut every ten minutes. As mp3 it is 9 MB, and an hour of speech goes in one request. A server on this machine is still handed the WAV, where nothing is uploaded and the encoder would only cost quality. How long a chunk may be is now measured from the encoded file rather than assumed from a bitrate. Where a file still has to be cut, the chunks overlap by a whisper window and stitch() drops the telling that was cut short, keeping the one that heard the sentence whole. Meetings, which upload the WAV itself and so still cut every ten minutes, get the same stitching.
This commit is contained in:
@@ -309,7 +309,7 @@ def local_failure(service, server, exc):
|
||||
exc.status)
|
||||
|
||||
|
||||
def _transcribe_request(target, wav_path, language, prompt, response_format,
|
||||
def _transcribe_request(target, audio_path, language, prompt, response_format,
|
||||
granularity=None, timeout=300, aborter=None):
|
||||
if target.provider == "local":
|
||||
# The timeouts here are sized for a hosted API, where a slow answer is a
|
||||
@@ -329,7 +329,7 @@ def _transcribe_request(target, wav_path, language, prompt, response_format,
|
||||
fields.append(("prompt", prompt))
|
||||
if granularity:
|
||||
fields.append(("timestamp_granularities[]", granularity))
|
||||
body, ctype = _multipart(fields, "file", wav_path)
|
||||
body, ctype = _multipart(fields, "file", audio_path)
|
||||
try:
|
||||
return _request(
|
||||
f"{target.base_url.rstrip('/')}/audio/transcriptions", body,
|
||||
@@ -381,9 +381,9 @@ def _merge_word_splits(segments):
|
||||
return merged
|
||||
|
||||
|
||||
def transcribe(target, wav_path, language="", prompt="", timeout=300, aborter=None):
|
||||
def transcribe(target, audio_path, language="", prompt="", timeout=300, aborter=None):
|
||||
data = _transcribe_request(
|
||||
target, wav_path, language, prompt, "json", timeout=timeout, aborter=aborter
|
||||
target, audio_path, language, prompt, "json", timeout=timeout, aborter=aborter
|
||||
)
|
||||
text = data.get("text") or ""
|
||||
if target.provider == "local":
|
||||
@@ -394,12 +394,12 @@ def transcribe(target, wav_path, language="", prompt="", timeout=300, aborter=No
|
||||
return text
|
||||
|
||||
|
||||
def transcribe_segments(target, wav_path, language="", prompt="", timeout=300,
|
||||
def transcribe_segments(target, audio_path, language="", prompt="", timeout=300,
|
||||
aborter=None):
|
||||
"""[(start_seconds, end_seconds, text)] using whisper-1's verbose response."""
|
||||
data = _transcribe_request(
|
||||
target._replace(model=timestamp_model(target.provider, target.model)),
|
||||
wav_path, language, prompt, "verbose_json",
|
||||
audio_path, language, prompt, "verbose_json",
|
||||
granularity="segment", timeout=timeout, aborter=aborter,
|
||||
)
|
||||
segments = data.get("segments") or []
|
||||
|
||||
Reference in New Issue
Block a user