#!/bin/sh if [ ! -f /mnt/sata1-4/whisper-small/model.bin ]; then echo "MISSING: /mnt/sata1-4/whisper-small/model.bin - upload and extract the tar first"; exit 1; fi ls -l /mnt/sata1-4/whisper-small echo "== 1/2 pull python:3.11-slim ==" docker pull python:3.11-slim echo "== 2/2 fetch audio, transcribe with local model (takes a few minutes) ==" docker run --rm --network host -v /mnt/sata1-4/whisper-small:/tmp/whisper-base:ro -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" import time def get(u): last = None for attempt in range(3): try: return urllib.request.urlopen(urllib.request.Request(u, headers={"User-Agent": "Mozilla/5.0"}), timeout=30).read() except Exception as e: last = e print("fetch retry", attempt + 1, e) time.sleep(3) raise last 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 && 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 =="