Reza2kn's picture
Shenava Rizeh v1.6
c977a3e verified
Raw History Blame Contribute Delete
1.12 kB
"""Extract commentary_unlabeled chunks to FLAC (for Hydrogen labels)."""
import os,io,json,pandas as pd,soundfile as sf,pyarrow.parquet as pq
from huggingface_hub import hf_hub_download
O="/home/rezo/value_study/claude_r16";G="/home/rezo/value_study/claude_gj"
A=pd.read_parquet(G+"/audit.parquet");C=A[A.tag=="commentary_unlabeled"]
for sh in sorted(C.shard.unique()):
if os.path.exists(f"{O}/caudio/.{sh}.done"): continue
want=set(C[C.shard==sh].row.tolist())
p=hf_hub_download("Reza2kn/ganjoor-recitations-chunked",f"data/train-{sh:05d}-of-00061.parquet",repo_type="dataset",local_dir=O+"/shards_c");ri=0;n=0
for b in pq.ParquetFile(p).iter_batches(batch_size=256,columns=["audio"]):
for r in b.to_pylist():
if ri in want:
x,sr=sf.read(io.BytesIO(r["audio"]["bytes"]),dtype="int16")
if x.ndim>1: x=x.mean(1).astype("int16")
sf.write(f"{O}/caudio/{sh:02d}_{ri:05d}.flac",x,sr,format="FLAC");n+=1
ri+=1
os.remove(p);open(f"{O}/caudio/.{sh}.done","w").write("ok");print("shard",sh,n,flush=True)
print("DONE",flush=True)