LLM Code Generation in Practice: Building a Desktop Video-to-Audio Converter with AI
This article tests how well a large language model can generate a complete Python and tkinter desktop tool for batch extracting audio from video. It covers requirement design, prompt strategy, generated code quality, threading and ffmpeg handling, common pitfalls, and follow-up verification. Readers will learn practical lessons for using AI in GUI tool development, including how to define requirements clearly and review generated code effectively.
1. Background: Where LLM Programming Capabilities Stand
In recent years, large language models have improved in code generation much faster than many expected. Public benchmark results show that leading open-source and closed-source models have approached, and in some areas reached, the level of mid-level human engineers on programming tasks. This is especially true for engineering tasks where requirements are clear and boundaries are well defined; generated code can often pass compilation and runtime checks on the first attempt.
But benchmark scores are one thing, and performance in real development scenarios is another. As a developer, I care most about three practical questions:
- Can the generated code run directly, rather than requiring extensive manual repair?
- Are complex requirements fully covered, rather than only the simplest skeleton being implemented?
- Are engineering details reliable, such as exception handling, thread safety, and boundary conditions?
To verify these points, I designed a representative test task: ask an AI model to build a “video and audio batch extraction tool” in Python. This kind of task involves GUI programming, external process calls, multithreading, and other typical engineering concerns, making it a good test of the model’s real capabilities.
2. Requirement Design: Deliberately Including Common Beginner Traps
To avoid a simple “toy-level” test, I stacked multiple constraints into the requirement list:
- Support common video formats and export mainstream audio formats such as MP3 and WAV;
- Use Python and the tkinter framework to build the desktop interface;
- Include a file import list and input/output format settings;
- Provide complete functions such as file import, conversion execution, and program exit;
- Keep the interface layout reasonable and the application responsive;
- Must include a progress bar and status bar, show prompts on errors, and must not freeze the UI.
The last item is key. Anyone familiar with GUI programming knows that “must not freeze” alone can rule out many lazy generation approaches. The reason is that tkinter’s event loop runs in the main thread. If a time-consuming batch conversion task is written directly in the main thread, the interface will freeze completely, resulting in a poor user experience. The correct approach is:
import threadingdef start_conversion(self):# Run the time-consuming task in a worker thread to avoid blocking the main thread's UI event loopt = threading.Thread(target=self.run_conversion, daemon=True)t.start()def run_conversion(self):for i, file in enumerate(self.file_list):self.convert(file)progress = (i + 1) / len(self.file_list) * 100# Update the UI in a thread-safe wayself.root.after(0, self.update_progress, progress)
The detail here is that a worker thread cannot directly manipulate tkinter widgets. Updates must be scheduled back to the main thread through root.after() or a queue mechanism. Whether this point is handled correctly is a dividing line between “can write code” and “can write engineering code.”
3. Hands-On Test: From Prompt to Finished Tool
3.1 Prompt Writing Strategy
I organized the requirements above into a structured prompt and sent it in one shot, without step-by-step follow-up questions. In practice, for tasks with clear boundaries, providing a complete and explicit requirement list at once is more likely to produce high-quality results than multiple scattered conversations. The prompt should include: technology stack constraints, feature list, non-functional requirements such as performance and exception handling, and acceptance criteria.
3.2 Analysis of the Generated Result
After the code was generated, I focused on checking several areas:
Functional completeness: Every item in the requirement list was implemented, with no omissions. More surprisingly, the generated result proactively added several details I had not mentioned:
- Recursively scan subdirectories, so files do not need to be added one by one during batch import;
- Automatically complete a mapping table of common video and audio formats;
- Automatically append a number to output files with the same name to avoid overwriting existing files;
- Check whether ffmpeg is installed before conversion, and give a clear prompt instead of crashing directly when it is missing.
Code quality: Syntax validation passed on the first attempt, and the program ran with zero errors. The ffmpeg call used subprocess and correctly captured stderr. When conversion failed, the status bar displayed the specific error message instead of failing silently.
Threading model: As mentioned earlier, the conversion task was correctly placed in a worker thread, the progress bar was updated through a scheduling mechanism, the interface remained responsive during conversion, and the cancel button also worked properly.
4. Review of Key Pitfalls
The success of this test was not accidental. I summarized several points worth noting when using AI to assist with GUI tool development:
1. Thread blocking. Any time-consuming operation, such as file I/O, network requests, or external process calls, must leave the main thread. When giving requirements to AI, you should explicitly state “do not freeze the UI”; otherwise, the model is very likely to generate the simplest serial implementation.
2. External dependency detection. When calling external tools such as ffmpeg, use shutil.which() before the task starts to check whether the executable exists, fail early, and give a friendly prompt:
import shutilif shutil.which("ffmpeg") is None:messagebox.showerror("Error", "ffmpeg was not detected. Please install it and configure the environment variable first.")return
3. Exceptions must be visible. Silent failure is one of the worst problems in desktop tools. In a batch task, failure of a single file should not interrupt the entire process. Instead, it should be recorded in the status bar or log area, and the number of successes and failures should be summarized at the end.
4. Cover boundary conditions comprehensively. Output file name conflicts, corrupted input files, and paths containing Chinese characters or spaces are details that the model can usually handle properly once they are explicitly called out in the prompt.
5. Follow-Up Verification: Comprehension Matters Too
After the code generation was complete, I asked a follow-up question: “Is the output directory after conversion the current program directory by default?” The model accurately answered the default behavior and pointed to the corresponding configuration location in the code. This showed that it had complete “memory” and understanding of the context of the generated code, rather than mechanically assembling snippets. This ability to support follow-up questions and iteration is exactly where the real value of AI-assisted development lies.
6. Conclusion
This hands-on test made my judgment of large language model programming capabilities more concrete: for utility software with clear requirements and moderate scope, AI can already handle the bulk of coding from zero to one, while developers shift their energy toward requirement definition, code review, and architecture oversight. A reasonable division of labor in human-AI collaboration is taking shape, and developers who know how to use AI will have an increasingly obvious efficiency advantage. For developers who want to try this approach, my advice is: write requirements clearly, declare pitfalls in advance, and maintain a habit of reviewing generated results. These three points determine the final quality of AI-assisted development.
