AI Coding in Practice: Building a Desktop Audio/Video Extraction Tool
This article examines a practical AI-coding scenario: using an AI coding assistant to build a multi-threaded desktop tool that batch-extracts audio tracks from video files. It shows how to turn a vague request into explicit requirements, why a worker-thread plus queue architecture keeps the UI responsive, how to enumerate formats and check dependencies up front, and how to handle edge cases such as duplicate filenames and unwritable paths. A reusable prompt structure, code skeletons, follow-up questions, and an acceptance checklist are included.
1. Background: Why “It Generates Code” Is Not “It Delivers Software”
As AI coding tools spread quickly, the metric developers care about has shifted from “can it produce a runnable snippet” to “can it deliver a structurally complete application in one pass.” The scenario in the source material is representative: the requester wanted a desktop program, written in a scripting language with a built-in GUI library, that batch-extracts audio and video tracks, and explicitly imposed one hard constraint — the interface must not freeze.
Such a request looks simple but covers most of the hard parts of desktop development:
- Compatibility handling for multiple input and multiple output formats;
- Thread model design for the GUI and background tasks;
- Progress feedback and state synchronization for long-running tasks;
- Observability of error paths and user-facing messages;
- Output filename collisions and overwrite protection.
So rather than benchmarking any specific model or platform, this article abstracts the topic into a general engineering question: how to use AI coding capabilities to reliably produce a multi-threaded desktop tool that meets engineering standards, along with a practical way to describe requirements, a code skeleton, and acceptance criteria.
2. Requirements Engineering: Turning “Tedious” into Machine-Executable Constraints
Vague descriptions are the biggest enemy of generation quality. The original request worked because it stated functionality, non-functional requirements, and boundary conditions all at once. A reusable prompt structure has four layers:
- Tech stack constraints: language, GUI framework, dependency boundaries (for example, only the standard library plus an external command-line transcoding component).
- Feature list: file import, queue display, input/output format selection, start conversion, exit program.
- Non-functional constraints: interface responsiveness, progress visualization, error messages, log retention.
- Boundaries and fault tolerance: empty queue, unsupported format, missing dependency, duplicate filename, unwritable path.
An illustrative prompt fragment:
Build a batch audio/video extraction tool in Python + tkinter:- Support importing multiple video files; the queue can be added to and reduced;- Output can select common audio formats;- Conversion runs in a background thread; the main thread only handles the UI and queue state;- Provide overall progress and a per-file status column;- Missing dependencies, unsupported formats, and unwritable paths must all produce clear messages;- Duplicate output names automatically get a sequence number appended; silent overwriting is forbidden.
This turns “no freezing” from an adjective into a verifiable engineering constraint and noticeably reduces the chance of the generated result drifting off target.
3. Architecture: Threads and Queues Are the Core of Freeze Prevention
The event loop of a GUI framework runs on the main thread, so any time-consuming operation placed there makes the window unresponsive. The correct approach is “the main thread only does the UI, worker threads only do the work,” with the two communicating through a thread-safe queue.
Recommended layering:
- UI layer: widget construction, event binding, state refresh;
- Scheduling layer: task queue, worker thread pool, cancellation flag;
- Execution layer: invoking the external transcoding component for demuxing and audio encoding;
- Validation layer: checking dependency availability and output directory writability before startup.
Key implementation points:
import queueimport threadingtask_q = queue.Queue()result_q = queue.Queue()stop_flag = threading.Event()def worker():while not stop_flag.is_set():try:item = task_q.get(timeout=0.2)except queue.Empty:continue# Run the conversion, then write progress/results into result_qresult_q.put(("done", item.name))task_q.task_done()def poll_results(root):while not result_q.empty():status, name = result_q.get_nowait()# Update widgets on the main thread; avoid touching the UI across threadsroot.after(0, update_ui, status, name)root.after(100, poll_results, root)
Notes:
- Worker threads never manipulate UI widgets directly; all UI updates are executed back on the main thread;
- Queue pulls use a timeout so threads can respond to the exit signal;
- Progress and results travel through a message queue, avoiding shared-variable races;
- Cancellation is cooperative via an event flag rather than forcibly terminating threads.
4. Formats and Dependencies: Write “Common Formats” as an Explicit List
“Supports common formats” is a classic requirements trap. In engineering terms, input containers and output codecs should be enumerated explicitly and kept consistent between the UI and the validation logic:
- Input: common video containers and packaging formats;
- Output: common lossy and lossless audio formats;
- Dependencies: the external transcoding component must be detected at startup, and a missing one should produce installation guidance instead of a stack trace.
Illustrative startup self-check:
def check_dependency(executable: str) -> bool:import shutilreturn shutil.which(executable) is not None
If the check fails, the UI should disable the “Start Conversion” button during startup and explain the reason in the status bar. This “fail early” strategy gives a better experience than failing mid-run and is also easier to verify through automated acceptance.
5. Robustness Details: Duplicate Names, Paths, and Error Messages
The quality gap in generated code often shows up in details nobody explicitly asked for. A deliverable tool should at minimum handle:
- Duplicate output names: automatically append a sequence number or timestamp; never overwrite silently;
- Path validity: create the output directory if it does not exist; warn in advance if it is not writable;
- Empty queue: disable conversion and show a message when no files are imported;
- Per-file failure isolation: one failed file must not abort the whole batch; the status column marks the failure reason;
- Cancellation: long tasks support stopping and reclaim thread resources.
Illustrative naming strategy:
def unique_path(out_dir, stem, ext):candidate = f"{stem}{ext}"index = 1while os.path.exists(os.path.join(out_dir, candidate)):candidate = f"{stem}_{index}{ext}"index += 1return os.path.join(out_dir, candidate)
6. Follow-Up Verification: Confirming Implicit Assumptions with Continuous Questions
The most valuable step in the test run was continuing to ask about default behavior after generation, for example “where is the default output directory,” “is overwriting allowed,” and “what happens when a dependency is missing.” These questions make implicit assumptions explicit and avoid expectation gaps after delivery.
Suggested follow-up checklist:
- Default output directory and how it can be configured;
- Overwrite policy and naming rules;
- Fallback plan when dependency detection fails;
- Cancellation and exception recovery behavior;
- Log level and where logs are kept.
7. Acceptance Checklist: From “Zero Errors” to “Deliverable”
Compiling cleanly is only the starting point. Recommended acceptance checks:
- Zero errors from syntax and static checks;
- The main thread stays responsive during conversion (the window can be dragged, Cancel can be clicked);
- Progress and the status column update in real time with no cross-thread UI exceptions;
- Missing dependencies, unsupported formats, and unwritable paths all produce readable messages;
- Duplicate output names do not overwrite, and a failed file does not affect subsequent tasks;
- On exit, threads and queues are reclaimed correctly with no leftover processes.
8. Conclusion
Using AI coding for desktop tool development is less about how many lines are generated in one pass and more about whether requirements are structured, whether the thread model is correct, and whether boundaries are handled explicitly. Following the path of “constraints first, main thread only for UI, fail early, prevent overwrites with naming, fill gaps with follow-up questions” can significantly improve the first-pass success rate and maintainability of generated code. Combined with general cloud capabilities such as cloud builds, log services, and monitoring alerts, it is also possible to add version traceability for build artifacts and runtime quality observation, moving this kind of small tool from “it runs” toward “it is operable.”
