Building a Desktop Audio Extraction Tool with LLM Assistance: A Practical Review and Checklist
This article examines what happens when a large language model is asked to build a desktop tool for batch audio extraction from video files using Python, tkinter, and ffmpeg. It covers why this task is a good test of LLM-generated code, a reproducible test checklist, a working multi-threaded implementation, common pitfalls, and data safety considerations. Readers will learn how to evaluate LLM-generated GUI code item by item rather than trusting it blindly.
Why This Requirement Makes a Good Test
A batch audio extraction tool looks simple, but it actually touches on UI layout, concurrent execution, file system operations, and external program calls all at once. The requirements include: importing common video formats and exporting audio as MP3, WAV, and similar formats; providing a file list, format selection, and output directory settings; showing a progress bar and status bar; giving clear error messages; and keeping the UI responsive during conversion.
The most easily overlooked issue is UI freezing. tkinter’s event loop runs on the main thread. If the conversion command is called directly on the main thread, the window cannot respond to clicks or redraws during conversion, and the OS may mark it as “Not Responding.” The common solution is to run the time-consuming task in a worker thread. The worker thread only handles external program calls and progress calculation, leaving UI updates to the main thread.
Test Environment and Reproducibility
The original test record did not specify the model name, version, or dependency versions, so this article makes no claims about pass rates or stability. If you want to reproduce the test, it is recommended to record the following information:
- The LLM’s name, version, and invocation parameters, such as temperature and maximum output length
- The full prompt text, including the requirements list and constraints
- The Python version and OS version (tkinter is installed with Python)
- The ffmpeg version, which you can get by running
ffmpeg -versionon the command line - Every generated code file and run log
Acceptance Checklist
The table below can serve as an item-by-item verification checklist. The result column should be filled in after actual testing.
| # | Acceptance Item | Verification Method | Result |
|---|---|---|---|
| 1 | Import common video formats such as mp4, mkv, mov | Import sample files one by one | TBD |
| 2 | Export MP3 and WAV audio | Check output file encoding with ffprobe |
TBD |
| 3 | Recursively detect videos when importing a folder | Use a test folder containing subdirectories | TBD |
| 4 | Auto-number duplicate output filenames | Convert the same file twice in a row | TBD |
| 5 | Window stays draggable and buttons clickable during conversion | Convert a video longer than 10 minutes and observe the UI | TBD |
| 6 | Show a warning when ffmpeg is missing | Temporarily remove ffmpeg from PATH and launch the program | TBD |
| 7 | Status bar shows the reason when conversion fails | Import a corrupted video file | TBD |
Key Points of the Multi-Threading Approach
The following code shows a workable structure. Compared with the illustrative code a model typically generates, it adds dependency detection, filename conflict handling, and error reporting.
import osimport queueimport shutilimport subprocessimport threadingdef find_ffmpeg():path = shutil.which("ffmpeg")if path is None:raise FileNotFoundError("ffmpeg not found. Please install it and add it to your system PATH")return pathdef unique_path(path):# If the target file already exists, append _1, _2, etc.base, ext = os.path.splitext(path)candidate, i = path, 1while os.path.exists(candidate):candidate = f"{base}_{i}{ext}"i += 1return candidatedef convert_one(ffmpeg, src, dst):# Arguments are passed as a list, so special characters in filenames are not parsed by the shell# -n means do not overwrite if the target file already existssubprocess.run([ffmpeg, "-n", "-i", src, "-vn", dst],check=True, capture_output=True)class Extractor:def __init__(self, root):self.root = rootself.events = queue.Queue()self.cancel_flag = threading.Event()self.root.after(100, self.poll_events)def start(self, files, out_dir, fmt):self.cancel_flag.clear()threading.Thread(target=self.worker, args=(files, out_dir, fmt), daemon=True).start()def worker(self, files, out_dir, fmt):# Never call tkinter widget methods in the worker thread; only push messages to the queuetry:ffmpeg = find_ffmpeg()except FileNotFoundError as e:self.events.put(("error", str(e)))returntotal = len(files)for i, src in enumerate(files, 1):if self.cancel_flag.is_set():self.events.put(("status", "Cancelled; stopping after the current file finishes"))returnname = os.path.splitext(os.path.basename(src))[0] + "." + fmtdst = unique_path(os.path.join(out_dir, name))try:convert_one(ffmpeg, src, dst)self.events.put(("progress", i / total))except subprocess.CalledProcessError:self.events.put(("error", f"Conversion failed: {src}"))self.events.put(("done", None))def poll_events(self):# The main thread periodically retrieves messages and updates the UItry:while True:kind, value = self.events.get_nowait()self.update_ui(kind, value)except queue.Empty:passself.root.after(100, self.poll_events)def update_ui(self, kind, value):# Update the progress bar and status bar here; actual widgets are provided by the UI modulepass
A few details deserve attention. First, queue.Queue is thread-safe, but tkinter widgets are not. All widget operations should be done in poll_events. Second, root.after(100, ...) polls every 100 milliseconds, refreshing progress about 10 times per second, which is sufficient for this scenario. Third, cancellation only takes effect between conversions; a running ffmpeg process will finish the current file.
Common Questions
How do you prevent the tkinter UI from freezing?
Run time-consuming tasks in a child thread. The child thread never touches UI widgets directly; it only sends messages through a queue. The main thread uses after to periodically retrieve messages and update the progress bar and status bar.
How do you detect the ffmpeg dependency?
At startup, use shutil.which("ffmpeg") to locate the executable. If it is not found, display installation instructions in the status bar and disable the convert button. Do not wait until mid-conversion to report the error, or the user may have already processed some files.
How do you handle duplicate filenames?
Check whether the output path exists before generating it; if it does, append _1, _2, and so on. Also pass the -n flag to ffmpeg, so even if the path check has a gap, existing files will never be silently overwritten.
What are the risks of recursively importing large directories?
With deep directory hierarchies or symbolic links, traversal can fall into an infinite loop. Importing thousands of files can also slow down list refreshes. It is advisable to limit recursion depth, track visited real paths, and load the file list in batches.
Data Safety Notes
- If the output directory is the same as the source directory, the UI should ask the user to confirm.
- Closing the program mid-conversion may leave incomplete audio files behind. Verify file size and playability before deleting anything.
- Before a batch conversion, do a trial run with two or three sample files.
- Files that fail to convert should remain in the list so users can investigate the cause; they should not be deleted automatically.
Conclusion and Next Steps
LLMs can generate well-structured GUI and threading code, but whether it is ready for production depends on item-by-item verification against an acceptance checklist. The original test record lacked the model version, prompt text, and environment details, so the stability of the results cannot be demonstrated. Readers can record their own test results using the checklist above, and save the prompt, generated code, and failure samples together to make it easier to compare how different models perform.
