mirror of
https://github.com/anomalyco/hex.git
synced 2026-11-28 13:02:21 +01:00
* meetings: import audio files behind a Labs switch Adds Labs › Import audio (macOS, off by default): Meetings offers Import audio… beside Start recording, decodes a WAV, M4A, MP3, AIFF, or CAF file to 16 kHz mono float through a new AVFoundation Swift bridge in bounded blocks, writes it as an ordinary meeting with an empty microphone track, and runs the same final transcript, Markdown export, and notes path a recording does. Imported turns are labelled Speaker in the pane and its Markdown export; a manifest flag keeps older files reading as recorded meetings. Refuses while a recording or another import runs, and a final.pending meeting finishes on the next launch if Hex quits mid-import. * meetings: harden audio import decoding and cleanup Fixes review findings on #1462: the staging WAV is named for AVAudioFile, declares kAudioFileWAVEType, closes before Rust reads it, and the converter loop separates input exhaustion from termination, writes every non-empty buffer, downmixes stereo, and reports a zero-frame read as EOF. Every failure before final.pending removes the meeting folder; quitting during the final pass leaves it Interrupted with final.pending for the next launch; shutdown logs import errors and still joins pending finals. The import button and watcher share the managed Labs gate, and the watcher refuses an off-lab import before spawning a worker. Adds macOS decode tests for 44.1 kHz stereo float and 16-bit PCM. * meetings: cancel abandoned audio imports and sweep their folders A quit now cancels the AVFoundation decode between blocks, so the existing cleanup removes the meeting folder within the drain. A crash or a quit past the deadline can still leave a staging file and lock; a launch sweep removes those folders only when they have no manifest, contain system.importing.wav, and their lock is free. Also drops read error code 0 as EOF, autopools each converter iteration, and makes the macOS stereo tests silent on the left so a lost downmix fails. * meetings: keep compressed imports whole and close the import crash window A short AVAudioFile read no longer ends input; only a zero-frame read, kAudioFileEndOfFileError, or an error at/after the recorded end does. The import now fsyncs its staging WAV, creates and syncs the empty microphone track, and computes its samples before the rename; the manifest write immediately follows the rename. The launch sweep also removes a folder with both finished tracks and no manifest, covering the rename-to-manifest window. * meetings: mark imports explicitly for the launch sweep An import writes import.pending under its lock before decoding and removes it only after final.pending is synced; the sweep now requires that marker, no manifest, and a free lock, so it never guesses from the files a folder contains. A tail read error after a short read counts as EOF for MP3s whose estimated length is too high, while a mid-file error after a full read still fails.
51 lines
2 KiB
Rust
51 lines
2 KiB
Rust
//! The final pass of a meeting whose audio is complete: its transcript, the
|
|
//! user's Markdown copy, and its finished event, or `final.pending` recovery
|
|
//! when Hex is quitting.
|
|
|
|
use std::fs;
|
|
use std::path::Path;
|
|
|
|
use color_eyre::eyre::Result;
|
|
|
|
use super::{FINAL_PENDING_FILE, MeetingManifest, MeetingStatus, transcribe, write_manifest};
|
|
|
|
/// Transcribes and publishes a meeting whose audio is complete, with the
|
|
/// folder's lock held. A failure while quitting keeps `final.pending` and
|
|
/// leaves it Interrupted for the next launch; any other failure keeps the
|
|
/// meeting Interrupted with its error.
|
|
pub(crate) fn finish_transcription(
|
|
directory: &Path,
|
|
mut manifest: MeetingManifest,
|
|
selection: &crate::transcription::models::TranscriptionSelection,
|
|
) -> Result<MeetingManifest> {
|
|
match transcribe(directory, &mut manifest, selection, None) {
|
|
Ok(()) => {
|
|
manifest.status = MeetingStatus::Complete;
|
|
manifest.error = None;
|
|
write_manifest(directory, &manifest)?;
|
|
super::finished_events::publish(&manifest.id);
|
|
Ok(manifest)
|
|
}
|
|
Err(error) if crate::desktop::process_exit::quitting() => {
|
|
// Quitting cut the final pass short: like quitting while
|
|
// recording, the transcript finishes at the next launch.
|
|
manifest.status = MeetingStatus::Interrupted;
|
|
manifest.error = None;
|
|
fs::write(directory.join(FINAL_PENDING_FILE), b"")?;
|
|
write_manifest(directory, &manifest)?;
|
|
tracing::info!(
|
|
meeting = manifest.id,
|
|
%error,
|
|
"Hex quit during final transcription; the transcript finishes at the next launch"
|
|
);
|
|
Ok(manifest)
|
|
}
|
|
Err(error) => {
|
|
manifest.status = MeetingStatus::Interrupted;
|
|
manifest.error = Some(error.to_string());
|
|
write_manifest(directory, &manifest)?;
|
|
let _ = fs::remove_file(directory.join(FINAL_PENDING_FILE));
|
|
Err(error)
|
|
}
|
|
}
|
|
}
|