mirror of
https://github.com/jamiepine/voicebox.git
synced 2026-09-19 23:00:45 -07:00
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:
@@ -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) => {
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user