Archilyzer · Source

archilyzer

Archilyzer
git clone https://archilyzer.pages.dev/source/archilyzer.git
Log | Files | Refs | README | LICENSE

commit 579fe5421a1a061e9df3e4bff12d53e7b6a3df95
parent 31dc985afdfea9377fb8b74ece1ac17ba92b7bd6
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Fri,  6 Nov 2026 21:16:20 -0500

umtool: quote-in-audio -- find a clip's quote in the words of what it plays, and how far it is from its cues

The per-clip guarantee the operator's ear was giving. Pure: tokens (case,
punctuation, [bracketed] and apostrophes gone; numbers one token however they
are written -- "thirty eight point five" = "38.5", "a hundred" = "100"; a word
one letter off still counts), a local alignment over tokens (Smith-Waterman),
fragments split at an ellipsis and found in order, short quotes whole or not
at all. The offset is the median of heard - cued over the quote's tokens both
found, the cues' own first words (timed exactly) preferred over the words
spread across a cue.

Tests on the 6 Nov windows' parakeet words against their cues
(fixtures/rev9-a3-rumble-words.json): c43 +13.06 s, c45 +13.54 s, c20 +4.80 s,
k46 -0.50 s, c44 -0.06 s -- the editing agent's +13.1, +13.6, +5.2, -0.7, 0.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

Diffstat:
Aumtool/report-to-video/fixtures/rev9-a3-rumble-words.json | 1+
Aumtool/report-to-video/quote-in-audio.mjs | 378+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Aumtool/report-to-video/quote-in-audio.test.mjs | 94+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 473 insertions(+), 0 deletions(-)

