Skip to content

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

Python

Fix system audio recording for Firefox and improve error messages

Murtaza Nasirc309773d6086
diff --git a/static/js/app.modular.js b/static/js/app.modular.js
index 24af9e7d..716ef1ad 100644
--- a/static/js/app.modular.js
+++ b/static/js/app.modular.js
@@ -150,7 +150,7 @@ document.addEventListener('DOMContentLoaded', async () => {
const recordingTime = ref(0);
const recordingInterval = ref(null);
const canRecordAudio = ref(navigator.mediaDevices && navigator.mediaDevices.getUserMedia);
- const canRecordSystemAudio = ref(false);
+ const canRecordSystemAudio = computed(() => navigator.mediaDevices && navigator.mediaDevices.getDisplayMedia);
const systemAudioSupported = ref(false);
const systemAudioError = ref('');
const recordingNotes = ref('');
diff --git a/static/js/modules/composables/audio.js b/static/js/modules/composables/audio.js
index 46095499..de9c9e52 100644
--- a/static/js/modules/composables/audio.js
+++ b/static/js/modules/composables/audio.js
@@ -67,29 +67,8 @@ export function useAudio(state, utils) {
}
};
- // Detect system audio capabilities
- const detectSystemAudioCapabilities = async () => {
- systemAudioSupported.value = false;
- canRecordSystemAudio.value = false;
- systemAudioError.value = '';
-
- // Check if getDisplayMedia is available
- if (!navigator.mediaDevices || !navigator.mediaDevices.getDisplayMedia) {
- systemAudioError.value = 'getDisplayMedia API not supported';
- return;
- }
-
- try {
- // Test if we can request system audio (this will prompt user)
- // We'll do this only when user actually tries to record
- systemAudioSupported.value = true;
- canRecordSystemAudio.value = true;
- systemAudioError.value = '';
- } catch (error) {
- systemAudioError.value = error.message;
- console.warn('System audio detection failed:', error);
- }
- };
+ // Note: System audio capability detection is now handled by computed property
+ // canRecordSystemAudio = computed(() => navigator.mediaDevices && navigator.mediaDevices.getDisplayMedia)
// Hide recording notification
const hideRecordingNotification = async () => {
@@ -162,19 +141,31 @@ export function useAudio(state, utils) {
source.connect(analyser.value);
} else if (mode === 'system') {
- stream = await navigator.mediaDevices.getDisplayMedia({
- video: true,
- audio: {
+ // Firefox and Chrome handle system audio differently
+ // Firefox requires simpler constraints and the tab must have audio playing
+ const isFirefox = navigator.userAgent.toLowerCase().indexOf('firefox') > -1;
+
+ const displayMediaConstraints = {
+ video: true, // Required by spec, we'll stop it immediately
+ audio: isFirefox ? true : {
echoCancellation: false,
noiseSuppression: false,
autoGainControl: false
}
- });
+ };
+
+ stream = await navigator.mediaDevices.getDisplayMedia(displayMediaConstraints);
const audioTrack = stream.getAudioTracks()[0];
if (!audioTrack) {
stream.getTracks().forEach(track => track.stop());
- throw new Error('No system audio track available. Please share a tab or window with audio.');
+ const browserName = isFirefox ? 'Firefox' : 'your browser';
+ throw new Error(
+ `No system audio track available. In ${browserName}, please:\n` +
+ `1. Share a tab or window that is actively playing audio\n` +
+ `2. Make sure "Share audio" checkbox is checked in the sharing dialog\n` +
+ `3. The audio must be playing when you start sharing`
+ );
}
// Stop video track
@@ -197,9 +188,12 @@ export function useAudio(state, utils) {
}
});
+ // Firefox and Chrome handle system audio differently
+ const isFirefox = navigator.userAgent.toLowerCase().indexOf('firefox') > -1;
+
const displayStream = await navigator.mediaDevices.getDisplayMedia({
video: true,
- audio: {
+ audio: isFirefox ? true : {
echoCancellation: false,
noiseSuppression: false,
autoGainControl: false
@@ -210,7 +204,13 @@ export function useAudio(state, utils) {
if (!systemAudioTrack) {
micStream.getTracks().forEach(track => track.stop());
displayStream.getTracks().forEach(track => track.stop());
- throw new Error('No system audio track available.');
+ const browserName = isFirefox ? 'Firefox' : 'your browser';
+ throw new Error(
+ `No system audio track available. In ${browserName}, please:\n` +
+ `1. Share a tab or window that is actively playing audio\n` +
+ `2. Make sure "Share audio" checkbox is checked in the sharing dialog\n` +
+ `3. The audio must be playing when you start sharing`
+ );
}
// Stop video tracks
@@ -530,9 +530,9 @@ export function useAudio(state, utils) {
return isRecording.value || audioBlobURL.value;
};
- // Initialize audio capabilities
+ // No initialization needed - system audio detection is handled by computed property
const initializeAudio = async () => {
- await detectSystemAudioCapabilities();
+ // Placeholder for future initialization if needed
};
return {
@@ -551,7 +551,6 @@ export function useAudio(state, utils) {
hasUnsavedRecording,
acquireWakeLock,
releaseWakeLock,
- detectSystemAudioCapabilities,
initializeAudio
};
}
diff --git a/static/js/modules/state/audio.js b/static/js/modules/state/audio.js
index 0c9f7f4b..ff4a9f3d 100644
--- a/static/js/modules/state/audio.js
+++ b/static/js/modules/state/audio.js
@@ -2,7 +2,7 @@
* Audio recording state management
*/
-export function createAudioState(ref) {
+export function createAudioState(ref, computed) {
// --- Audio Recording State ---
const isRecording = ref(false);
const mediaRecorder = ref(null);
@@ -11,7 +11,7 @@ export function createAudioState(ref) {
const recordingTime = ref(0);
const recordingInterval = ref(null);
const canRecordAudio = ref(navigator.mediaDevices && navigator.mediaDevices.getUserMedia);
- const canRecordSystemAudio = ref(false);
+ const canRecordSystemAudio = computed(() => navigator.mediaDevices && navigator.mediaDevices.getDisplayMedia);
const systemAudioSupported = ref(false);
const systemAudioError = ref('');
const recordingNotes = ref('');
diff --git a/templates/modals/system-audio-help-modal.html b/templates/modals/system-audio-help-modal.html
index e093e696..ceaf1f85 100644
--- a/templates/modals/system-audio-help-modal.html
+++ b/templates/modals/system-audio-help-modal.html
@@ -11,7 +11,7 @@
<div>
<p class="font-medium text-blue-800 dark:text-blue-300 mb-2">Browser Compatibility</p>
<p class="text-sm text-blue-700 dark:text-blue-400">
- System audio recording requires a Chromium-based browser (Chrome, Edge, Brave) and is not supported on mobile devices.
+ System audio recording works best in Chrome, Edge, and Brave. Firefox is supported but requires the tab to be actively playing audio. Not supported on Safari or mobile devices.
</p>
</div>
</div>
@@ -22,8 +22,8 @@
<ol class="list-decimal list-inside space-y-2 text-sm text-[var(--text-secondary)]">
<li>Click "System Audio" or "Mic + System" button</li>
<li>A screen sharing dialog will appear</li>
- <li>Select a Chrome tab or entire screen</li>
- <li>Make sure "Share audio" checkbox is enabled</li>
+ <li>Select a tab or window that is <strong>actively playing audio</strong></li>
+ <li>Make sure "Share audio" checkbox is <strong>checked</strong></li>
<li>Click "Share" to start recording</li>
</ol>
</div>
@@ -31,10 +31,11 @@
<div>
<h4 class="font-medium mb-2">Troubleshooting:</h4>
<ul class="list-disc list-inside space-y-1 text-sm text-[var(--text-muted)]">
- <li>Ensure you're using Chrome, Edge, or Brave</li>
- <li>Check that "Share audio" option is visible and enabled</li>
+ <li><strong>Important:</strong> The tab/window must be playing audio when you share it</li>
+ <li>Check that "Share audio" checkbox is checked in the sharing dialog</li>
+ <li>In Firefox, start playing audio first, then click record</li>
<li>Some content may have DRM protection that blocks recording</li>
- <li>Firefox and Safari do not support this feature</li>
+ <li>Not supported on Safari or mobile browsers</li>
</ul>
</div>
</div>