Enhance audio recording functionality to improve duration handling

- Updated getAudioDuration function to utilize recordedDuration property for files, addressing metadata issues on Windows.
- Modified onRecordingComplete callbacks in audio recording hooks to pass the actual recorded duration.
- Adjusted error handling in ProfileForm and SampleUpload components to clear validation errors for recorded files.
- Ensured consistent handling of audio file duration across components.
This commit is contained in:
Jamie Pine
2026-01-26 16:22:31 -08:00
parent 446182e16c
commit 8cd868d33f
5 changed files with 63 additions and 19 deletions
+6 -2
View File
@@ -3,7 +3,7 @@ import { isTauri } from '@/lib/tauri';
interface UseAudioRecordingOptions {
maxDurationSeconds?: number;
onRecordingComplete?: (blob: Blob) => void;
onRecordingComplete?: (blob: Blob, duration?: number) => void;
}
export function useAudioRecording({
@@ -87,7 +87,11 @@ export function useAudioRecording({
mediaRecorder.onstop = () => {
const blob = new Blob(chunksRef.current, { type: 'audio/webm' });
onRecordingComplete?.(blob);
// Pass the actual recorded duration
const recordedDuration = startTimeRef.current
? (Date.now() - startTimeRef.current) / 1000
: undefined;
onRecordingComplete?.(blob, recordedDuration);
// Stop all tracks
streamRef.current?.getTracks().forEach((track) => {
+6 -2
View File
@@ -4,7 +4,7 @@ import { isTauri } from '@/lib/tauri';
interface UseSystemAudioCaptureOptions {
maxDurationSeconds?: number;
onRecordingComplete?: (blob: Blob) => void;
onRecordingComplete?: (blob: Blob, duration?: number) => void;
}
/**
@@ -110,7 +110,11 @@ export function useSystemAudioCapture({
}
const blob = new Blob([bytes], { type: 'audio/wav' });
onRecordingComplete?.(blob);
// Pass the actual recorded duration
const recordedDuration = startTimeRef.current
? (Date.now() - startTimeRef.current) / 1000
: undefined;
onRecordingComplete?.(blob, recordedDuration);
} catch (err) {
const errorMessage =
err instanceof Error