Skip to content

Speakr is a personal, self-hosted web application designed for transcribing audio recordings

Python

Transcript editor: every speaker can be chosen for a segment (#425)

Murtaza Nasirdab1270a508c
diff --git a/static/js/modules/composables/transcription.js b/static/js/modules/composables/transcription.js
index e69ff415..9c01d2f0 100644
--- a/static/js/modules/composables/transcription.js
+++ b/static/js/modules/composables/transcription.js
@@ -287,12 +287,20 @@ export function useTranscription(state, utils) {
}
};
- // O(1) dropdown management using single ref instead of O(n) forEach
- const openSpeakerSuggestions = (index) => {
- if (editingSegments.value[index]) {
+ // O(1) dropdown management using single ref instead of O(n) forEach.
+ // Opening the list (focus, chevron) shows every speaker; the list is
+ // filtered only while the name is being typed. Filtering by the name
+ // already in the field left only that speaker to choose (#425).
+ const openSpeakerSuggestions = (index, { filter = false } = {}) => {
+ const segment = editingSegments.value[index];
+ if (segment) {
// Simply set the open index - O(1) instead of O(n) forEach
openAsrDropdownIndex.value = index;
- filterSpeakerSuggestions(index);
+ if (filter) {
+ filterSpeakerSuggestions(index);
+ } else {
+ segment.filteredSpeakers = [...availableSpeakers.value];
+ }
updateDropdownPosition(index);
}
};
@@ -387,7 +395,10 @@ export function useTranscription(state, utils) {
});
};
- const selectSpeaker = (index, speaker) => {
+ // Not selectSpeaker: the Identify Speakers dialog exports that name, and
+ // as the later composable in the app it replaced this one, so choosing a
+ // name in the editor did nothing (#425).
+ const selectSegmentSpeaker = (index, speaker) => {
if (editingSegments.value[index]) {
editingSegments.value[index].speaker = speaker;
closeSpeakerSuggestions(index);
@@ -609,7 +620,7 @@ export function useTranscription(state, utils) {
isDropdownOpen,
getDropdownPosition,
updateDropdownPosition,
- selectSpeaker,
+ selectSegmentSpeaker,
addSegment,
removeSegment,
addSegmentBelow,
diff --git a/static/js/modules/composables/transcription.test.js b/static/js/modules/composables/transcription.test.js
new file mode 100644
index 00000000..f4eac745
--- /dev/null
+++ b/static/js/modules/composables/transcription.test.js
@@ -0,0 +1,45 @@
+import { describe, expect, it } from 'vitest';
+
+import { useTranscription } from './transcription.js';
+
+const ref = (value) => ({ value });
+
+// #425: a segment assigned to SPEAKER_02 offered only SPEAKER_02, because the
+// list was filtered by the name already in the field when it opened.
+function editor() {
+ const state = {
+ editingSegments: ref([
+ { speaker: 'SPEAKER_02', text: 'Yellow' },
+ { speaker: 'SPEAKER_01', text: 'Purple' },
+ ]),
+ availableSpeakers: ref(['SPEAKER_01', 'SPEAKER_02']),
+ openAsrDropdownIndex: ref(null),
+ dropdownPositions: ref({}),
+ };
+ const api = useTranscription(state, { showToast() {}, setGlobalError() {}, nextTick() {} });
+ return { state, api };
+}
+
+describe('speaker list in the transcript editor', () => {
+ it('lists every speaker when it is opened', () => {
+ const { state, api } = editor();
+ api.openSpeakerSuggestions(0);
+ expect(state.openAsrDropdownIndex.value).toBe(0);
+ expect(state.editingSegments.value[0].filteredSpeakers).toEqual(['SPEAKER_01', 'SPEAKER_02']);
+ });
+
+ it('filters the list while a name is typed', () => {
+ const { state, api } = editor();
+ state.editingSegments.value[0].speaker = '01';
+ api.openSpeakerSuggestions(0, { filter: true });
+ expect(state.editingSegments.value[0].filteredSpeakers).toEqual(['SPEAKER_01']);
+ });
+
+ it('assigns the chosen speaker to the segment', () => {
+ const { state, api } = editor();
+ api.openSpeakerSuggestions(0);
+ api.selectSegmentSpeaker(0, 'SPEAKER_01');
+ expect(state.editingSegments.value[0].speaker).toBe('SPEAKER_01');
+ expect(state.openAsrDropdownIndex.value).toBe(null);
+ });
+});
diff --git a/templates/modals/asr-editor-modal.html b/templates/modals/asr-editor-modal.html
index b1a4e0ce..a77691b4 100644
--- a/templates/modals/asr-editor-modal.html
+++ b/templates/modals/asr-editor-modal.html
@@ -103,8 +103,9 @@
<div class="relative h-full">
<div class="flex items-center h-full">
<input type="text" v-model="editingSegments[segment._originalIndex].speaker"
- @input="filterSpeakerSuggestions(segment._originalIndex); openSpeakerSuggestions(segment._originalIndex)"
+ @input="openSpeakerSuggestions(segment._originalIndex, { filter: true })"
@focus="openSpeakerSuggestions(segment._originalIndex)"
+ @click.stop="openSpeakerSuggestions(segment._originalIndex)"
class="w-full h-full px-3 py-2.5 pr-7 bg-transparent border-0 focus:outline-none text-sm text-[var(--text-primary)]" />
<button type="button" @click.stop="openSpeakerSuggestions(segment._originalIndex)"
class="absolute right-2 top-1/2 -translate-y-1/2 p-1 text-[var(--text-muted)] hover:text-[var(--text-primary)] cursor-pointer">
@@ -116,7 +117,7 @@
<div v-if="isDropdownOpen(segment._originalIndex)"
class="fixed z-[100] w-40 bg-[var(--bg-secondary)] border border-[var(--border-primary)] rounded-md shadow-lg max-h-48 overflow-y-auto"
:style="getDropdownPosition(segment._originalIndex)">
- <div v-for="speaker in editingSegments[segment._originalIndex].filteredSpeakers" :key="speaker" @mousedown.prevent="selectSpeaker(segment._originalIndex, speaker)" class="px-3 py-2 cursor-pointer hover:bg-[var(--bg-tertiary)] text-sm">${speaker}</div>
+ <div v-for="speaker in editingSegments[segment._originalIndex].filteredSpeakers" :key="speaker" @mousedown.prevent="selectSegmentSpeaker(segment._originalIndex, speaker)" class="px-3 py-2 cursor-pointer hover:bg-[var(--bg-tertiary)] text-sm">${speaker}</div>
<div @mousedown.prevent="openEditSpeakersModal" class="px-3 py-2 cursor-pointer hover:bg-[var(--bg-accent)] text-sm text-[var(--text-accent)] border-t border-[var(--border-primary)] flex items-center">
<i class="fas fa-user-edit mr-2"></i> <span v-text="t('buttons.editSpeakers')"></span>
</div>