How to align a transcript to what is on screen
Ask for the transcript with words set to true and every word carries a start and an end. Then ask what was on screen at that second, carrying the session_id, and the two are lined up by the same clock.
Last updated
The call
Copy this as it stands. “What was on screen while they said the price?” is the question it answers.
const { segments } = await playhead.transcript({ url, words: true });
const price = segments
.flatMap((s) => s.words ?? [])
.find((w) => /\$\d/.test(w.word));
if (price) {
const frame = await playhead.watch({
url,
window: { from: price.start, to: price.start + 1 },
question: "what is on screen here",
});
console.log(`"${price.word}" at ${price.start}s:`, frame.answer);
}curl -X POST https://api.tryplayhead.com/v1/transcript \
-H "Authorization: Bearer $PLAYHEAD_API_KEY" \
-H "Content-Type: application/json" \
-d '{"url": "…", "words": true}' | jq '.segments[0].words'Watch out for
Everything the API can refuse, and what to send instead, is on the errors page.