Skip to content

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

Python
23.4 KB
Raw Blame
<!-- Recording View -->
<div v-else-if="currentView === 'recording'" class="flex-1 flex flex-col p-2 md:p-8 bg-[var(--bg-primary)] min-h-0">
    <div class="flex-1 flex flex-col max-w-4xl w-full mx-auto bg-[var(--bg-secondary)] rounded-xl border border-[var(--border-primary)] min-h-0 overflow-hidden">
        <!-- Top: Visualizer and Status (Fixed) -->
        <div class="flex-shrink-0 p-3 md:p-6 text-center bg-[var(--bg-tertiary)] border-b border-[var(--border-primary)]">
            <div v-if="isRecording" class="w-full mx-auto mb-3 md:mb-4">
                <!-- Live preview of the captured tab/window/screen when the
                     user opted into video recording (#303). The stream is
                     attached by audio.js (srcObject can't be template-bound). -->
                <div v-if="recordingVideoActive" class="max-w-2xl mx-auto mb-2 md:mb-3">
                    <video id="recordingVideoPreview"
                           class="w-full max-h-48 md:max-h-64 rounded-lg bg-black object-contain"
                           muted autoplay playsinline></video>
                    <p class="text-[10px] text-[var(--text-muted)] mt-0.5">
                        <i class="fas fa-video mr-1"></i>${ t('recording.videoPreviewLabel') }
                    </p>
                </div>
                <!-- Dual visualizer for 'both' mode -->
                <div v-if="recordingMode === 'both'" class="max-w-4xl mx-auto flex gap-2 md:gap-4">
                    <div class="w-1/2 min-h-[8rem] md:min-h-[12rem] h-32 md:h-48 flex flex-col bg-[var(--bg-primary)] rounded-lg p-1.5 md:p-2">
                        <div class="flex-1 w-full overflow-hidden rounded-md" style="min-height: 6rem;">
                            <canvas ref="micVisualizer" class="w-full h-full"></canvas>
                        </div>
                        <p class="text-xs text-[var(--text-muted)] pt-0.5 md:pt-1" v-text="t('recording.microphone')"></p>
                    </div>
                    <div class="w-1/2 min-h-[8rem] md:min-h-[12rem] h-32 md:h-48 flex flex-col bg-[var(--bg-primary)] rounded-lg p-1.5 md:p-2">
                        <div class="flex-1 w-full overflow-hidden rounded-md" style="min-height: 6rem;">
                            <canvas ref="systemVisualizer" class="w-full h-full"></canvas>
                        </div>
                        <p class="text-xs text-[var(--text-muted)] pt-0.5 md:pt-1" v-text="t('recording.systemAudio')"></p>
                    </div>
                </div>
                <!-- Single visualizer for other modes -->
                <div v-else class="min-h-[8rem] md:min-h-[12rem] h-32 md:h-48 max-w-2xl mx-auto bg-[var(--bg-primary)] rounded-lg p-1.5 md:p-2 flex flex-col">
                    <div class="flex-1 w-full overflow-hidden rounded-md" style="min-height: 6rem;">
                        <canvas ref="visualizer" class="w-full h-full"></canvas>
                    </div>
                    <p class="text-xs text-[var(--text-muted)] pt-0.5 md:pt-1 capitalize">${recordingMode}</p>
                </div>
            </div>
            <div v-if="!isRecording && audioBlobURL" class="w-full mb-3 md:mb-4">
                <!-- A video capture reviews as a video player; audio-only
                     recordings keep the compact audio bar. -->
                <div v-if="recordingVideoActive" class="max-w-2xl mx-auto">
                    <video :src="audioBlobURL" controls playsinline
                           @loadedmetadata="normalizeLiveMediaDuration"
                           class="w-full max-h-64 md:max-h-80 rounded-lg bg-black object-contain"></video>
                </div>
                <div v-else class="audio-player-container">
                    <audio :src="audioBlobURL" controls class="w-full"
                           @loadedmetadata="normalizeLiveMediaDuration">
                        ${ t('recording.audioElementUnsupported') }
                    </audio>
                </div>
            </div>

            <div>
                <div class="text-xl md:text-2xl font-mono text-[var(--text-accent)]">${formatTime(recordingTime)}</div>
                <p class="text-xs md:text-sm text-[var(--text-muted)]">${ isRecording ? (isPaused ? t('recording.recordingPaused') : t('recording.recordingInProgress')) : t('recording.recordingFinished') }</p>
                <!-- Real-time file size display -->
                <div v-if="isRecording && estimatedFileSize > 0" class="mt-1.5">
                    <p class="text-xs text-[var(--text-muted)]">
                        ${ t('help.estimatedSize') }: <span class="font-mono">${formatFileSize(estimatedFileSize)}</span>
                        <span v-if="actualBitrate > 0" class="ml-2">
                            (${Math.round(actualBitrate / 1000)}kbps)
                        </span>
                    </p>
                    <!-- Size warning indicator. Only meaningful on the legacy
                         in-RAM path: with server-side chunk streaming there is
                         no size limit (only an hours ceiling), so showing an
                         "approaching limit" banner would be wrong (#332). -->
                    <div v-if="!isServerStreamedRecording && estimatedFileSize > (maxRecordingMB * 1024 * 1024 * 0.8)" class="mt-0.5">
                        <div class="flex items-center text-xs text-amber-600 dark:text-amber-400">
                            <i class="fas fa-exclamation-triangle mr-1"></i>
                            <span v-text="t('help.approachingLimit', { limit: maxRecordingMB })"></span>
                        </div>
                    </div>
                </div>

                <!-- Mobile Background Recording Warning - Below timer -->
                <div v-if="isRecording && isMobileDevice"
                     class="mt-2 p-2 bg-amber-50 dark:bg-amber-900 dark:bg-opacity-20 border border-amber-300 dark:border-amber-700 rounded">
                    <div class="flex items-start gap-1.5 text-left">
                        <i class="fas fa-exclamation-triangle text-amber-600 dark:text-amber-400 flex-shrink-0 text-xs" style="margin-top: 2px;"></i>
                        <div class="flex-1 min-w-0">
                            <div class="text-xs text-amber-800 dark:text-amber-200 leading-snug">
                                <strong class="font-semibold" v-text="t('recording.keepAppVisible')"></strong>
                                <span class="block text-[10px] mt-0.5" v-text="t('recording.keepAppVisibleHint')"></span>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <!-- MIDDLE: Content Area -->
        <div class="flex-1 min-h-0 flex flex-col">

            <!-- STATE 1: Recording in progress — notes fill space, no accordion -->
            <template v-if="isRecording">
                <div class="flex-1 min-h-0 flex flex-col p-2 md:p-3">
                    <label for="recordingNotes" class="block text-sm font-medium text-[var(--text-secondary)] mb-1.5 flex-shrink-0">
                        <i class="fas fa-pencil-alt mr-1"></i>
                        ${ t('recording.notesMarkdownLabel') }
                    </label>
                    <div class="recording-notes-editor recording-active" style="min-height: 150px;">
                        <textarea ref="recordingNotesEditor" v-model="recordingNotes"
                                  class="w-full h-full bg-[var(--bg-input)] border border-[var(--border-secondary)] rounded-lg p-2 md:p-3 text-sm focus:outline-none focus:ring-2 focus:ring-[var(--ring-focus)] resize-none"
                                  :placeholder="t('form.notesPlaceholder')"></textarea>
                    </div>
                </div>
            </template>

            <!-- STATE 2: Recording finished — accordion -->
            <template v-else-if="audioBlobURL">

                <!-- Notes Section -->
                <div :class="['flex flex-col border-b border-[var(--border-primary)]',
                               expandedSection === 'notes' ? 'flex-1 min-h-0' : 'flex-shrink-0']">
                    <!-- Header bar (always visible) -->
                    <button @click="expandedSection = expandedSection === 'notes' ? 'settings' : 'notes'"
                            class="flex-shrink-0 flex items-center justify-between w-full px-3 md:px-6 py-2.5
                                   bg-[var(--bg-tertiary)] hover:bg-[var(--bg-accent)] transition-colors">
                        <span class="flex items-center gap-2 text-sm font-medium text-[var(--text-secondary)]">
                            <i class="fas fa-pencil-alt text-[var(--text-muted)]"></i>
                            ${ t('recording.notesLabel') }
                            <span v-if="recordingNotes" class="text-[10px] text-[var(--text-muted)]" v-text="t('recording.hasContent')"></span>
                        </span>
                        <i :class="['fas text-[var(--text-muted)] transition-transform duration-200',
                                    expandedSection === 'notes' ? 'fa-chevron-up' : 'fa-chevron-down']"></i>
                    </button>
                    <!-- Content (when expanded). Small padding so the
                         bordered editor reads as a defined card filling the
                         section, without the old wide box-in-box gap. -->
                    <div v-show="expandedSection === 'notes'" class="flex-1 min-h-0 flex flex-col p-2 md:p-3">
                        <div class="recording-notes-editor accordion-expanded">
                            <textarea ref="recordingNotesEditor" v-model="recordingNotes"
                                      class="w-full h-full bg-[var(--bg-input)] border border-[var(--border-secondary)] rounded-lg p-2 md:p-3 text-sm focus:outline-none focus:ring-2 focus:ring-[var(--ring-focus)] resize-none"
                                      :placeholder="t('form.notesPlaceholder')"></textarea>
                        </div>
                    </div>
                </div>

                <!-- Settings Section -->
                <div :class="['flex flex-col',
                               expandedSection === 'settings' ? 'flex-1 min-h-0' : 'flex-shrink-0']">
                    <!-- Header bar -->
                    <button @click="expandedSection = expandedSection === 'settings' ? 'notes' : 'settings'"
                            class="flex-shrink-0 flex items-center justify-between w-full px-3 md:px-6 py-2.5
                                   bg-[var(--bg-tertiary)] border-b border-[var(--border-primary)]
                                   hover:bg-[var(--bg-accent)] transition-colors">
                        <span class="flex items-center gap-2 text-sm font-medium text-[var(--text-secondary)]">
                            <i class="fas fa-sliders-h text-[var(--text-muted)]"></i>
                            ${ t('recording.uploadSettings') }
                        </span>
                        <i :class="['fas text-[var(--text-muted)] transition-transform duration-200',
                                    expandedSection === 'settings' ? 'fa-chevron-up' : 'fa-chevron-down']"></i>
                    </button>
                    <!-- Content (when expanded) -->
                    <div v-show="expandedSection === 'settings'" class="flex-1 min-h-0 overflow-y-auto p-3 md:p-6">
                        <div class="flex flex-col gap-3 md:gap-4">

                            {% include 'components/shared/folder-tag-picker.html' %}

                            <!-- Advanced Options (collapsible). Shown whenever the active
                                 connector supports any of the options inside — mirrors the
                                 upload modal so in-browser recordings can also set the
                                 initial prompt and hotwords (#375). -->
                            <div v-if="connectorSupportsDiarization || connectorSupportsSpeakerCount || connectorSupportsExactSpeakerCount || connectorSupportsHotwords || connectorSupportsInitialPrompt">
                                <button @click="showAdvancedOptions = !showAdvancedOptions"
                                        class="w-full flex items-center justify-between px-3 py-2 bg-[var(--bg-tertiary)] rounded-md hover:bg-[var(--bg-accent)] transition-colors text-xs font-medium">
                                    <span class="flex items-center gap-2 text-[var(--text-secondary)]">
                                        <i class="fas fa-cog text-[var(--text-muted)]"></i>
                                        <span v-text="t('help.advancedAsrOptions')"></span>
                                    </span>
                                    <i :class="['fas text-[var(--text-muted)]', showAdvancedOptions ? 'fa-chevron-up' : 'fa-chevron-down']"></i>
                                </button>

                                <div v-if="showAdvancedOptions" class="mt-2 p-3 bg-[var(--bg-tertiary)] rounded-md border border-[var(--border-secondary)] space-y-3">
                                    {% with apply_template_fn='applyInitialPromptTemplateToRecording',
                                            prompt_ref='asrInitialPrompt', hotwords_ref='asrHotwords',
                                            model_ref='asrTranscriptionModel', lang_ref='asrLanguage',
                                            exact_ref='asrSpeakersExact', min_ref='asrMinSpeakers', max_ref='asrMaxSpeakers' %}
                                    {% include 'components/shared/asr-options.html' %}
                                    {% endwith %}
                                </div>
                            </div>

                            <!-- Incognito Mode Toggle (only shown if feature is enabled) -->
                            <div v-if="enableIncognitoMode">
                                <button @click="incognitoMode = !incognitoMode"
                                        :class="[
                                            'w-full flex items-center justify-between px-3 py-2.5 rounded-lg border transition-all duration-200',
                                            incognitoMode
                                                ? 'bg-gradient-to-r from-violet-500/10 to-purple-500/10 border-violet-400/50 dark:border-violet-500/50'
                                                : 'bg-[var(--bg-tertiary)] border-[var(--border-secondary)] hover:border-[var(--border-focus)]'
                                        ]">
                                    <div class="flex items-center gap-3">
                                        <div :class="[
                                            'w-8 h-8 rounded-full flex items-center justify-center transition-all',
                                            incognitoMode
                                                ? 'bg-gradient-to-br from-violet-500 to-purple-600 text-white'
                                                : 'bg-[var(--bg-secondary)] text-[var(--text-muted)]'
                                        ]">
                                            <i class="fas fa-user-secret text-sm"></i>
                                        </div>
                                        <div class="text-left">
                                            <span :class="['text-sm font-medium', incognitoMode ? 'text-violet-700 dark:text-violet-300' : 'text-[var(--text-secondary)]']">
                                                ${ t('incognito.mode') }
                                            </span>
                                            <p v-if="!incognitoMode" class="text-[10px] text-[var(--text-muted)]">
                                                ${ t('incognito.processWithoutSaving') }
                                            </p>
                                            <p v-else class="text-[10px] text-violet-600 dark:text-violet-400">
                                                ${ t('incognito.sessionOnly') } &bull; ${ t('incognito.notSavedToAccount') }
                                            </p>
                                        </div>
                                    </div>
                                    <div :class="[
                                        'w-10 h-5 rounded-full relative transition-all duration-200',
                                        incognitoMode ? 'bg-gradient-to-r from-violet-500 to-purple-500' : 'bg-[var(--bg-secondary)]'
                                    ]">
                                        <div :class="[
                                            'absolute top-0.5 w-4 h-4 rounded-full bg-white shadow transition-all duration-200',
                                            incognitoMode ? 'left-5' : 'left-0.5'
                                        ]"></div>
                                    </div>
                                </button>
                            </div>

                        </div>
                    </div>
                </div>

            </template>
        </div>

        <!-- BOTTOM: Action Buttons (always pinned) -->
        <div class="flex-shrink-0 p-3 md:p-6 bg-[var(--bg-tertiary)] border-t border-[var(--border-primary)]">
            <div v-if="isRecording" class="flex gap-3 justify-center">
                <!-- Pause / Resume toggle (#338): MediaRecorder freezes the media
                     timeline while paused, so meeting breaks are excluded from the
                     recording without a silent gap. -->
                <button v-if="!isPaused" @click="pauseRecording"
                        class="px-5 md:px-6 py-2.5 md:py-3 bg-[var(--bg-button)] text-[var(--text-button)] rounded-lg hover:bg-[var(--bg-button-hover)] transition-colors text-sm md:text-base flex items-center">
                    <i class="fas fa-pause mr-2"></i><span v-text="t('recording.pauseRecording')"></span>
                </button>
                <button v-else @click="resumeRecording"
                        class="px-5 md:px-6 py-2.5 md:py-3 bg-green-600 text-white rounded-lg hover:bg-green-700 transition-colors text-sm md:text-base flex items-center">
                    <i class="fas fa-play mr-2"></i><span v-text="t('recording.resumeRecording')"></span>
                </button>
                <button @click="stopRecording"
                        :class="['px-6 md:px-8 py-2.5 md:py-3 bg-red-600 text-white rounded-lg hover:bg-red-700 transition-colors text-sm md:text-base flex items-center', isPaused ? '' : 'animate-pulse']">
                    <i class="fas fa-stop mr-2"></i><span v-text="t('recording.stopRecording')"></span>
                </button>
            </div>
            <div v-if="!isRecording && audioBlobURL" class="flex flex-col sm:flex-row gap-3 justify-center">
                <!-- Normal Upload Button (split: main uploads, caret opens options) -->
                <div v-if="!incognitoMode || !enableIncognitoMode" class="flex-1 flex relative">
                    <!-- Disabled + spinner while finalizing: draining the chunk
                         backlog can take many seconds, and without immediate
                         feedback users double-click (which used to create
                         duplicate recordings). -->
                    <button @click="uploadRecordedAudio"
                            :disabled="isFinalizingRecording"
                            class="flex-1 px-6 py-3 bg-[var(--bg-button)] text-[var(--text-button)] rounded-l-lg hover:bg-[var(--bg-button-hover)] disabled:opacity-60 disabled:cursor-not-allowed transition-colors flex items-center justify-center gap-2">
                        <i :class="isFinalizingRecording ? 'fas fa-spinner fa-spin' : 'fas fa-upload'"></i>
                        <span v-text="isFinalizingRecording ? t('help.uploadingRecording') : t('help.uploadRecordingNotes')"></span>
                    </button>
                    <button @click="showUploadSplitMenu = !showUploadSplitMenu"
                            :disabled="isFinalizingRecording"
                            class="px-3 bg-[var(--bg-button)] text-[var(--text-button)] rounded-r-lg hover:bg-[var(--bg-button-hover)] disabled:opacity-60 disabled:cursor-not-allowed transition-colors border-l border-white/25 flex items-center justify-center"
                            :title="t('mergeRecordings.moreOptions')">
                        <i class="fas fa-chevron-down text-xs"></i>
                    </button>
                    <!-- Click-away backdrop -->
                    <div v-if="showUploadSplitMenu" @click="showUploadSplitMenu = false" class="fixed inset-0 z-40"></div>
                    <!-- Options menu (opens upward; the bar is pinned to the bottom) -->
                    <div v-if="showUploadSplitMenu"
                         class="absolute bottom-full right-0 mb-2 z-50 rounded-xl p-1.5"
                         style="min-width: 300px; background-color: var(--bg-secondary); border: 1px solid var(--border-primary); box-shadow: var(--shadow-lg);">
                        <div class="px-2.5 pt-1 pb-1.5">
                            <span class="text-[10px] font-semibold uppercase tracking-wider text-[var(--text-muted)]" v-text="t('mergeRecordings.moreOptions')"></span>
                        </div>
                        <button @click="showUploadSplitMenu = false; mergeRecordedWithExisting()"
                                class="w-full text-left px-2.5 py-2.5 rounded-lg hover:bg-[var(--bg-tertiary)] transition-colors flex items-center gap-3 group">
                            <span class="flex-shrink-0 w-9 h-9 rounded-lg flex items-center justify-center text-purple-400 bg-purple-500/15 group-hover:bg-purple-500/25 transition-colors">
                                <i class="fas fa-object-group"></i>
                            </span>
                            <span class="text-sm font-medium text-[var(--text-primary)] min-w-0" v-text="t('mergeRecordings.mergeWithExisting')"></span>
                        </button>
                        <!-- Pointer connecting the menu to the caret button below it -->
                        <span class="absolute -bottom-1.5 right-4 w-3 h-3 rotate-45"
                              style="background-color: var(--bg-secondary); border-right: 1px solid var(--border-primary); border-bottom: 1px solid var(--border-primary);"></span>
                    </div>
                </div>
                <!-- Incognito Upload Button -->
                <button v-else
                        @click="uploadRecordedAudioIncognito"
                        :disabled="incognitoProcessing"
                        class="flex-1 px-6 py-3 bg-gradient-to-r from-violet-500 to-purple-600 text-white rounded-lg hover:from-violet-600 hover:to-purple-700 disabled:opacity-50 disabled:cursor-not-allowed transition-all flex items-center justify-center gap-2 shadow-sm">
                    <i :class="incognitoProcessing ? 'fas fa-spinner fa-spin' : 'fas fa-user-secret'"></i>
                    <span v-if="incognitoProcessing" v-text="t('incognito.processing')"></span>
                    <span v-else v-text="t('incognito.processInIncognito')"></span>
                </button>
                <button @click="discardRecording"
                        :disabled="isFinalizingRecording"
                        class="px-6 py-3 bg-[var(--bg-danger)] text-white rounded-lg hover:bg-[var(--bg-danger-hover)] disabled:opacity-60 disabled:cursor-not-allowed transition-colors flex items-center justify-center gap-2">
                    <i class="fas fa-trash"></i>
                    <span v-text="t('help.discard')"></span>
                </button>
            </div>
        </div>
    </div>
</div>