diff --git a/umtool/report-to-video/fixtures/rev9-a3-rumble-words.json b/umtool/report-to-video/fixtures/rev9-a3-rumble-words.json @@ -0,0 +1 @@ +{"note":"rev9-a3 (quartering-diet, 6 Nov 2026): parakeet word timings of fetched Rumble windows (on the window file's clock; add `window[0]` for the cue clock) and the recording's cues around them. The editing agent measured c43 +13.1 s, c45 +13.6 s, c20 +5.2 s, k46 -0.7 s, c44 0 s.","clips":[{"id":"c43","channel":"the-quartering-rumble","video":"v7drc5w","quote":"so total loss now is thirty eight point five pounds started at three hundred forty nine I'm down to three hundred ten point five","window":[2104.34,2142.44],"words":[{"w":"If","start":2.16,"end":2.32},{"w":"the","start":2.72,"end":2.8},{"w":"link's","start":2.8,"end":3.28},{"w":"not","start":3.28,"end":3.44},{"w":"working","start":3.44,"end":3.6},{"w":"and","start":3.68,"end":3.84},{"w":"you","start":3.84,"end":3.92},{"w":"can't","start":3.92,"end":4.24},{"w":"figure","start":4.24,"end":4.48},{"w":"that","start":4.56,"end":4.72},{"w":"out.","start":4.72,"end":4.88},{"w":"Look","start":7.04,"end":7.2},{"w":"good","start":7.36,"end":7.44},{"w":"by","start":7.6,"end":7.68},{"w":"the","start":7.68,"end":7.76},{"w":"way,","start":7.76,"end":7.84},{"w":"Jeremy,","start":7.92,"end":8.32},{"w":"I'm","start":8.4,"end":8.72},{"w":"down","start":8.72,"end":8.8},{"w":"twenty","start":8.88,"end":9.04},{"w":"now","start":9.12,"end":9.2},{"w":"from","start":9.28,"end":9.44},{"w":"your","start":9.52,"end":9.6},{"w":"inspiration.","start":9.76,"end":10.32},{"w":"Dude,","start":10.48,"end":10.72},{"w":"I'm","start":11.36,"end":11.6},{"w":"so","start":11.6,"end":11.76},{"w":"proud","start":11.76,"end":12},{"w":"of","start":12.08,"end":12.16},{"w":"you.","start":12.16,"end":12.32},{"w":"That's","start":12.48,"end":12.88},{"w":"amazing.","start":12.88,"end":13.44},{"w":"That's","start":15.68,"end":16.08},{"w":"crazy","start":16.08,"end":16.48},{"w":"good,","start":16.56,"end":16.72},{"w":"dude.","start":16.8,"end":17.12},{"w":"I","start":19.04,"end":19.2},{"w":"weighed","start":19.2,"end":19.52},{"w":"in","start":19.52,"end":19.68},{"w":"this","start":19.68,"end":19.76},{"w":"morning","start":19.76,"end":20},{"w":"and","start":20.08,"end":20.24},{"w":"the","start":20.24,"end":20.32},{"w":"weight","start":20.32,"end":20.64},{"w":"loss","start":20.64,"end":20.96},{"w":"has","start":20.96,"end":21.12},{"w":"slowed,","start":21.2,"end":21.68},{"w":"but","start":22.56,"end":22.8},{"w":"I","start":23.2,"end":23.28},{"w":"lost","start":23.76,"end":24.08},{"w":"another","start":24.4,"end":24.64},{"w":"pound","start":25.44,"end":25.76},{"w":"and","start":25.84,"end":25.92},{"w":"a","start":25.92,"end":26},{"w":"half,","start":26.08,"end":26.32},{"w":"I","start":26.48,"end":26.64},{"w":"think","start":26.64,"end":26.8},{"w":"last","start":27.04,"end":27.12},{"w":"week.","start":27.36,"end":27.68},{"w":"So","start":28.56,"end":28.72},{"w":"total","start":28.88,"end":29.2},{"w":"loss","start":29.28,"end":29.6},{"w":"now","start":29.68,"end":29.84},{"w":"is","start":29.92,"end":30.08},{"w":"thirty","start":30.16,"end":30.48},{"w":"eight","start":30.64,"end":30.8},{"w":"point","start":30.88,"end":31.04},{"w":"five","start":31.2,"end":31.36},{"w":"pounds.","start":31.52,"end":31.92},{"w":"I","start":32.72,"end":32.8},{"w":"started","start":32.96,"end":33.2},{"w":"at","start":33.2,"end":33.28},{"w":"three","start":33.36,"end":33.44},{"w":"hundred","start":33.52,"end":33.6},{"w":"forty","start":33.68,"end":33.84},{"w":"nine,","start":33.92,"end":34.08},{"w":"I'm","start":34.24,"end":34.48},{"w":"down","start":34.48,"end":34.64},{"w":"to","start":34.64,"end":34.72},{"w":"three","start":34.8,"end":34.88},{"w":"hundred","start":34.96,"end":35.12},{"w":"ten","start":35.12,"end":35.2},{"w":"point","start":35.36,"end":35.52},{"w":"five.","start":35.68,"end":35.84},{"w":"My","start":36.4,"end":36.48},{"w":"goal","start":36.56,"end":36.72},{"w":"is","start":36.88,"end":36.96},{"w":"probably","start":36.96,"end":37.04},{"w":"two","start":37.28,"end":37.36},{"w":"and","start":37.52,"end":37.6},{"w":"a","start":37.6,"end":37.68},{"w":"quarter.","start":37.68,"end":37.92}],"cues":[{"start":2078,"end":2084.72,"text":"I can't figure out the ad too confusing for me but here's a little support in a way I can figure out appreciate the paladin"},{"start":2087.28,"end":2090.88,"text":"basically just go to the Google Play store and download Rumble Wallet"},{"start":2093.84,"end":2096,"text":"if the link's not working and you can't figure that out"},{"start":2098.64,"end":2104.56,"text":"good by the way Jeremy I'm down twenty now from your inspiration dude I'm so proud of you that's amazing"},{"start":2106.96,"end":2108.4,"text":"that's crazy good dude"},{"start":2110.24,"end":2112.96,"text":"I weighed in this morning and the weight loss has slowed"},{"start":2113.76,"end":2115.84,"text":"but I lost another"},{"start":2116.72,"end":2118.96,"text":"pound and a half I think last week"},{"start":2119.84,"end":2123.2,"text":"so total loss now is thirty eight point five pounds"},{"start":2124.24,"end":2127.04,"text":"started at three hundred forty nine I'm down to three hundred ten point five"},{"start":2127.92,"end":2129.84,"text":"my goal is probably two and a quarter"},{"start":2131.12,"end":2138.4,"text":"I'd be I'd be very happy even at two hundred forty even though that would still technically be obese I think or certainly overweight"},{"start":2139.76,"end":2140,"text":"but"},{"start":2140.88,"end":2141.6,"text":"two twenty five"},{"start":2142.4,"end":2142.88,"text":"thirty five"},{"start":2144,"end":2147.92,"text":"which means what I have another seventy five eighty five pounds to lose"},{"start":2149.28,"end":2151.2,"text":"I think I can do that by the end of next year"},{"start":2153.84,"end":2154.88,"text":"by the end of next year."},{"start":2157.36,"end":2159.12,"text":"Melanie's helping me out with some"},{"start":2160.08,"end":2161.2,"text":"I asked her to do some"},{"start":2162.24,"end":2170.24,"text":"by Melanie and I'm still great friends she's helping me out because she sent me a workout list to do like workout exercises"}]},{"id":"c44","channel":"the-quartering-rumble","video":"v7eqa6e","quote":"I am now down fifty point one pounds in eleven weeks and I am under three hundred for the first time since college","window":[618.42,659.16],"words":[{"w":"Oh","start":0,"end":0.08},{"w":"no,","start":0.56,"end":0.64},{"w":"I","start":0.72,"end":0.8},{"w":"didn't","start":0.88,"end":1.12},{"w":"I","start":2.4,"end":2.48},{"w":"shook","start":2.48,"end":2.72},{"w":"up","start":2.72,"end":2.88},{"w":"my","start":2.88,"end":3.04},{"w":"water","start":3.04,"end":3.2},{"w":"and","start":3.28,"end":3.44},{"w":"I","start":3.44,"end":3.6},{"w":"didn't","start":3.6,"end":3.84},{"w":"close","start":3.84,"end":4.16},{"w":"the","start":4.16,"end":4.32},{"w":"top.","start":4.32,"end":4.48},{"w":"That'll","start":4.96,"end":5.44},{"w":"teach","start":5.44,"end":5.76},{"w":"me.","start":5.76,"end":5.92},{"w":"Also,","start":11.6,"end":11.92},{"w":"weight","start":12.72,"end":12.88},{"w":"loss","start":12.96,"end":13.2},{"w":"journey","start":13.28,"end":13.68},{"w":"announcement.","start":13.84,"end":14.32},{"w":"I","start":15.44,"end":15.6},{"w":"am","start":15.6,"end":15.68},{"w":"now","start":15.76,"end":15.92},{"w":"down","start":16,"end":16.24},{"w":"fifty","start":16.4,"end":16.72},{"w":"point","start":16.72,"end":16.88},{"w":"one","start":17.04,"end":17.2},{"w":"pounds","start":17.36,"end":17.76},{"w":"in","start":18.96,"end":19.12},{"w":"eleven","start":19.2,"end":19.44},{"w":"weeks","start":19.6,"end":20},{"w":"and","start":22.08,"end":22.32},{"w":"I","start":22.8,"end":22.88},{"w":"am","start":22.88,"end":23.04},{"w":"under","start":23.12,"end":23.36},{"w":"three","start":23.44,"end":23.6},{"w":"hundred","start":23.6,"end":23.68},{"w":"for","start":24,"end":24.16},{"w":"the","start":24.16,"end":24.24},{"w":"first","start":24.24,"end":24.4},{"w":"time","start":24.4,"end":24.56},{"w":"since","start":24.56,"end":24.88},{"w":"college.","start":24.96,"end":25.44},{"w":"Obviously","start":26.32,"end":26.72},{"w":"I","start":26.8,"end":26.88},{"w":"have","start":26.96,"end":27.04},{"w":"a","start":27.04,"end":27.12},{"w":"long","start":27.2,"end":27.28},{"w":"way","start":27.36,"end":27.52},{"w":"to","start":27.52,"end":27.68},{"w":"go.","start":27.68,"end":27.84},{"w":"I","start":29.44,"end":29.52},{"w":"want","start":29.68,"end":29.84},{"w":"to","start":29.92,"end":30.08},{"w":"get","start":30.08,"end":30.24},{"w":"I","start":30.56,"end":30.64},{"w":"mean,","start":30.72,"end":30.88},{"w":"whatever","start":31.04,"end":31.44},{"w":"the","start":31.44,"end":31.68},{"w":"internet","start":31.68,"end":32.08},{"w":"scales","start":32.16,"end":32.48},{"w":"say","start":32.64,"end":32.72},{"w":"I","start":32.8,"end":32.96},{"w":"should","start":32.96,"end":33.12},{"w":"be","start":33.12,"end":33.2},{"w":"at","start":33.2,"end":33.28},{"w":"like","start":33.44,"end":33.52},{"w":"two","start":33.6,"end":33.76},{"w":"hundred","start":33.76,"end":33.92},{"w":"twenty","start":33.92,"end":34.08},{"w":"at","start":35.2,"end":35.36},{"w":"six.","start":35.44,"end":35.52},{"w":"I","start":37.76,"end":37.92},{"w":"don't","start":37.92,"end":38.16},{"w":"think","start":38.16,"end":38.24},{"w":"I'll","start":38.32,"end":38.56},{"w":"ever","start":38.56,"end":38.64},{"w":"get","start":38.8,"end":38.88},{"w":"to","start":38.88,"end":38.96},{"w":"two","start":39.04,"end":39.12},{"w":"hundred","start":39.12,"end":39.28},{"w":"twenty.","start":39.36,"end":39.52}],"cues":[{"start":603.28,"end":609.92,"text":"it's abundantly obvious that Jeremy adores his animals that's not even in question exactly anybody who actually watches the show you know what I mean like"},{"start":611.04,"end":613.92,"text":"yeah but people create like an alternate reality"},{"start":614.8,"end":619.52,"text":"because I don't know I don't know it gets clicks I guess so no I didn't"},{"start":620.8,"end":624.48,"text":"I shook up my water and I didn't close the top that'll teach me"},{"start":630.08,"end":630.32,"text":"also"},{"start":631.2,"end":632.72,"text":"weight loss journey announcement"},{"start":633.92,"end":636.16,"text":"I am now down fifty point one pounds"},{"start":637.44,"end":638.48,"text":"in eleven weeks"},{"start":640.48,"end":643.76,"text":"and I am under three hundred for the first time since college"},{"start":644.72,"end":646.32,"text":"obviously I have a long way to go"},{"start":647.92,"end":652.56,"text":"I want to get I mean whatever the internet scales say I should be at like two hundred twenty"},{"start":653.6,"end":654,"text":"at six"},{"start":656.24,"end":657.92,"text":"I don't think I'll ever get to twenty"},{"start":658.8,"end":660.8,"text":"but I'd be really happy at like"},{"start":662,"end":669.68,"text":"two thirty two forty so we got another seventy to go so my goal was fifty by Christmas I got there now"},{"start":670.32,"end":670.56,"text":"and"},{"start":672.08,"end":679.6,"text":"you know I'm not going to take the foot off the gas maybe now I can be down fifty five or sixty by Christmas because I have another what"}]},{"id":"c45","channel":"the-quartering-rumble","video":"v7eqa6e","quote":"when I started my weight loss journey I was at almost three hundred ninety pounds so I've lost almost a hundred since starting it.","window":[2294.18,2337.8],"words":[{"w":"A","start":1.52,"end":1.68},{"w":"little","start":1.68,"end":1.84},{"w":"bit","start":1.84,"end":1.92},{"w":"QR","start":2.96,"end":3.28},{"w":"code","start":3.36,"end":3.6},{"w":"too","start":3.68,"end":3.76},{"w":"small.","start":3.84,"end":3.92},{"w":"There","start":4.16,"end":4.24},{"w":"should","start":4.24,"end":4.32},{"w":"be","start":4.4,"end":4.48},{"w":"a","start":4.48,"end":4.56},{"w":"link","start":4.64,"end":4.8},{"w":"in","start":4.88,"end":4.96},{"w":"the","start":4.96,"end":5.04},{"w":"description","start":5.04,"end":5.44},{"w":"you","start":5.52,"end":5.6},{"w":"can","start":5.6,"end":5.68},{"w":"use","start":5.76,"end":5.84},{"w":"too.","start":6,"end":6.16},{"w":"I","start":10.72,"end":10.88},{"w":"think","start":10.88,"end":10.96},{"w":"let","start":12.4,"end":12.56},{"w":"me","start":12.56,"end":12.64},{"w":"go","start":12.8,"end":13.04},{"w":"here.","start":13.04,"end":13.28},{"w":"From","start":15.68,"end":15.84},{"w":"Devin,","start":15.92,"end":16.32},{"w":"congrats","start":16.4,"end":16.96},{"w":"on","start":16.96,"end":17.12},{"w":"being","start":17.12,"end":17.28},{"w":"under","start":17.28,"end":17.44},{"w":"three","start":17.52,"end":17.6},{"w":"hundred","start":17.6,"end":17.68},{"w":"pounds.","start":17.84,"end":18.08},{"w":"People","start":18.24,"end":18.4},{"w":"don't","start":18.48,"end":18.72},{"w":"realize","start":18.72,"end":19.04},{"w":"how","start":19.04,"end":19.2},{"w":"difficult","start":19.2,"end":19.6},{"w":"that","start":19.6,"end":19.68},{"w":"is.","start":19.68,"end":19.76},{"w":"Keep","start":20,"end":20.16},{"w":"it","start":20.16,"end":20.24},{"w":"up","start":20.32,"end":20.4},{"w":"dude.","start":20.48,"end":20.8},{"w":"Well,","start":21.28,"end":21.44},{"w":"you","start":21.68,"end":21.76},{"w":"know,","start":21.84,"end":22},{"w":"I'll","start":22.48,"end":22.8},{"w":"tell","start":22.8,"end":22.96},{"w":"you","start":22.96,"end":23.04},{"w":"this,","start":23.12,"end":23.28},{"w":"it's","start":23.36,"end":23.68},{"w":"very","start":23.68,"end":23.92},{"w":"easy","start":23.92,"end":24.08},{"w":"to","start":24.16,"end":24.24},{"w":"get","start":24.24,"end":24.4},{"w":"over","start":24.4,"end":24.56},{"w":"three","start":24.72,"end":24.88},{"w":"hundred.","start":24.88,"end":24.96},{"w":"When","start":29.12,"end":29.28},{"w":"I","start":29.28,"end":29.44},{"w":"started","start":29.44,"end":29.68},{"w":"my","start":29.68,"end":29.84},{"w":"weight","start":29.84,"end":30},{"w":"loss","start":30.08,"end":30.32},{"w":"journey,","start":30.4,"end":30.8},{"w":"I","start":30.96,"end":31.12},{"w":"was","start":31.12,"end":31.28},{"w":"at","start":31.28,"end":31.44},{"w":"almost","start":31.6,"end":31.92},{"w":"three","start":32,"end":32.08},{"w":"hundred","start":32.24,"end":32.4},{"w":"ninety","start":32.56,"end":32.88},{"w":"pounds.","start":32.88,"end":33.28},{"w":"So","start":34.24,"end":34.4},{"w":"I've","start":34.4,"end":34.72},{"w":"lost","start":34.72,"end":34.88},{"w":"almost","start":35.04,"end":35.28},{"w":"a","start":35.44,"end":35.52},{"w":"hundred","start":35.52,"end":35.6},{"w":"since","start":35.92,"end":36.08},{"w":"starting","start":36.16,"end":36.32},{"w":"it.","start":36.4,"end":36.48},{"w":"I","start":36.64,"end":36.8},{"w":"started","start":36.8,"end":37.04},{"w":"it","start":37.04,"end":37.2},{"w":"with","start":37.2,"end":37.36},{"w":"intermittent","start":37.36,"end":37.84},{"w":"fasting","start":38,"end":38.48},{"w":"to","start":39.04,"end":39.2},{"w":"get","start":39.2,"end":39.36},{"w":"down","start":39.36,"end":39.44},{"w":"to","start":39.6,"end":39.68},{"w":"whatever","start":39.92,"end":40.24},{"w":"I","start":40.32,"end":40.4},{"w":"was","start":40.4,"end":40.48},{"w":"at","start":40.56,"end":40.64},{"w":"three","start":40.8,"end":40.88},{"w":"hundred","start":40.96,"end":41.04},{"w":"fifty","start":41.12,"end":41.36},{"w":"something","start":41.44,"end":41.52},{"w":"and","start":42.48,"end":42.56},{"w":"I","start":42.64,"end":42.72},{"w":"fell","start":42.8,"end":42.96},{"w":"off","start":42.96,"end":43.04},{"w":"the","start":43.2,"end":43.28},{"w":"weight.","start":43.28,"end":43.36}],"cues":[{"start":2273.28,"end":2277.76,"text":"shout out to the six thousand wonderful people in viewing right now"},{"start":2279.04,"end":2280.4,"text":"I know news is a little bit"},{"start":2282.08,"end":2286.8,"text":"a little bit QR code is too small there should be a link in the description you can use too"},{"start":2291.36,"end":2291.6,"text":"I think"},{"start":2293.04,"end":2293.92,"text":"let me go here"},{"start":2296.32,"end":2304.32,"text":"from Devin congrats on being under three hundred pounds people don't realize how difficult that is keep it up dude. Well you know I'll tell you this it's"},{"start":2304.32,"end":2305.76,"text":"very easy to get over three hundred"},{"start":2309.68,"end":2314,"text":"when I started my weight loss journey I was at almost three hundred ninety pounds"},{"start":2314.96,"end":2322.4,"text":"so I've lost almost a hundred since starting it. I started it with intermittent fasting to get down to whatever I was at three hundred fifty something"},{"start":2323.36,"end":2325.84,"text":"and then I fell off the wagon so then I started"},{"start":2327.52,"end":2331.2,"text":"intermittent fasting plus keto plus walking"},{"start":2332.4,"end":2340.32,"text":"and I lost another fifty I've got seventy to go or so hopefully I don't look all old when I lose the weight that'll be the bummer"},{"start":2342.56,"end":2350.16,"text":"like look what happened to John Goodman when he lost the weight look what happened to who's the fat funny guy"},{"start":2351.12,"end":2351.84,"text":"Jonah Hill"},{"start":2352.72,"end":2356.08,"text":"he lost that weight and he looks thirty years older"}]},{"id":"c20","channel":"the-quartering-rumble","video":"v6pmznn","quote":"I promise you, by this time next year I will be down 100 pounds","window":[7486.82,7506.74],"words":[{"w":"Damn,","start":1.12,"end":1.44},{"w":"he","start":1.6,"end":1.68},{"w":"is","start":2,"end":2.08},{"w":"eighty.","start":2.16,"end":2.4},{"w":"Is","start":2.8,"end":2.88},{"w":"he","start":3.04,"end":3.12},{"w":"seventy","start":3.28,"end":3.44},{"w":"nine?","start":3.52,"end":3.68},{"w":"He","start":3.92,"end":4},{"w":"actually","start":4,"end":4.08},{"w":"does","start":4.16,"end":4.24},{"w":"look","start":4.32,"end":4.4},{"w":"good.","start":4.56,"end":4.64},{"w":"He","start":5.04,"end":5.12},{"w":"looks","start":5.2,"end":5.36},{"w":"nine.","start":5.36,"end":5.44},{"w":"Great.","start":6,"end":6.16},{"w":"Yeah,","start":6.4,"end":6.48},{"w":"holy","start":6.8,"end":7.04},{"w":"crap.","start":7.2,"end":7.52},{"w":"What","start":7.84,"end":7.92},{"w":"a","start":8,"end":8.08},{"w":"miracle","start":8.08,"end":8.4},{"w":"genetics.","start":8.48,"end":8.88},{"w":"Imagine","start":9.12,"end":9.6},{"w":"if","start":9.68,"end":9.76},{"w":"he","start":9.76,"end":9.84},{"w":"wasn't","start":9.84,"end":10.32},{"w":"fat.","start":10.32,"end":10.48},{"w":"Well,","start":10.8,"end":10.88},{"w":"yeah,","start":11.2,"end":11.28},{"w":"what'll","start":11.52,"end":11.84},{"w":"happen","start":11.84,"end":11.92},{"w":"though","start":12,"end":12.16},{"w":"is","start":12.24,"end":12.32},{"w":"like,","start":12.4,"end":12.48},{"w":"you'll","start":12.56,"end":12.8},{"w":"see,","start":12.8,"end":12.88},{"w":"I","start":13.04,"end":13.12},{"w":"promise","start":13.2,"end":13.52},{"w":"you","start":13.6,"end":13.68},{"w":"by","start":13.84,"end":14},{"w":"this","start":14,"end":14.08},{"w":"time","start":14.08,"end":14.24},{"w":"next","start":14.24,"end":14.32},{"w":"year","start":14.48,"end":14.64},{"w":"I","start":14.72,"end":14.8},{"w":"will","start":14.8,"end":14.96},{"w":"be","start":15.04,"end":15.12},{"w":"down","start":15.12,"end":15.2},{"w":"one","start":15.36,"end":15.44},{"w":"hundred","start":15.44,"end":15.52},{"w":"pounds","start":15.6,"end":15.92},{"w":"and","start":16,"end":16.16},{"w":"I'll","start":16.16,"end":16.4},{"w":"look","start":16.4,"end":16.56},{"w":"ten","start":16.56,"end":16.72},{"w":"years","start":16.72,"end":16.88},{"w":"older.","start":16.88,"end":17.28},{"w":"Like","start":17.52,"end":17.6},{"w":"there's","start":17.84,"end":18.08},{"w":"something","start":18.08,"end":18.16},{"w":"that","start":18.24,"end":18.32},{"w":"happens","start":18.32,"end":18.56},{"w":"when","start":18.64,"end":18.8},{"w":"big","start":18.88,"end":18.96},{"w":"guys","start":19.04,"end":19.12},{"w":"lose","start":19.28,"end":19.44},{"w":"weight.","start":19.52,"end":19.76}],"cues":[{"start":7463.1,"end":7469.34,"text":"you can still do cardio in a wheelchair, you can do you can do a lot of stuff in a wheelchair."},{"start":7469.34,"end":7477.9,"text":"So I mean, you know, I don't really do looks pretty good for 80. He's not 80. No, if he's 80,"},{"start":7477.9,"end":7484.7,"text":"then he looks great. I know. Can I say he's 80? There's no way. Damn, he is 80."},{"start":7484.7,"end":7489.82,"text":"He's 79. He actually does look the first. He looks great. Yeah. Holy crap."},{"start":7489.82,"end":7494.62,"text":"Miracle genetics. Imagine if he wasn't fat. Well, yeah, what will happen though is like,"},{"start":7494.62,"end":7498.86,"text":"you'll see, I promise you by this time next year, I will be down 100 pounds and I'll look 10 years"},{"start":7498.86,"end":7503.74,"text":"older. Like there's something that happens when big guys lose weight, you know, it's worth it."},{"start":7503.74,"end":7510.06,"text":"Yeah. Yeah. It's worth it. Yeah. Also, the thing is, though, is you don't carry a lot of weight"},{"start":7510.06,"end":7515.9,"text":"in your face, though. No, that might be okay. I because yeah, I don't think you're going to have"},{"start":7515.9,"end":7522.38,"text":"a ton of problems. Yeah, it'll be all right. Yeah, I take it all back. This guy's killing it."},{"start":7522.38,"end":7531.18,"text":"Like, I don't care if he is 400 pounds. He's 80 years old, like, slay king. Yeah."}]},{"id":"k46","channel":"the-quartering-rumble","video":"v6qogub","quote":"My goal is to lose 100 pounds by Christmas. Trust me, I have a plan and I'm going to try to stick to it.","window":[810.52,854.42],"words":[{"w":"in","start":1.12,"end":1.2},{"w":"April.","start":1.2,"end":1.52},{"w":"I","start":1.68,"end":1.76},{"w":"lost","start":1.84,"end":2},{"w":"about","start":2.08,"end":2.24},{"w":"ten","start":2.24,"end":2.32},{"w":"pounds","start":2.4,"end":2.72},{"w":"in","start":2.8,"end":2.88},{"w":"April.","start":2.88,"end":3.28},{"w":"My","start":4.8,"end":4.96},{"w":"goal","start":4.96,"end":5.2},{"w":"is","start":5.2,"end":5.28},{"w":"to","start":5.36,"end":5.44},{"w":"lose","start":5.52,"end":5.68},{"w":"one","start":5.76,"end":5.92},{"w":"hundred","start":5.92,"end":6.08},{"w":"pounds","start":6.16,"end":6.48},{"w":"by","start":6.56,"end":6.72},{"w":"Christmas.","start":6.72,"end":7.28},{"w":"I","start":7.92,"end":8.08},{"w":"know","start":8.08,"end":8.24},{"w":"that's","start":8.4,"end":8.64},{"w":"a","start":8.64,"end":8.8},{"w":"lot","start":8.8,"end":8.96},{"w":"and","start":9.36,"end":9.52},{"w":"generally","start":9.52,"end":9.84},{"w":"that","start":10,"end":10.16},{"w":"triggers","start":10.16,"end":10.4},{"w":"everyone","start":10.56,"end":10.88},{"w":"giving","start":10.96,"end":11.28},{"w":"unsolicited","start":11.28,"end":11.92},{"w":"health","start":12.16,"end":12.48},{"w":"advice.","start":12.56,"end":13.04},{"w":"Trust","start":15.2,"end":15.52},{"w":"me,","start":15.52,"end":15.6},{"w":"I","start":16.48,"end":16.56},{"w":"have","start":16.72,"end":16.88},{"w":"a","start":16.88,"end":17.04},{"w":"plan","start":17.04,"end":17.28},{"w":"and","start":17.76,"end":18},{"w":"I'm","start":18.64,"end":18.88},{"w":"going","start":18.96,"end":19.04},{"w":"to","start":19.04,"end":19.12},{"w":"try","start":19.2,"end":19.36},{"w":"to","start":19.36,"end":19.52},{"w":"stick","start":19.52,"end":19.68},{"w":"to","start":19.68,"end":19.84},{"w":"it.","start":19.84,"end":19.92},{"w":"So","start":20.08,"end":20.16},{"w":"one","start":20.32,"end":20.4},{"w":"hundred","start":20.4,"end":20.48},{"w":"pounds","start":20.64,"end":20.96},{"w":"by","start":21.12,"end":21.28},{"w":"Christmas.","start":21.36,"end":21.92},{"w":"That's","start":22.72,"end":23.12},{"w":"roughly","start":23.92,"end":24.48},{"w":"ten","start":24.96,"end":25.12},{"w":"or","start":25.52,"end":25.68},{"w":"fifteen","start":25.76,"end":26.08},{"w":"pounds","start":26.16,"end":26.48},{"w":"a","start":26.64,"end":26.72},{"w":"month.","start":26.72,"end":27.04},{"w":"When","start":27.76,"end":27.84},{"w":"you're","start":27.92,"end":28.08},{"w":"one","start":28.16,"end":28.24},{"w":"hundred","start":28.24,"end":28.32},{"w":"pounds","start":28.48,"end":28.72},{"w":"overweight,","start":28.8,"end":29.28},{"w":"I","start":29.44,"end":29.6},{"w":"should","start":29.6,"end":29.76},{"w":"be","start":29.76,"end":29.84},{"w":"able","start":29.92,"end":30.08},{"w":"to","start":30.08,"end":30.24},{"w":"do","start":30.24,"end":30.32},{"w":"it.","start":30.32,"end":30.48},{"w":"It","start":30.72,"end":30.88},{"w":"should","start":30.88,"end":31.04},{"w":"be","start":31.12,"end":31.28},{"w":"close.","start":31.28,"end":31.6},{"w":"And","start":33.28,"end":33.44},{"w":"last","start":33.52,"end":33.68},{"w":"month","start":33.68,"end":33.92},{"w":"I","start":34,"end":34.08},{"w":"was","start":34.16,"end":34.32},{"w":"only","start":34.32,"end":34.48},{"w":"like","start":34.64,"end":34.8},{"w":"half","start":35.04,"end":35.28},{"w":"assinant.","start":35.68,"end":36.32},{"w":"Actually,","start":36.64,"end":36.96},{"w":"I","start":37.04,"end":37.12},{"w":"was","start":37.12,"end":37.2},{"w":"like","start":37.28,"end":37.36},{"w":"quarter","start":37.44,"end":37.76},{"w":"assinant","start":37.92,"end":38.4},{"w":"last","start":38.56,"end":38.72},{"w":"week.","start":38.8,"end":39.04},{"w":"Quarter","start":39.36,"end":39.76},{"w":"assin.","start":40,"end":40.48}],"cues":[{"start":784.02,"end":795.02,"text":"Like, everyone just automatically leaves a like on the video when they get in here. Let's get on that homepage and see if we can start finding some new people."},{"start":795.02,"end":803.02,"text":"Same thing I try to do every weekend. Take over the world. That's right. So, what do I got going on?"},{"start":803.02,"end":816.02,"text":"I had a doctor's appointment this morning for my foot. Everything looks good. It's healing. I've lost 10 pounds in April. I lost about 10 pounds in April."},{"start":816.02,"end":826.02,"text":"My goal is to lose 100 pounds by Christmas. I know that's a lot. And generally that triggers everyone giving unsolicited health advice."},{"start":826.02,"end":839.02,"text":"Trust me, I have a plan and I'm going to try to stick to it. So 100 pounds by Christmas. That's roughly 10 or 15 pounds a month."},{"start":839.02,"end":844.02,"text":"When you're 100 pounds overweight, I should be able to do it. It should be close."},{"start":844.02,"end":853.02,"text":"And last month, I was only like half-assen it. Actually, I was like quarter-assen it last week. Quarter-assen?"},{"start":853.02,"end":861.02,"text":"Because, you know, my foot was hurt and I had to stop working out for the last week."},{"start":861.02,"end":869.02,"text":"I hope Jeremy's coffee can be survived. I don't buy it, but it's cool. He thinks, well, yeah, I'm going to talk about that later. I think I'm going to do a little."},{"start":869.02,"end":881.02,"text":"I was thinking about putting out some sort of contest like I'll shave my head if we just break even."}]}]} diff --git a/umtool/report-to-video/quote-in-audio.mjs b/umtool/report-to-video/quote-in-audio.mjs @@ -0,0 +1,378 @@ +// quote-in-audio — IS THE QUOTE IN THE SECONDS THE CLIP PLAYS? (lane one-clock) +// +// The per-clip guarantee the operator's ear was giving: transcribe what the +// render will actually play (the clip's source window, words timed), find the +// clip's `quote` in those words, and say how far from the cue clock's seconds +// it is. On 6 Nov seven Rumble clips played other words than their quotes +// (c43 +13.1 s: the 9:18 "310" misclip, c45 +13.6 s, c20 +5.2 s, k41 +2.6 s, +// c18 +1.6 s, k46 −0.7 s, c19 ≈ −1 s) and only listening caught it. +// +// THE MATCH is loose on purpose: the quote is prose a person wrote about speech +// a machine transcribed. Case, punctuation, `[bracketed]` editorial words and +// apostrophes go; NUMBERS are one token however they are written ("thirty eight +// point five" = "38.5", "a hundred" = "100", "three hundred ten point five" = +// "310.5"); a word one letter off still counts ("weighed"/"waited" does not — +// two letters). An ellipsis splits the quote into fragments found in order. The +// alignment is a local one (Smith–Waterman over tokens), so a quote that starts +// a word early or runs past the window is still found by its middle. +// +// Pure. The transcription is the caller's (lib/report/quoteCheck.mjs asks the +// editor's transcribe op); words arrive on the CUE clock. + +const ONES = { + zero: 0, oh: 0, one: 1, two: 2, three: 3, four: 4, five: 5, six: 6, seven: 7, eight: 8, nine: 9, ten: 10, + eleven: 11, twelve: 12, thirteen: 13, fourteen: 14, fifteen: 15, sixteen: 16, seventeen: 17, eighteen: 18, nineteen: 19, +}; +const TENS = { twenty: 20, thirty: 30, forty: 40, fourty: 40, fifty: 50, sixty: 60, seventy: 70, eighty: 80, ninety: 90 }; +const DIGIT_WORDS = { zero: "0", oh: "0", one: "1", two: "2", three: "3", four: "4", five: "5", six: "6", seven: "7", eight: "8", nine: "9" }; + +/** The minimum share of the quote's tokens a match must align to be FOUND. */ +export const MIN_MATCH = 0.6; +/** Within this many seconds of the cue clock, a found quote is where the clip says. */ +export const ON_TIME_S = 0.5; + +/** + * Raw word tokens of a text: lower case, no `[bracketed]` editorial, no + * apostrophes, digits with their decimal point and thousands commas folded. + * @param {string} text + * @returns {string[]} + */ +export function rawTokens(text) { + return String(text ?? "") + .toLowerCase() + .replace(/\[[^\]]*\]/g, " ") + .replace(/(\d),(\d{3})\b/g, "$1$2") + .replace(/%/g, " percent ") + .replace(/[’'`]/g, "") + .replace(/(\d)\.(\d)/g, "$1\u0000$2") + .replace(/[^a-z0-9\u0000]+/g, " ") + .replace(/\u0000/g, ".") + .split(" ") + .filter(Boolean); +} + +/** + * Fold every run of number words into one numeric token, keeping which raw + * tokens each output token came from. + * @param {string[]} toks + * @returns {{ t: string, from: number, to: number }[]} `from`/`to`: raw token indexes (inclusive) + */ +export function foldNumbers(toks) { + const out = []; + let i = 0; + while (i < toks.length) { + const w = toks[i]; + const startsNumber = w in ONES || w in TENS || (w === "a" && toks[i + 1] === "hundred"); + if (!startsNumber) { + out.push({ t: w, from: i, to: i }); + i += 1; + continue; + } + let total = 0; + let cur = 0; + let j = i; + let lastKind = ""; + for (; j < toks.length; j += 1) { + const x = toks[j]; + if (x in ONES) { + // "twenty twenty one", "five five": a second small number starts anew. + if (lastKind === "one" || (lastKind === "ten" && ONES[x] >= 10)) break; + cur += ONES[x]; + lastKind = "one"; + } else if (x in TENS) { + if (lastKind === "one" || lastKind === "ten") break; + cur += TENS[x]; + lastKind = "ten"; + } else if (x === "a" && toks[j + 1] === "hundred" && lastKind === "") { + cur = 1; + lastKind = "a"; + } else if (x === "hundred" && (lastKind === "one" || lastKind === "a" || lastKind === "ten")) { + cur = (cur || 1) * 100; + lastKind = "hundred"; + } else if (x === "thousand" && lastKind !== "") { + total += (cur || 1) * 1000; + cur = 0; + lastKind = "thousand"; + } else if (x === "and" && (lastKind === "hundred" || lastKind === "thousand") && (toks[j + 1] in ONES || toks[j + 1] in TENS)) { + lastKind = "and"; + } else break; + } + let value = String(total + cur); + let end = j - 1; + // "point five", "point one five": decimals digit by digit. + if (toks[j] === "point" && toks[j + 1] in DIGIT_WORDS) { + let k = j + 1; + let dec = ""; + while (k < toks.length && toks[k] in DIGIT_WORDS) { + dec += DIGIT_WORDS[toks[k]]; + k += 1; + } + value = `${value}.${dec}`; + end = k - 1; + j = k; + } + if (end < i) { + out.push({ t: w, from: i, to: i }); + i += 1; + continue; + } + out.push({ t: value, from: i, to: end }); + i = end + 1; + } + return out; +} + +/** A text as match tokens. @param {string} text @returns {string[]} */ +export const quoteTokens = (text) => foldNumbers(rawTokens(text)).map((x) => x.t); + +/** + * Timed words as match tokens: each token keeps the start of its first word and + * the end of its last. + * @param {{ w?: string, text?: string, start: number, end: number }[]} words + * @returns {{ t: string, start: number, end: number }[]} + */ +export function timedTokens(words) { + const raw = []; + for (const w of words ?? []) { + rawTokens(w.w ?? w.text ?? "").forEach((t, k) => + raw.push({ t, start: Number(w.start), end: Number(w.end), anchor: k === 0 && w.anchor === true }), + ); + } + return foldNumbers(raw.map((r) => r.t)).map((x) => ({ + t: x.t, + start: raw[x.from].start, + end: raw[x.to].end, + ...(raw[x.from].anchor ? { anchor: true } : {}), + })); +} + +function lev1(a, b) { + if (a === b) return true; + if (a.length < 4 || b.length < 4 || Math.abs(a.length - b.length) > 1) return false; + let i = 0; + let j = 0; + let edits = 0; + while (i < a.length && j < b.length) { + if (a[i] === b[j]) { + i += 1; + j += 1; + continue; + } + edits += 1; + if (edits > 1) return false; + if (a.length > b.length) i += 1; + else if (b.length > a.length) j += 1; + else { + i += 1; + j += 1; + } + } + return edits + (a.length - i) + (b.length - j) <= 1; +} + +/** Same token: equal, a near spelling, or one number written two ways ("40" / "40.0"). */ +export function sameToken(a, b) { + if (a === b) return true; + const na = Number(a); + const nb = Number(b); + if (/^\d/.test(a) && /^\d/.test(b) && Number.isFinite(na) && na === nb) return true; + return lev1(a, b); +} + +/** + * The best LOCAL alignment of `q` inside `w` (Smith–Waterman: match +2, + * mismatch −1, gap −1), searching from `w[from]` on. + * @param {string[]} q + * @param {{ t: string }[]} w + * @param {number} [from] + * @returns {{ pairs: [number, number][], score: number }} pairs: [q index, w index], in order + */ +export function alignLocal(q, w, from = 0) { + const n = q.length; + const m = w.length - from; + if (!n || m <= 0) return { pairs: [], score: 0 }; + const H = Array.from({ length: n + 1 }, () => new Float64Array(m + 1)); + const B = Array.from({ length: n + 1 }, () => new Uint8Array(m + 1)); // 1 diag, 2 up, 3 left + let best = 0; + let bi = 0; + let bj = 0; + for (let i = 1; i <= n; i += 1) { + for (let j = 1; j <= m; j += 1) { + const match = sameToken(q[i - 1], w[from + j - 1].t); + const d = H[i - 1][j - 1] + (match ? 2 : -1); + const u = H[i - 1][j] - 1; + const l = H[i][j - 1] - 1; + let v = 0; + let b = 0; + if (d > v) [v, b] = [d, 1]; + if (u > v) [v, b] = [u, 2]; + if (l > v) [v, b] = [l, 3]; + H[i][j] = v; + B[i][j] = b; + if (v > best) [best, bi, bj] = [v, i, j]; + } + } + const pairs = []; + let i = bi; + let j = bj; + while (i > 0 && j > 0 && H[i][j] > 0) { + const b = B[i][j]; + if (b === 1) { + if (sameToken(q[i - 1], w[from + j - 1].t)) pairs.push([i - 1, from + j - 1]); + i -= 1; + j -= 1; + } else if (b === 2) i -= 1; + else if (b === 3) j -= 1; + else break; + } + pairs.reverse(); + return { pairs, score: best }; +} + +/** + * Find a clip's quote in timed words (CUE clock). + * + * @param {string} quote + * @param {{ w?: string, text?: string, start: number, end: number }[]} words + * @param {{ expectedStart?: number | null, expectedEnd?: number | null, minMatch?: number }} [opts] + * `expectedStart`/`expectedEnd`: where the clip says the quote is (its + * quoteStart/quoteEnd, else its cut, else its extent) — the offset is + * measured from there. + * @returns {{ + * found: boolean, match: number, tokens: number, matched: number, + * from: number | null, to: number | null, offset: number | null, + * fragments: { text: string, match: number, from: number | null, to: number | null }[], + * pairs: { q: number, start: number, end: number, anchor?: boolean }[], + * heard: string, + * }} + * `pairs`: each matched quote token (its index in the whole quote) and the + * seconds it was heard at — what quoteOffset compares two findings by. + */ +export function findQuote(quote, words, { expectedStart = null, expectedEnd = null, minMatch = MIN_MATCH } = {}) { + const w = timedTokens(words); + const frags = String(quote ?? "") + .split(/\.{3}|…/) + .map((f) => f.trim()) + .filter((f) => quoteTokens(f).length); + const total = frags.reduce((n, f) => n + quoteTokens(f).length, 0); + const fragments = []; + const timed = []; + let after = 0; + let matched = 0; + let first = null; + let firstQ = 0; + let last = null; + let base = 0; + for (const f of frags) { + const q = quoteTokens(f); + const { pairs } = alignLocal(q, w, after); + const share = q.length ? pairs.length / q.length : 0; + for (const [qi, wi] of pairs) { + timed.push({ q: base + qi, start: w[wi].start, end: w[wi].end, ...(w[wi].anchor ? { anchor: true } : {}) }); + } + base += q.length; + if (!pairs.length) { + fragments.push({ text: f, match: 0, from: null, to: null }); + continue; + } + matched += pairs.length; + const a = w[pairs[0][1]]; + const b = w[pairs[pairs.length - 1][1]]; + fragments.push({ text: f, match: round2(share), from: a.start, to: b.end }); + if (first === null) { + first = a; + // How far into the whole quote the first matched token is. + firstQ = fragments.length === 1 ? pairs[0][0] : 0; + } + last = b; + after = pairs[pairs.length - 1][1] + 1; + } + const share = total ? matched / total : 0; + // Short quotes (under four tokens) must match whole. + const need = total < 4 ? 1 : minMatch; + const found = share >= need && first !== null; + let offset = null; + if (found && Number.isFinite(expectedStart)) { + // The expected second of the first MATCHED token: the quote's own span, + // shared out by token, when the clip says where it ends too. + const span = Number.isFinite(expectedEnd) && expectedEnd > expectedStart ? expectedEnd - expectedStart : 0; + const at = expectedStart + (total ? (span * firstQ) / total : 0); + offset = round2(first.start - at); + } + const heard = w + .filter((x) => found && x.start >= (first?.start ?? 0) - 0.01 && x.end <= (last?.end ?? 0) + 0.01) + .map((x) => x.t) + .join(" "); + return { + found, + match: round2(share), + tokens: total, + matched, + from: found ? first.start : null, + to: found ? last.end : null, + offset, + fragments, + pairs: found ? timed : [], + heard, + }; +} + +/** + * How far the quote was HEARD from where the CUES have it: the median, over the + * quote's tokens both found, of heard − cued. Null when they share none. + * @param {{ pairs: { q: number, start: number }[] }} heard + * @param {{ pairs: { q: number, start: number }[] }} cued + */ +export function quoteOffset(heard, cued) { + // A cue's FIRST word is timed exactly (the cue starts on it); the words after + // it are spread over the cue and can be seconds off where the speaker paused + // inside one. The exact ones decide when the quote shares any. + const exact = cued.pairs.filter((p) => p.anchor); + const use = heard.pairs.some((h) => exact.some((c) => c.q === h.q)) ? exact : cued.pairs; + const at = new Map(use.map((p) => [p.q, p.start])); + const d = heard.pairs.filter((p) => at.has(p.q)).map((p) => p.start - /** @type {number} */ (at.get(p.q))); + if (!d.length) return null; + d.sort((a, b) => a - b); + const mid = d.length >> 1; + return round2(d.length % 2 ? d[mid] : (d[mid - 1] + d[mid]) / 2); +} + +/** + * Cues as timed words: each cue's words spread over its span by their length + * (a cue carries no word timings; this is good to a fraction of a second, and + * the offsets that matter are seconds). + * @param {{ start: number, end: number, text: string }[]} cues + * @param {{ from?: number, to?: number }} [span] only the cues overlapping it + * @returns {{ w: string, start: number, end: number, anchor?: boolean }[]} `anchor`: a + * cue's first word, timed exactly + */ +export function cueWords(cues, { from = -Infinity, to = Infinity } = {}) { + const out = []; + for (const c of cues ?? []) { + const s = Number(c.start); + const e = Number(c.end); + if (!(e >= from && s <= to)) continue; + const ws = String(c.text ?? "").split(/\s+/).filter(Boolean); + const total = ws.reduce((n, x) => n + x.length + 1, 0); + let at = s; + ws.forEach((x, k) => { + const d = total ? ((e - s) * (x.length + 1)) / total : 0; + out.push({ w: x, start: round2(at), end: round2(at + d), ...(k === 0 ? { anchor: true } : {}) }); + at += d; + }); + } + return out; +} + +const round2 = (x) => Math.round(x * 100) / 100; + +/** + * The verdict for a found (or not) quote: `ok` within ON_TIME_S of the cue + * clock, `moved` further, `not-found`. + * @param {ReturnType<typeof findQuote>} r + */ +export function quoteStatus(r, onTime = ON_TIME_S) { + if (!r.found) return "not-found"; + if (r.offset !== null && Math.abs(r.offset) > onTime) return "moved"; + return "ok"; +} diff --git a/umtool/report-to-video/quote-in-audio.test.mjs b/umtool/report-to-video/quote-in-audio.test.mjs @@ -0,0 +1,94 @@ +// quote-in-audio.mjs (lane one-clock): numbers however written, fragments in +// order, and the offsets the rev9-a3 pass measured by ear and by hand — from +// the parakeet words of the windows that were fetched on 6 Nov and the cues +// they were cut by (fixtures/rev9-a3-rumble-words.json). +// +// Run with: pnpm test:scripts +import assert from "node:assert/strict"; +import test from "node:test"; +import { readFileSync } from "node:fs"; +import { fileURLToPath } from "node:url"; +import path from "node:path"; +import { + cueWords, + findQuote, + foldNumbers, + quoteOffset, + quoteStatus, + quoteTokens, + rawTokens, + sameToken, +} from "./quote-in-audio.mjs"; + +const FIX = JSON.parse( + readFileSync(path.join(path.dirname(fileURLToPath(import.meta.url)), "fixtures", "rev9-a3-rumble-words.json"), "utf8"), +); + +test("numbers are one token however they are written", () => { + assert.deepEqual(quoteTokens("thirty eight point five pounds"), ["38.5", "pounds"]); + assert.deepEqual(quoteTokens("I'm down to 310.5"), ["im", "down", "to", "310.5"]); + assert.deepEqual(quoteTokens("three hundred ten point five"), ["310.5"]); + assert.deepEqual(quoteTokens("a hundred and ten"), ["110"]); + assert.deepEqual(quoteTokens("lose about one hundred pounds"), ["lose", "about", "100", "pounds"]); + assert.deepEqual(quoteTokens("1,000 [sic] people, 17%"), ["1000", "people", "17", "percent"]); + assert.deepEqual(quoteTokens("fifty point one pounds in eleven weeks"), ["50.1", "pounds", "in", "11", "weeks"]); + // "twenty twenty one" is two numbers, not 41. + assert.deepEqual(quoteTokens("twenty twenty one"), ["20", "21"]); + assert.deepEqual(foldNumbers(rawTokens("down twenty now")), [ + { t: "down", from: 0, to: 0 }, + { t: "20", from: 1, to: 1 }, + { t: "now", from: 2, to: 2 }, + ]); + assert.equal(sameToken("40", "40.0"), true); + assert.equal(sameToken("weighed", "weighd"), true); + assert.equal(sameToken("weighed", "waited"), false); +}); + +const words = (list, t0 = 0) => + list.split(" ").map((w, i) => ({ w, start: t0 + i * 0.4, end: t0 + i * 0.4 + 0.3 })); + +test("a quote with its numbers mangled both ways is found where it was said", () => { + const heard = words("so total loss now is thirty eight point five pounds I started at three hundred forty nine I'm down to three hundred ten point five my goal", 100); + const r = findQuote("total loss now is 38.5 pounds, started at 349, I'm down to 310.5", heard, { expectedStart: 100.4 }); + assert.equal(r.found, true); + assert.equal(r.match >= 0.9, true, String(r.match)); + assert.equal(r.from, 100.4); + assert.equal(r.offset, 0); + assert.equal(quoteStatus(r), "ok"); +}); + +test("an ellipsis: fragments found in order; a quote that is not there is not found", () => { + const heard = words("I have begun what is commonly referred to as dry January which only about 17 percent of people can complete I've also begun intermittent fasting today", 10); + const r = findQuote("I have begun what is commonly referred to as dry January... I've also begun intermittent fasting today.", heard); + assert.equal(r.found, true); + assert.equal(r.fragments.length, 2); + assert.ok(r.fragments.every((f) => f.match === 1)); + const miss = findQuote("I promise you, by this time next year I will be down 100 pounds", heard); + assert.equal(miss.found, false); + assert.equal(quoteStatus(miss), "not-found"); + // Short quotes match whole or not at all. + assert.equal(findQuote("dry February", heard).found, false); +}); + +test("cue words: a cue's words spread over it, its first word exact", () => { + const w = cueWords([{ start: 10, end: 12, text: "a bb ccc" }, { start: 20, end: 21, text: "x" }], { from: 0, to: 15 }); + assert.deepEqual(w.map((x) => [x.w, x.start, x.anchor ?? false]), [["a", 10, true], ["bb", 10.44, false], ["ccc", 11.11, false]]); +}); + +// THE 6 NOV WINDOWS. Heard = the window's words on the cue clock (window start +// + the file's seconds); cued = the same quote found in the cues. The editing +// agent's offsets: c43 +13.1, c45 +13.6, c20 +5.2, k46 -0.7, c44 0. +const EXPECTED = { c43: [13.1, 0.15], c45: [13.6, 0.15], c20: [5.2, 0.5], k46: [-0.7, 0.3], c44: [0, 0.15] }; + +for (const clip of FIX.clips) { + test(`rev9-a3 ${clip.id} (${clip.channel}/${clip.video}): the quote is heard ${EXPECTED[clip.id][0]} s from its cues`, () => { + const [from, to] = clip.window; + const heard = findQuote(clip.quote, clip.words.map((w) => ({ ...w, start: w.start + from, end: w.end + from }))); + const cued = findQuote(clip.quote, cueWords(clip.cues, { from: from - 30, to: to + 30 })); + assert.equal(heard.found, true, `heard ${heard.match}`); + assert.equal(cued.found, true, `cued ${cued.match}`); + const off = quoteOffset(heard, cued); + const [want, tol] = EXPECTED[clip.id]; + assert.ok(Math.abs(off - want) <= tol, `${clip.id}: ${off} vs ${want}`); + }); +}