Talking to AI before it was cool
I can talk a lot quicker than I can write. I always thought about using dictation to increase productivity in writing code, but so far it hasn’t really been possible. Code is highly structured text which is really hard to dictate. Try dictating this:
swaymsg -t get_outputs | jq '.[] | {name, make, rect}'
With large language models this has changed, since they take inputs mostly in the form of textual descriptions, not unstructured text. This is much quicker to say than to type out.
This idea prompted me to hack together a tool for dictation under Linux, since I couldn’t find any good existing options. This has been made somewhat superfluous by GPT-4o, but I thought it was worth sharing nonetheless, even if it’s just to show how amazingly simple it is to put together things like this, these days.
Implementation
The architecture is very straightforward. There’s a flask app that I run at startup, which accepts a /state
command telling you whether it’s currently recording or not. It also accepts /start
and /end
commands to start and end recordings. The /end
command returns a json with a result
field, containing the text which was said while recording.
There is a wrapper around that which starts recording if not already running, and stops recording otherwise. If it just stopped recording, it puts the transcribed text into my clipboard.
The text is recorded using pyaudio
and transcribed using AI magic. Essentially:
The tricky bits were actually unrelated to AI. One thing was capturing the audio in a separate thread, so that it wouldn’t block the flask app’s worker thread. This was easily done using the threading module, no doubt because some brain-bending work done by PyAudio to evade the GIL:
A second was to play a sound when recording is started and stopped to give confirmation that the system is working. I did this using PyGame because it’s the most reliable way I know of to play sound on Linux. It pulls in lots of unneeded dependencies, but oh well.
Repo link here.
Usefullness
It’s so fucking good. It is very useful for talking to chat GPT because I don’t need to structure my thoughts very clearly and the language model will usually deal with it just fine. With LLMs, often I get time savings if I can get the language model to find me a bit of documentation 10 seconds quicker than I could myself. If I was interacting with it using text, the time spent typing out my query would negate the benefit. This dictation tool takes the friction out of the process, which means that I get to have a lot of small time savings, which I wouldn’t otherwise have. Also asking the computer questions by voice doesn’t break flow as much as looking for information on the internet would.
I am not sure about the use in other writing. I need to think more carefully about what I want to write, which makes it feel less fluid. Also, the ease of producing lots of text gives an incentive to be less concise, which is a bad thing. But I think with practice I might see productivity gains here as well.
Of course, I cannot use this tool in an open plan office, so for now it must be confined to the realm of personal projects.