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

⚡️ Resume transcription tasks #325

Merged
merged 1 commit into from
Aug 6, 2023
Merged
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
25 changes: 20 additions & 5 deletions worker/transcribee_worker/whisper_transcribe.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def get_context(model_name: str) -> api.Context:
def _transcription_work(
queue: SubmissionQueue,
data: NDArray[Any],
start_offset: float,
model_name: str,
lang_code: Optional[str],
progress_callback: Optional[ProgressCallbackType],
Expand Down Expand Up @@ -112,9 +113,9 @@ def handle_new_segment(
text=text,
conf=conf,
# 10·ms -> seconds
start=start / 100,
start=(start / 100) + start_offset,
# 10·ms -> seconads
end=end / 100,
end=(end / 100) + start_offset,
conf_ts=conf_ts,
)
)
Expand Down Expand Up @@ -161,10 +162,19 @@ def handle_new_segment(


def transcribe(
data: NDArray, model_name: str, lang_code="en", progress_callback=None
data: NDArray,
start_offset: float,
model_name: str,
lang_code="en",
progress_callback=None,
) -> AsyncIterator[Paragraph]:
return async_task(
_transcription_work, data, model_name, lang_code, progress_callback
_transcription_work,
data,
start_offset,
model_name,
lang_code,
progress_callback,
)


Expand Down Expand Up @@ -233,7 +243,11 @@ async def remove_leading_whitespace_from_paragraph(


async def transcribe_clean(
data: NDArray, model_name: str, lang_code: str = "en", progress_callback=None
data: NDArray,
start_offset: float,
model_name: str,
lang_code: str = "en",
progress_callback=None,
):
chain = (
recombine_split_words,
Expand All @@ -243,6 +257,7 @@ async def transcribe_clean(
iter = aiter(
transcribe(
data=data,
start_offset=start_offset,
model_name=model_name,
lang_code=lang_code,
progress_callback=progress_callback,
Expand Down
27 changes: 22 additions & 5 deletions worker/transcribee_worker/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,16 @@ def ensure_atom_invariants(doc: EditorDocument):
prev_atom = atom


def get_last_atom_end(doc: EditorDocument):
for paragraph_idx in reversed(range(len(doc.children))):
for atom_idx in reversed(range(len(doc.children[paragraph_idx].children))):
atom = doc.children[paragraph_idx].children[atom_idx]
if atom.end is not None:
return atom.end

return 0


class Worker:
base_url: str
token: str
Expand Down Expand Up @@ -166,14 +176,21 @@ async def transcribe(
audio = self.load_document_audio(task.document)

async with self.api_client.document(task.document.id) as doc:

async with doc.transaction("Reset Document") as d:
anuejn marked this conversation as resolved.
Show resolved Hide resolved
d.children = []
if d.children is None:
d.children = []

start_offset = get_last_atom_end(d)

audio = audio[int(start_offset * settings.SAMPLE_RATE) :]

async for paragraph in transcribe_clean(
audio,
task.task_parameters.model,
task.task_parameters.lang,
progress_callback,
data=audio,
start_offset=start_offset,
model_name=task.task_parameters.model,
lang_code=task.task_parameters.lang,
progress_callback=progress_callback,
):
async with doc.transaction("Automatic Transcription") as d:
p = paragraph.dict()
Expand Down