Skip to main content

Read an episode’s transcript lines in an admin screen

Premium Intermediate

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_options and Transcription switched on for that show (403 benecaster_transcription_not_active otherwise), and it ignores transcript visibility: show its text only to people who can edit the episode.
  • A plain-text import has timed: false, no lines, and its text in text.
  • For plain text on the server side, benecaster_get_episode_transcript_text() is simpler, and returns null for 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.
    }
}

View on GitHub →

Need this built rather than just documented? See our services →