Speakr is a personal, self-hosted web application designed for transcribing audio recordings
Python
feat: recording chat cites transcript timestamps as clickable seek chips - prompt instructs bracketed timestamps when the user's timestamp setting is on, and the chat renderer turns them into pills that start playback at that moment (no numbering or sources list; single recording in view)
Murtaza Nasir9c3b02f2f762
diff --git a/src/api/recordings.py b/src/api/recordings.pyindex ba56dd24..b6671f43 100644--- a/src/api/recordings.py+++ b/src/api/recordings.py@@ -3281,8 +3281,21 @@ def chat_incognito():else:chat_transcript = formatted_transcription[:transcript_limit]- system_prompt = f"""You are a professional meeting and audio transcription analyst assisting {user_name}, who is a(n) {user_title} at {user_company}. {language_instruction} Analyze the following meeting information and respond to the specific request.+ # When timestamps are in the transcript, ask the model to cite them so+ # the chat panel can render clickable seek chips (bracketed [h:mm:ss]).+ timestamp_instruction = ""+ if _chat_ts:+ timestamp_instruction = (+ "\nWhen you reference a specific moment in the recording, cite its "+ "timestamp in square brackets exactly as it appears in the transcript "+ "(for example [00:07:35]). The interface renders these as clickable "+ "links that start playback at that moment, so cite them wherever they "+ "support your answer. Never invent a timestamp that is not in the "+ "transcript.\n"+ )+ system_prompt = f"""You are a professional meeting and audio transcription analyst assisting {user_name}, who is a(n) {user_title} at {user_company}. {language_instruction} Analyze the following meeting information and respond to the specific request.+{timestamp_instruction}Following are the meeting participants and their roles:{participants or "No specific participants information provided."}@@ -4017,8 +4030,21 @@ def chat_with_transcription():else:chat_transcript = formatted_transcription[:transcript_limit]- system_prompt = f"""You are a professional meeting and audio transcription analyst assisting {user_name}, who is a(n) {user_title} at {user_company}. {language_instruction} Analyze the following meeting information and respond to the specific request.+ # When timestamps are in the transcript, ask the model to cite them so+ # the chat panel can render clickable seek chips (bracketed [h:mm:ss]).+ timestamp_instruction = ""+ if _chat_ts:+ timestamp_instruction = (+ "\nWhen you reference a specific moment in the recording, cite its "+ "timestamp in square brackets exactly as it appears in the transcript "+ "(for example [00:07:35]). The interface renders these as clickable "+ "links that start playback at that moment, so cite them wherever they "+ "support your answer. Never invent a timestamp that is not in the "+ "transcript.\n"+ )+ system_prompt = f"""You are a professional meeting and audio transcription analyst assisting {user_name}, who is a(n) {user_title} at {user_company}. {language_instruction} Analyze the following meeting information and respond to the specific request.+{timestamp_instruction}Following are the meeting participants and their roles:{recording.participants or "No specific participants information provided."}diff --git a/static/css/styles.css b/static/css/styles.cssindex 596b713e..95eafee5 100644--- a/static/css/styles.css+++ b/static/css/styles.css@@ -4652,3 +4652,32 @@ select:disabled {.recording-row {position: relative;}++/* Chat timestamp chips: the recording chat cites moments as bracketed+ transcript timestamps; they render as clickable pills (same visual+ language as Inquire citation chips) that seek the in-view player. */+.chat-ts-chip {+ display: inline-block;+ background-color: var(--bg-accent);+ color: var(--text-accent);+ border: 1px solid var(--border-accent, var(--border-secondary));+ border-radius: 9999px;+ padding: 0 0.55em;+ font-size: 0.78em;+ line-height: 1.55;+ font-family: inherit;+ cursor: pointer;+ /* Centre the pill against the surrounding text line (see the+ matching Inquire chip rule for the rationale). */+ vertical-align: -0.35em;+ margin: 0 0.1em;+ white-space: nowrap;+}+.chat-ts-chip::before {+ content: "\25B8"; /* small play triangle */+ margin-right: 0.3em;+ font-size: 0.9em;+}+.chat-ts-chip:hover {+ border-color: var(--border-focus);+}diff --git a/static/js/modules/composables/chat.js b/static/js/modules/composables/chat.jsindex 2196a97d..c6f81455 100644--- a/static/js/modules/composables/chat.js+++ b/static/js/modules/composables/chat.js@@ -13,6 +13,89 @@ export function useChat(state, utils) {const { showToast, setGlobalError, onChatComplete, t } = utils;+ // ------------------------------------------------------------------+ // Timestamp chips: the chat prompt asks the model to cite moments as+ // bracketed transcript timestamps ([00:07:35]); render them as+ // clickable chips that seek the in-view recording's player. Unlike+ // Inquire citations there is no numbering or Sources list — chat is+ // always about the single recording in view.+ // ------------------------------------------------------------------++ const CHAT_TS_RE = /\[(\d{1,2}):(\d{2})(?::(\d{2}))?\]/g;++ const formatChatSeconds = (s) => {+ const h = Math.floor(s / 3600), m = Math.floor((s % 3600) / 60), sec = s % 60;+ return h > 0+ ? h + ':' + String(m).padStart(2, '0') + ':' + String(sec).padStart(2, '0')+ : m + ':' + String(sec).padStart(2, '0');+ };++ /** Replace [h:mm:ss] / [m:ss] in sanitized chat HTML with seek chips. */+ const decorateChatTimestamps = (html) => {+ if (!html || !/\[\d/.test(html)) return html;+ try {+ const tpl = document.createElement('template');+ tpl.innerHTML = html;+ const walker = document.createTreeWalker(tpl.content, NodeFilter.SHOW_TEXT, {+ acceptNode: (node) =>+ node.parentElement && node.parentElement.closest('code, pre, a')+ ? NodeFilter.FILTER_REJECT : NodeFilter.FILTER_ACCEPT,+ });+ const targets = [];+ let n;+ while ((n = walker.nextNode())) {+ if (CHAT_TS_RE.test(n.nodeValue)) targets.push(n);+ CHAT_TS_RE.lastIndex = 0;+ }+ for (const node of targets) {+ const frag = document.createDocumentFragment();+ let last = 0;+ const text = node.nodeValue;+ for (const m of text.matchAll(CHAT_TS_RE)) {+ // [a:b] is m:ss; [a:b:c] is h:mm:ss+ const seconds = m[3] !== undefined+ ? (+m[1]) * 3600 + (+m[2]) * 60 + (+m[3])+ : (+m[1]) * 60 + (+m[2]);+ frag.appendChild(document.createTextNode(text.slice(last, m.index)));+ const chip = document.createElement('button');+ chip.type = 'button';+ chip.className = 'chat-ts-chip';+ chip.dataset.seek = String(seconds);+ chip.title = t('chat.playFromHere') || 'Play from here';+ chip.textContent = formatChatSeconds(seconds);+ frag.appendChild(chip);+ last = m.index + m[0].length;+ }+ frag.appendChild(document.createTextNode(text.slice(last)));+ node.parentNode.replaceChild(frag, node);+ }+ return tpl.innerHTML;+ } catch (_) {+ return html;+ }+ };++ const renderChatHtml = (content) => decorateChatTimestamps(window.renderMarkdownSafe(content));++ /** Delegated click handler for the chat messages containers. */+ const handleChatBubbleClick = (event) => {+ const chip = event.target.closest && event.target.closest('.chat-ts-chip');+ if (!chip) return;+ const seconds = parseInt(chip.dataset.seek, 10);+ if (!isFinite(seconds)) return;+ // The detail view's player streams from /audio/; incognito uses a+ // blob URL, so fall back to any media element on the page.+ const all = [...document.querySelectorAll('audio, video')];+ const media = all.find((el) => ((el.currentSrc || el.src || '').includes('/audio/')))+ || all.find((el) => (el.currentSrc || el.src));+ if (!media) return;+ const target = isFinite(media.duration)+ ? Math.min(seconds, Math.max(0, media.duration - 1))+ : seconds;+ media.currentTime = target;+ media.play().catch(() => {});+ };+// Helper function to check if chat is scrolled to bottom (within bottom 5%)const isChatScrolledToBottom = () => {if (!chatMessagesRef.value) return true;@@ -184,7 +267,7 @@ export function useChat(state, utils) {}assistantMessage.content += textContent;- assistantMessage.html = window.renderMarkdownSafe(assistantMessage.content);+ assistantMessage.html = renderChatHtml(assistantMessage.content);if (shouldScroll) {await Vue.nextTick();@@ -197,7 +280,7 @@ export function useChat(state, utils) {// instead of presenting it as complete (issue #349).if (data.truncated && assistantMessage && assistantMessage.content) {assistantMessage.content += `\n\n_⚠️ ${t('chat.responseTruncated')}_`;- assistantMessage.html = window.renderMarkdownSafe(assistantMessage.content);+ assistantMessage.html = renderChatHtml(assistantMessage.content);}return;}@@ -230,7 +313,7 @@ export function useChat(state, utils) {const errSuffix = `\n\n_⚠️ Connection ended before the response completed: ${error.message}_`;if (partial) {assistantMessage.content = partial + errSuffix;- assistantMessage.html = window.renderMarkdownSafe(assistantMessage.content);+ assistantMessage.html = renderChatHtml(assistantMessage.content);} else {assistantMessage.content = `Error: ${error.message}`;assistantMessage.html = `<span class="text-red-500">Error: ${error.message}</span>`;@@ -377,6 +460,7 @@ export function useChat(state, utils) {return {isChatScrolledToBottom,scrollChatToBottom,+ handleChatBubbleClick,toggleChatMaximize,sendChatMessage,handleChatKeydown,diff --git a/static/locales/de.json b/static/locales/de.jsonindex 7155ad6a..917bcbd1 100644--- a/static/locales/de.json+++ b/static/locales/de.json@@ -425,7 +425,8 @@"whatAreActionItems": "Was sind die Aktionspunkte?","whatAreKeyPoints": "Was sind die wichtigsten Punkte?","whatWasDiscussed": "Was wurde besprochen?",- "whoSaidWhat": "Wer hat was gesagt?"+ "whoSaidWhat": "Wer hat was gesagt?",+ "playFromHere": "Ab hier abspielen"},"colorScheme": {"chooseRecording": "Wählen Sie eine Aufnahme aus der Seitenleiste, um ihre Transkription und Zusammenfassung zu sehen",diff --git a/static/locales/en.json b/static/locales/en.jsonindex ce3d4fab..9f493602 100644--- a/static/locales/en.json+++ b/static/locales/en.json@@ -425,7 +425,8 @@"whatAreActionItems": "What are the action items?","whatAreKeyPoints": "What are the key points?","whatWasDiscussed": "What was discussed?",- "whoSaidWhat": "Who said what?"+ "whoSaidWhat": "Who said what?",+ "playFromHere": "Play from here"},"colorScheme": {"chooseRecording": "Choose a recording from the sidebar to view its transcription and summary",diff --git a/static/locales/es.json b/static/locales/es.jsonindex f3c60dbc..c98787b3 100644--- a/static/locales/es.json+++ b/static/locales/es.json@@ -425,7 +425,8 @@"whatAreActionItems": "¿Cuáles son los elementos de acción?","whatAreKeyPoints": "¿Cuáles son los puntos clave?","whatWasDiscussed": "¿Qué se discutió?",- "whoSaidWhat": "¿Quién dijo qué?"+ "whoSaidWhat": "¿Quién dijo qué?",+ "playFromHere": "Reproducir desde aquí"},"colorScheme": {"chooseRecording": "Elige una grabación de la barra lateral para ver su transcripción y resumen",diff --git a/static/locales/fr.json b/static/locales/fr.jsonindex 891f9cac..04eb2573 100644--- a/static/locales/fr.json+++ b/static/locales/fr.json@@ -425,7 +425,8 @@"whatAreActionItems": "Quelles sont les actions à mener?","whatAreKeyPoints": "Quels sont les points clés?","whatWasDiscussed": "Qu'est-ce qui a été discuté?",- "whoSaidWhat": "Qui a dit quoi?"+ "whoSaidWhat": "Qui a dit quoi?",+ "playFromHere": "Lire à partir d'ici"},"colorScheme": {"chooseRecording": "Choisissez un enregistrement dans la barre latérale pour voir sa transcription et son résumé",diff --git a/static/locales/pt-BR.json b/static/locales/pt-BR.jsonindex f762e0ae..b39b9a23 100644--- a/static/locales/pt-BR.json+++ b/static/locales/pt-BR.json@@ -425,7 +425,8 @@"whatAreActionItems": "Quais são os itens de ação?","whatAreKeyPoints": "Quais são os pontos-chave?","whatWasDiscussed": "O que foi discutido?",- "whoSaidWhat": "Quem disse o quê?"+ "whoSaidWhat": "Quem disse o quê?",+ "playFromHere": "Reproduzir a partir daqui"},"colorScheme": {"chooseRecording": "Escolha uma gravação na barra lateral para visualizar sua transcrição e resumo",diff --git a/static/locales/ru.json b/static/locales/ru.jsonindex cff656df..e52b9616 100644--- a/static/locales/ru.json+++ b/static/locales/ru.json@@ -425,7 +425,8 @@"whatAreActionItems": "Какие есть задачи к выполнению?","whatAreKeyPoints": "Каковы ключевые моменты?","whatWasDiscussed": "Что обсуждалось?",- "whoSaidWhat": "Кто что сказал?"+ "whoSaidWhat": "Кто что сказал?",+ "playFromHere": "Воспроизвести отсюда"},"colorScheme": {"chooseRecording": "Выберите запись на боковой панели, чтобы увидеть её транскрипцию и резюме",diff --git a/static/locales/zh.json b/static/locales/zh.jsonindex 0767b34f..b2ed9161 100644--- a/static/locales/zh.json+++ b/static/locales/zh.json@@ -425,7 +425,8 @@"whatAreActionItems": "有哪些行动项?","whatAreKeyPoints": "关键要点是什么?","whatWasDiscussed": "讨论了什么?",- "whoSaidWhat": "谁说了什么?"+ "whoSaidWhat": "谁说了什么?",+ "playFromHere": "从此处播放"},"colorScheme": {"chooseRecording": "从侧边栏选择一个录音以查看其转录和摘要",diff --git a/templates/components/detail/floating-chat.html b/templates/components/detail/floating-chat.htmlindex 026bcb04..65f3b99a 100644--- a/templates/components/detail/floating-chat.html+++ b/templates/components/detail/floating-chat.html@@ -133,7 +133,7 @@</div><!-- Messages -->- <div ref="chatMessagesRef" class="floating-chat-messages">+ <div ref="chatMessagesRef" class="floating-chat-messages" @click="handleChatBubbleClick"><div v-if="chatMessages.length === 0" class="empty"><div class="empty__icon"><i class="fas fa-robot"></i></div><div class="empty__title" v-text="t('help.askAboutTranscription')"></div>diff --git a/templates/components/detail/mobile-chat-panel.html b/templates/components/detail/mobile-chat-panel.htmlindex 74206e0e..cf9d04fb 100644--- a/templates/components/detail/mobile-chat-panel.html+++ b/templates/components/detail/mobile-chat-panel.html@@ -2,7 +2,7 @@contextual toolbar so this panel no longer overlays its ownfloating × button on top of message content. --><div v-if="mobileTab === 'chat'" class="h-full flex flex-col overflow-hidden">- <div ref="chatMessagesRef" class="flex-1 overflow-y-auto px-3 py-3 space-y-4">+ <div ref="chatMessagesRef" class="flex-1 overflow-y-auto px-3 py-3 space-y-4" @click="handleChatBubbleClick"><div v-if="chatMessages.length === 0" class="empty"><div class="empty__icon"><i class="fas fa-robot"></i></div><div class="empty__title" v-text="t('help.askAboutTranscription')"></div>