#!/bin/sh echo "== 1/4 pull python:3.11-slim ==" docker pull python:3.11-slim echo "== 2/4 install faster-whisper, fetch audio + model, transcribe (takes a few minutes) ==" docker run --rm --network host -e HF_HUB_ENABLE_HF_TRANSFER=0 python:3.11-slim bash -c 'pip install -q -i https://pypi.tuna.tsinghua.edu.cn/simple faster-whisper; cat > /tmp/fetch.py << "PYEOF" import urllib.request, sys from urllib.parse import urljoin MASTER = "https://yt.roubao.eu.org/cnnh" def get(u): return urllib.request.urlopen(urllib.request.Request(u, headers={"User-Agent": "Mozilla/5.0"}), timeout=30).read() data = get(MASTER).decode("utf-8", "replace") lines = data.splitlines() variant = None for i, l in enumerate(lines): if l.startswith("#EXT-X-STREAM-INF"): variant = lines[i+1].strip() break print("variant:", variant) if not variant: print("NO VARIANT") print(data[:400]) sys.exit(1) vurl = urljoin(MASTER, variant) vl = get(vurl).decode("utf-8", "replace").splitlines() mapuri = None segs = [] durs = [] for i, l in enumerate(vl): if l.startswith("#EXT-X-MAP:"): mapuri = urljoin(vurl, l.split("URI=\"")[1].split("\"")[0]) elif l.startswith("#EXTINF:"): try: durs.append(float(l[8:].split(",")[0])) except Exception: durs.append(0) elif l and not l.startswith("#"): segs.append(urljoin(vurl, l.strip())) print("window:", len(segs), "map:", bool(mapuri)) take = segs[-5:] tdur = sum(durs[-5:]) if len(durs) == len(segs) else 0 print("audio seconds:", round(tdur, 1)) out = open("/tmp/cnn.media", "wb") if mapuri: out.write(get(mapuri)) n = 0 for u in take: d = get(u) out.write(d) n += len(d) out.close() print("bytes:", n) PYEOF python3 -u /tmp/fetch.py; cat > /tmp/fetch_model.py << "PYEOF" import urllib.request, os, time BASE = "https://py.roubao.eu.org/whisper-models/base/" FILES = ["config.json", "model.bin", "tokenizer.json", "vocabulary.txt"] CHUNK = 10 * 1024 * 1024 os.makedirs("/tmp/whisper-base", exist_ok=True) def fetch(url, path): done = 0 total = None mode = "wb" while total is None or done < total: end = done + CHUNK - 1 for attempt in range(5): try: req = urllib.request.Request(url, headers={"User-Agent": "Mozilla/5.0", "Range": "bytes=" + str(done) + "-" + str(end)}) resp = urllib.request.urlopen(req, timeout=60) cr = resp.headers.get("Content-Range", "") if resp.status == 206 and "/" in cr: total = int(cr.split("/")[1]) data = resp.read() if resp.status == 200: total = len(data) break except Exception as e: print("chunk retry", attempt + 1, "at", done, e) time.sleep(3) else: raise RuntimeError("chunk failed") out = open(path, mode) out.write(data) out.close() done += len(data) mode = "ab" print("progress:", done, "/", total) if len(data) == 0: break return done for f in FILES: print("downloading", f) n = fetch(BASE + f, "/tmp/whisper-base/" + f) print(f, n, "bytes") print("model ready") PYEOF python3 -u /tmp/fetch_model.py; echo "-- transcribing --"; python3 -u -c "import os,time; from faster_whisper import WhisperModel; print(\"cpus\", os.cpu_count()); t=time.time(); m=WhisperModel(\"/tmp/whisper-base\", device=\"cpu\", compute_type=\"int8\"); print(\"load\", round(time.time()-t,1)); t=time.time(); segs,info=m.transcribe(\"/tmp/cnn.media\", beam_size=1); txt=\" \".join(s.text for s in segs); print(\"transcribe\", round(time.time()-t,1)); print(\"lang\", info.language, round(info.language_probability,2)); print(txt)"' echo "== done =="