|
461 | 461 | "source": [
|
462 | 462 | "inputs, duration = get_audio(output_file)\n",
|
463 | 463 | "\n",
|
464 |
| - "transcription = pipe(\n", |
465 |
| - " inputs, generate_kwargs={\"task\": task.value}, return_timestamps=True\n", |
466 |
| - ")[\"chunks\"]" |
| 464 | + "transcription = pipe(inputs, generate_kwargs={\"task\": task.value}, return_timestamps=True)[\"chunks\"]" |
467 | 465 | ]
|
468 | 466 | },
|
469 | 467 | {
|
|
491 | 489 | " seconds = milliseconds // 1_000\n",
|
492 | 490 | " milliseconds -= seconds * 1_000\n",
|
493 | 491 | "\n",
|
494 |
| - " return (\n", |
495 |
| - " f\"{hours}:\" if hours > 0 else \"00:\"\n", |
496 |
| - " ) + f\"{minutes:02d}:{seconds:02d},{milliseconds:03d}\"\n", |
| 492 | + " return (f\"{hours}:\" if hours > 0 else \"00:\") + f\"{minutes:02d}:{seconds:02d},{milliseconds:03d}\"\n", |
497 | 493 | "\n",
|
498 | 494 | "\n",
|
499 | 495 | "def prepare_srt(transcription, filter_duration=None):\n",
|
|
506 | 502 | " if segment[\"timestamp\"][1] is None:\n",
|
507 | 503 | " segment[\"timestamp\"] = (segment[\"timestamp\"][0], filter_duration)\n",
|
508 | 504 | "\n",
|
509 |
| - " if filter_duration is not None and (\n", |
510 |
| - " segment[\"timestamp\"][0] >= math.floor(filter_duration)\n", |
511 |
| - " or segment[\"timestamp\"][1] > math.ceil(filter_duration) + 1\n", |
512 |
| - " ):\n", |
| 505 | + " if filter_duration is not None and (segment[\"timestamp\"][0] >= math.floor(filter_duration) or segment[\"timestamp\"][1] > math.ceil(filter_duration) + 1):\n", |
513 | 506 | " break\n",
|
514 | 507 | " segment_lines.append(str(idx + 1) + \"\\n\")\n",
|
515 | 508 | " time_start = format_timestamp(segment[\"timestamp\"][0])\n",
|
|
1257 | 1250 | " feature_extractor=processor.feature_extractor,\n",
|
1258 | 1251 | " )\n",
|
1259 | 1252 | " inputs, duration = get_audio(output_file)\n",
|
1260 |
| - " transcription = int8_pipe(\n", |
1261 |
| - " inputs, generate_kwargs={\"task\": task.value}, return_timestamps=True\n", |
1262 |
| - " )[\"chunks\"]\n", |
| 1253 | + " transcription = int8_pipe(inputs, generate_kwargs={\"task\": task.value}, return_timestamps=True)[\"chunks\"]\n", |
1263 | 1254 | " srt_lines = prepare_srt(transcription, filter_duration=duration)\n",
|
1264 | 1255 | " print(\"\".join(srt_lines))\n",
|
1265 | 1256 | " widgets.Video.from_file(output_file, loop=False, width=800, height=800)"
|
|
1429 | 1420 | " ydl.download(link.value)\n",
|
1430 | 1421 | " inputs, duration = get_audio(output_file)\n",
|
1431 | 1422 | " m_pipe = int8_pipe if use_int8 else pipe\n",
|
1432 |
| - " transcription = m_pipe(\n", |
1433 |
| - " inputs, generate_kwargs={\"task\": task.lower()}, return_timestamps=True\n", |
1434 |
| - " )[\"chunks\"]\n", |
| 1423 | + " transcription = m_pipe(inputs, generate_kwargs={\"task\": task.lower()}, return_timestamps=True)[\"chunks\"]\n", |
1435 | 1424 | " srt_lines = prepare_srt(transcription, duration)\n",
|
1436 | 1425 | " with output_file.with_suffix(\".srt\").open(\"w\") as f:\n",
|
1437 | 1426 | " f.writelines(srt_lines)\n",
|
|
0 commit comments