about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorelioat <elioat@tilde.institute>2025-03-10 21:10:49 -0400
committerelioat <elioat@tilde.institute>2025-03-10 21:10:49 -0400
commit775fe740bd08f53edaa2ffc28614ae41a74ac222 (patch)
treedeefe1579097c21be03abb4ec7ffbdc6a53ead7a
parentd18f8695a9781744bb4e1a906fb1709c7ea5bed6 (diff)
downloadtour-775fe740bd08f53edaa2ffc28614ae41a74ac222.tar.gz
*
-rw-r--r--html/voice-memos/app.js72
1 files changed, 67 insertions, 5 deletions
diff --git a/html/voice-memos/app.js b/html/voice-memos/app.js
index f13e28f..445fffc 100644
--- a/html/voice-memos/app.js
+++ b/html/voice-memos/app.js
@@ -514,15 +514,27 @@ const tryAlternativePlayback = async (audioBlob) => {
 };
 
 /**
- * Saves the recording as an audio file
+ * Saves the recording as an audio file with proper metadata
  */
-const saveRecording = () => {
-    const { audioChunks, mimeType } = stateManager.getState();
+const saveRecording = async () => {
+    const { audioChunks, mimeType, recordingStartTime } = stateManager.getState();
     
     // Use the detected MIME type or fallback to a generic audio type
     const blobType = mimeType || 'audio/webm';
     const audioBlob = new Blob(audioChunks, { type: blobType });
-    const audioUrl = URL.createObjectURL(audioBlob);
+    
+    // Calculate recording duration
+    const recordingDuration = recordingStartTime ? 
+        Math.floor((Date.now() - recordingStartTime) / 1000) : 0;
+    
+    // Get device information
+    const deviceId = elements.inputSource.value;
+    const deviceLabel = Array.from(elements.inputSource.options)
+        .find(option => option.value === deviceId)?.text || 'Unknown Device';
+    
+    // Format current date for filename
+    const now = new Date();
+    const formattedDate = now.toISOString().replace(/[:.]/g, '-');
     
     // Determine file extension based on MIME type
     let fileExtension = 'webm';
@@ -533,13 +545,63 @@ const saveRecording = () => {
         else if (mimeType.includes('wav')) fileExtension = 'wav';
     }
     
+    // For formats that support metadata through the Web Audio API
+    if (fileExtension === 'wav' || fileExtension === 'mp3') {
+        try {
+            // Create a new audio context
+            const audioContext = new (window.AudioContext || window.webkitAudioContext)();
+            
+            // Convert blob to array buffer
+            const arrayBuffer = await audioBlob.arrayBuffer();
+            
+            // Decode the audio data
+            const audioBuffer = await audioContext.decodeAudioData(arrayBuffer);
+            
+            // Create metadata object
+            const metadata = {
+                title: `Voice Memo ${formattedDate}`,
+                artist: 'Voice Memos App',
+                album: 'Voice Recordings',
+                date: now.toISOString(),
+                device: deviceLabel,
+                duration: recordingDuration,
+                sampleRate: audioBuffer.sampleRate,
+                numberOfChannels: audioBuffer.numberOfChannels
+            };
+            
+            console.log('Audio metadata:', metadata);
+            
+            // Note: Web browsers don't provide direct API for writing metadata to audio files
+            // We're logging the metadata and including what we can in the filename
+            
+            // For a complete solution, server-side processing or a dedicated library would be needed
+        } catch (error) {
+            console.warn('Could not process audio metadata:', error);
+        }
+    }
+    
+    // Include some metadata in the filename since browser APIs don't allow direct metadata embedding
+    const filename = `voice-memo_${formattedDate}_${deviceLabel.replace(/[^a-z0-9]/gi, '-')}_${recordingDuration}s.${fileExtension}`;
+    
+    // Create download link
+    const audioUrl = URL.createObjectURL(audioBlob);
     const a = document.createElement('a');
     a.href = audioUrl;
-    a.download = `voice-memo-${new Date().toISOString()}.${fileExtension}`;
+    a.download = filename;
     document.body.appendChild(a);
     a.click();
     document.body.removeChild(a);
     URL.revokeObjectURL(audioUrl);
+    
+    // Log metadata for debugging
+    console.log('Saved recording with filename:', filename);
+    console.log('Recording details:', {
+        timestamp: now.toISOString(),
+        duration: recordingDuration + 's',
+        device: deviceLabel,
+        mimeType: blobType,
+        fileSize: Math.round(audioBlob.size / 1024) + 'KB'
+    });
 };
 
 // Event Listeners