SpeakersPanel

Panel that lists all speakers in the active project, allowing the user to rename them, change their color, attach a voice sample, and delete them. Communicates back to the workspace via onSpeakerHover and onSpeakerModified callbacks.

Constructor

new SpeakersPanel(workspace, callbacks)

Parameters:
NameTypeDescription
workspaceobjectthe Workspace controller instance
callbacksobjectcallback functions for speaker interactions
Properties
NameTypeDescription
onSpeakerHoverfunctioncalled with speaker id when a speaker is hovered
onSpeakerModifiedfunctioncalled with speaker when a speaker is modified

Classes

SpeakersPanel

Methods

addSpeaker(speakerIdopt)

Adds a new speaker with an auto-generated unique id (SPEAKER_N where N avoids collisions). Immediately focuses the new name span so the user can type a custom name right away.
Parameters:
NameTypeAttributesDefaultDescription
speakerIdstring | null<optional>
nullexplicit id to assign; auto-generated if null

buildSpeakerRow(speaker)

Builds a table row for a speaker and appends it to the speakers table body.
Parameters:
NameTypeDescription
speakerobjectspeaker object with id, name, hue, and sample

buildSpeakerSampleCell(speaker) → {HTMLTableCellElement}

Builds the sample cell for a speaker row. If a sample exists it shows the waveform with play/remove controls; otherwise it shows upload/record/segment buttons.
Parameters:
NameTypeDescription
speakerobjectthe speaker object to build the cell for
Returns:
Type: 
HTMLTableCellElement

clearSpeakersPanel()

Clears the panel by re-rendering with no active project.

closeHuePicker()

Closes and removes the active hue picker if one is open.

(async) decodeSampleBuffer(arrayBuffer) → {Promise.<{audioBuffer: AudioBuffer, peaks: Array.<number>}>}

Decodes an audio ArrayBuffer and extracts 120 peak bars for the mini waveform visualization.
Parameters:
NameTypeDescription
arrayBufferArrayBufferraw audio data to decode
Returns:
Type: 
Promise.<{audioBuffer: AudioBuffer, peaks: Array.<number>}>

deleteSpeaker(id)

Deletes a speaker. If any transcript segments are assigned to this speaker, shows a reassignment modal prompting the user to pick another speaker before deletion. If no segments are affected, shows a simpler confirmation modal. Prevents deletion when only one speaker exists.
Parameters:
NameTypeDescription
idstringspeaker id to remove

drawSampleWaveform(canvas, peaks, progressopt, coloropt)

Renders waveform peak bars into a canvas element. Bars to the left of `progress` are drawn at full opacity (played), bars to the right at reduced opacity (unplayed).
Parameters:
NameTypeAttributesDefaultDescription
canvasHTMLCanvasElementtarget canvas element to draw into
peaksArray.<number>array of 0..1 amplitude values
progressnumber<optional>
0playback fraction 0..1
colorstring<optional>
'#47c8ff'hex color for the bars

loadFromProject(project)

Loads speaker data from the given project and renders the panel.
Parameters:
NameTypeDescription
projectProjectthe project to load speaker data from

makeSpeakerEditable(spanEl, speaker)

Replaces a speaker name span with a text input for inline editing. Commits on Enter or blur; cancels (restores span) on Escape.
Parameters:
NameTypeDescription
spanElHTMLElementthe .speaker-name span to replace
speakerobjectthe speaker object being renamed

makeSpeakerNameSpan(speaker) → {HTMLElement}

Creates a styled, clickable speaker name span. Clicking it enters inline edit mode; hovering it highlights that speaker's regions on the waveform.
Parameters:
NameTypeDescription
speakerobject | stringthe speaker object, or a speaker id string to look up
Returns:
Type: 
HTMLElement

openHuePicker(speaker, swatchEl)

Opens a hue picker popover anchored below `swatchEl`.
Parameters:
NameTypeDescription
speakerobjectthe speaker object whose hue should be changed
swatchElHTMLElementthe color swatch that was clicked

openSampleUpload(id)

Opens a hidden file input dialog for uploading a voice sample. On selection, decodes the audio and stores it via setSpeakerSample.
Parameters:
NameTypeDescription
idstringspeaker id

openSegPicker(speaker)

Opens the segment picker modal, showing all transcript segments. Clicking a row slices that segment's audio as the speaker's voice sample. If the selected segment belongs to a different speaker, a confirmation dialog is shown first.
Parameters:
NameTypeDescription
speakerobjectthe speaker object for whom the sample will be set

playSampleAudio(speaker, playBtn, canvas, peaks, progressLine)

Plays a speaker voice sample using the Web Audio API and animates a progress line over the mini waveform. Clicking the play button a second time stops playback early.
Parameters:
NameTypeDescription
speakerobjectthe speaker object whose sample will be played
playBtnHTMLButtonElementthe play/stop button element
canvasHTMLCanvasElementwaveform canvas to animate during playback
peaksArray.<number>120-bar peak array for waveform display
progressLineHTMLElementthin overlay element showing play position

removeSpeakerSample(id)

Removes a speaker's voice sample and revokes its blob URL.
Parameters:
NameTypeDescription
idstringspeaker id

renameSpeaker(speaker, newName)

Renames a speaker: updates liveNameMap, marks the transcript dirty, and live-patches all in-DOM speaker name spans so the page doesn't need a full re-render.
Parameters:
NameTypeDescription
speakerobjectthe speaker object to rename
newNamestringdesired display name; reset to id if blank

renderSpeakersPanel()

Re-renders the speakers table from the active project's speaker data.

setSpeakerSample(id, audioBuffer, blobUrl, peaks)

Stores a decoded speaker sample in state. Revokes any previously stored blob URL to avoid memory leaks, then re-renders the speakers panel.
Parameters:
NameTypeDescription
idstringspeaker id
audioBufferAudioBufferthe decoded audio buffer
blobUrlstring | nullblob URL for re-upload to server, or null if not needed
peaksArray.<number>120-bar peak array for waveform display

(async) sliceSegmentAsSample(id, seg)

Extracts the audio for a single transcript segment from the main track and stores it as a speaker voice sample. Uses the full decoded audio buffer to avoid re-fetching; slices by sample index rather than time. Only channel 0 is used (mono sample).
Parameters:
NameTypeDescription
idstringspeaker id
segObjectsegment with start/end in seconds

speakerDisplayName(id) → {string}

Returns the user-facing display name for a speaker, falling back to the raw CSV id if no rename has been applied.
Parameters:
NameTypeDescription
idstringspeaker id to look up
Returns:
Type: 
string

startRecording(id, btn)

Starts microphone recording for a speaker voice sample (or stops if already recording). Auto-stops after 20 seconds. On stop, encodes to a Blob and stores via setSpeakerSample.
Parameters:
NameTypeDescription
idstringspeaker id
btnHTMLButtonElementthe ⏺ Rec button; its text is toggled