Read an episode’s transcript lines in an admin screen
Your admin screen wants an episode’s transcript with its timestamps, to pick a quote or a clip, say. Read it through the route the episode editor’s Transcript tab uses, never the table.
- It needs
manage_optionsand Transcription switched on for that show (403 benecaster_transcription_not_activeotherwise), and it ignores transcript visibility: show its text only to people who can edit the episode. - A plain-text import has
timed: false, nolines, and its text intext. - For plain text on the server side,
benecaster_get_episode_transcript_text()is simpler, and returnsnullfor Hidden.
Code
const url = `${ window.wpApiSettings.root }benecaster-transcription/v1/shows/${ showId }/episodes/${ episodeId }/transcript`;
const response = await fetch( url, { headers: { 'X-WP-Nonce': window.benecasterAdmin.nonce } } );
const { transcript } = await response.json(); // null until the transcript is complete
if ( transcript?.timed ) {
for ( const line of transcript.lines ) {
// line = { index, start, end, speaker, text }; start and end in seconds.
}
}
Need this built rather than just documented? See our services →