zziang commited on
Commit
2f66858
·
verified ·
1 Parent(s): f3ffeb2

retake near-silent takes; whisper cap 15

Browse files
Files changed (1) hide show
  1. kaggle/radio_demo.py +15 -9
kaggle/radio_demo.py CHANGED
@@ -201,7 +201,7 @@ def main() -> None:
201
  y = y + v * (1.0 / STEPS)
202
  return y.detach()
203
 
204
- pieces, rows = [], []
205
  for line in lines:
206
  v = voices[line["slot"]]
207
  wav_path = str(BUNDLE / v["wav"])
@@ -234,18 +234,24 @@ def main() -> None:
234
  except Exception:
235
  log(f"{tag} line {line['index']} failed\n{traceback.format_exc()}")
236
  continue
237
- # A collapsed take shows up as a fraction of the expected duration:
238
- # one 24-character whisper line came out as 0.4 s of near-silence in
239
- # both voices. One retake with a different seed is cheap and fixes
240
- # most of them; keep whichever is longer.
241
- if y.size / SR < 0.09 * len(line["text"]):
242
- log(f"{tag} line {line['index']} short ({y.size/SR:.2f}s), retaking")
 
 
 
 
 
243
  try:
244
  y2 = gen(1)
245
- if y2.size > y.size:
246
  y = y2
247
  except Exception:
248
- log(f"{tag} line {line['index']} retake failed (keeping the short take)")
 
249
  wall = time.time() - t0
250
  p = OUT / "lines" / f"{tag}_{line['index']:02d}.wav"
251
  sf.write(str(p), y, SR)
 
201
  y = y + v * (1.0 / STEPS)
202
  return y.detach()
203
 
204
+ pieces, rows, peaks = [], [], []
205
  for line in lines:
206
  v = voices[line["slot"]]
207
  wav_path = str(BUNDLE / v["wav"])
 
234
  except Exception:
235
  log(f"{tag} line {line['index']} failed\n{traceback.format_exc()}")
236
  continue
237
+ # A collapsed take shows up two ways: a fraction of the expected
238
+ # duration (a 24-character whisper line came out as 0.4 s), or the
239
+ # right duration filled with near-silence (peak 0.13 against 0.68
240
+ # for every other line). One retake with a different seed is cheap;
241
+ # keep whichever take is longer and louder.
242
+ ref_peak = float(np.median(peaks)) if len(peaks) >= 2 else 0.0
243
+ weak = float(np.abs(y).max()) < (0.45 * ref_peak if ref_peak else 0.20)
244
+ short = y.size / SR < 0.09 * len(line["text"])
245
+ if short or weak:
246
+ why = "short" if short else "near-silent"
247
+ log(f"{tag} line {line['index']} {why} ({y.size/SR:.2f}s peak {np.abs(y).max():.2f}), retaking")
248
  try:
249
  y2 = gen(1)
250
+ if (y2.size, np.abs(y2).max()) > (y.size, np.abs(y).max()):
251
  y = y2
252
  except Exception:
253
+ log(f"{tag} line {line['index']} retake failed (keeping the first take)")
254
+ peaks.append(float(np.abs(y).max()))
255
  wall = time.time() - t0
256
  p = OUT / "lines" / f"{tag}_{line['index']:02d}.wav"
257
  sf.write(str(p), y, SR)