From mumbled voice notes to tidy paragraphs in two API calls

Dictation tools have become a favourite weekend project: hold a key, speak, release, and the transcribed text appears in whatever app you are using. Scripted desktops on macOS, tray utilities on Windows and small Linux daemons all follow the same pattern, usually with a hosted speech recognition model doing the transcription. The results are impressive, but raw transcripts still read like speech: "um", repeated words, sentences that change direction halfway and punctuation that does not match what you meant.
This guide shows how to add a second stage that turns a transcript into clean, ready-to-paste text using a language model. It is for developers and power users who already have, or want to build, a push-to-talk dictation tool. We cover the two-stage architecture, a cleanup prompt that does not change your meaning, working Python code against the keyless free-ai endpoint on this site, and the privacy and latency trade-offs. Note that free-ai handles text only; the speech recognition step needs a separate service or local model.
Frequently asked questions
Why not just use the transcript as it is?
For quick chat messages the raw transcript may be fine. For emails, documents and notes, fillers, repetitions and missing paragraph breaks make it look careless. A cleanup pass fixes these in a second or two without you retyping anything.
Can free-ai transcribe audio?
No. The keyless endpoint is text only. Use a speech recognition model for transcription, either a hosted one or a local one, and send the resulting text to the language model for cleanup.
Will the language model change what I said?
It can if the prompt is loose. A strict prompt that forbids adding information, keeps your wording where possible and only fixes fillers, grammar and punctuation keeps changes small. Always keep the raw transcript available in case you need it.
How does cleanup differ from summarization?
Cleanup keeps all your content and only improves form. Summarization shortens and selects. Mixing the two by accident is a common failure; the prompt should state clearly that nothing is to be removed except fillers and repetitions.
Is a local speech model good enough?
Modern open speech recognition models running locally are accurate for clear speech in widely spoken languages, especially on recent hardware. Hosted services can be faster on modest machines. Accents, noise and technical vocabulary are where differences show most.
What about technical terms and names?
Speech recognition often mishears product names, code identifiers and unusual surnames. Supply a short glossary in the cleanup prompt so the language model can correct likely mistakes to the right spelling.
How fast is the whole pipeline?
With short utterances, transcription and cleanup can each take well under a couple of seconds on fast services. Long dictations take longer. Streaming the cleanup output and pasting at the end is a reasonable compromise.
Step by step
- Capture audio on a hotkey — Record from the microphone while a key is held, and save a short WAV or compressed file when it is released.
- Transcribe the audio — Send the file to a speech recognition service or run a local model, and get back plain text.
- Clean the transcript — Send the text to the chat completions endpoint with a strict cleanup prompt and an optional glossary.
- Paste into the active app — Put the cleaned text on the clipboard and simulate a paste, keeping the raw transcript in a log.
- Review and tune — Read a week of outputs, note recurring errors and adjust the glossary and prompt.
The two-stage architecture
A dictation pipeline has two distinct jobs. Speech recognition turns sound into words. Language cleanup turns spoken words into written text. Combining them in one model is possible with some multimodal systems, but keeping them separate lets you choose the best tool for each, swap providers independently and debug each stage on its own.
The flow is simple: a hotkey starts recording, releasing it stops recording and sends the audio for transcription, the transcript goes to a language model with a cleanup prompt, and the result is pasted into the active window. On macOS, automation tools can watch for a key and drive the clipboard; on other systems, a small background script does the same.
Why separation helps
When output is wrong, you can look at the raw transcript and immediately see whether the error came from hearing or from rewriting. That makes tuning far faster than with a single opaque step.
Keep both versions
Store the raw transcript next to the cleaned text in a local log. If the cleanup ever drops or alters something important, you still have what you actually said.
Choosing a speech recognition option
Your options are hosted speech-to-text APIs or a local open model. Hosted services are quick to set up and fast on any machine, but they receive your audio. Some inference providers, Groq among them, have offered hosted speech recognition alongside their language models; check their current documentation for which audio models and limits apply. This site is not affiliated with Groq, and its keyless endpoint does not process audio.
Local models keep audio on your machine, which matters for private notes and meetings. On recent laptops with a decent GPU or a fast neural engine, small and medium open speech models transcribe short clips quickly. On older hardware, the larger models may be too slow for comfortable push-to-talk use.
Language and accent coverage
Test with your own voice, in your own environment, in each language you dictate in. Accuracy on public benchmarks says little about a strong accent in a noisy kitchen.

Writing a cleanup prompt that respects your words
The cleanup prompt is the heart of the second stage. It must be strict, because language models love to improve text, and improvements can quietly change meaning. Tell the model exactly what to fix and what never to touch. Ask for the cleaned text only, without quotes or commentary, so it can be pasted directly.
Spoken commands
Many people say things like "new paragraph" or "comma" while dictating. Add a line to the prompt listing which spoken commands to convert, so they are not left in the text as words.
Self-corrections
Speakers often correct themselves: "send it Tuesday, no, Wednesday". Instruct the model to keep only the corrected version when the correction is explicit, and to leave the sentence alone when it is ambiguous.
- Remove fillers such as um, uh, like and you know
- Remove accidental repetitions and false starts
- Fix punctuation, capitalization and obvious grammar slips
- Add paragraph breaks where the topic changes
- Keep the speaker's wording and tone otherwise
- Never add facts, greetings or sign-offs that were not spoken
- Apply glossary spellings for names and technical terms
The cleanup call in Python
Here is the cleanup stage as a function. It sends the transcript to the keyless endpoint with a strict system prompt and a glossary, at low temperature to keep edits conservative. The function works with any OpenAI-compatible provider: change the base URL, key and model name to use another one.
Guard against runaway edits
Compare the word count of the cleaned text with the raw transcript. If the cleaned version is much shorter or longer, something went wrong; fall back to the raw text with basic punctuation and flag it in the log.
from openai import OpenAI
client = OpenAI(base_url="https://api.apifreegroqkey.com/v1", api_key="free")
SYSTEM = """You clean up dictated text.
Remove fillers (um, uh, like, you know), repetitions and false starts.
Fix punctuation, capitalization and obvious grammar slips. Add paragraph breaks at topic changes.
Convert spoken commands: 'new paragraph' -> blank line, 'comma' -> ',', 'full stop' -> '.'.
Keep the speaker's words and tone. Do not add, remove or summarize content.
Output only the cleaned text."""
def clean(transcript, glossary=()):
extra = ""
if glossary:
extra = "\nCorrect spellings to use: " + ", ".join(glossary)
r = client.chat.completions.create(
model="free-ai",
messages=[
{"role": "system", "content": SYSTEM + extra},
{"role": "user", "content": transcript},
],
temperature=0.1,
max_tokens=2000,
)
return r.choices[0].message.content.strip()
raw = "um so I think we should uh move the the meeting to Tuesday no Wednesday new paragraph also ask Priya about the kubernetes migration"
print(clean(raw, glossary=["Priya", "Kubernetes"]))
Gluing it together on the desktop
The final piece is a small script triggered by your hotkey tool. It records audio to a temporary file, calls your transcription service, passes the text to clean(), copies the result to the clipboard and triggers a paste. On macOS, an automation tool can run the script and send the paste keystroke; on Linux and Windows, clipboard utilities and key simulation libraries do the same.
Keep the hotkey handler thin and let the script do the work, so a slow network call never blocks your keyboard. Show a small indicator while recording and processing, so you know when it is safe to keep typing.
Handle failures gracefully
If transcription fails, play a short sound and keep the audio file so you can retry. If cleanup fails or times out, paste the raw transcript instead of nothing. A dictation tool that loses your words is worse than no tool.
Latency: making it feel instant
Push-to-talk feels best when text appears within a couple of seconds of releasing the key. Transcription time grows with audio length, while cleanup time grows with the amount of text. For short notes both are quick; for minute-long dictations you may wait longer.
Several tactics help. Use a smaller, faster speech model for short clips. Skip cleanup for very short utterances where there is little to fix. Keep the cleanup prompt compact so prefill is quick. Our explainer on time to first token describes why prompt size affects the wait before output starts.
Respect the rate limit
The keyless endpoint allows one request per second per IP with small bursts, which is plenty for personal dictation. If you share a tool across an office behind one IP, everyone shares that limit, and a keyed provider makes more sense.

Privacy considerations
Dictation often contains personal and work information. Every hosted step sees what you say: the transcription service hears your audio, and the cleanup service reads your text. The keyless endpoint is stateless and does not keep conversations between calls, but each request leaves a technical log entry with time, IP, User-Agent, country, endpoint, status, latency, sizes and token counts.
For sensitive material, consider running both stages locally. A small local language model can handle cleanup well, because the task depends almost entirely on the input text. Our article on routing tasks between models shows how to send private requests to a local model and others to a hosted one.
Do not dictate secrets
Passwords, recovery codes and client confidential material should never pass through a dictation pipeline that uses third-party services, however convenient it is.
Where a stronger model helps
A mid-sized model like free-ai, an independent open-weight model of about 35B parameters, handles routine cleanup well in common languages. For long, rambling dictations that need restructuring into a clear document, or for languages with less training data, a larger commercial model will usually produce noticeably better results.
A useful split is to clean every utterance with a fast, cheap model and offer an optional second action that rewrites a longer note into polished prose with a stronger one. That keeps everyday dictation quick and reserves the heavier model for moments when structure really matters.
Tone presets
Some users add presets such as "casual chat", "professional email" and "meeting notes". Each preset adds one line to the system prompt. Keep the default preset conservative so ordinary dictation never surprises you.

Tuning over the first week
Dictation quality improves quickly with small adjustments. Read your log at the end of each day for the first week. Add misheard names to the glossary, tighten the prompt where the model over-edits and loosen it where fillers slip through. Most people find the prompt settles after a handful of changes and then needs little attention.
If you also build voice interfaces for other people, the same cleanup ideas apply to handling noisy input from players or customers; our guide to LLM dialogue in games discusses that side.
Track a few simple numbers
Count how often you edit the pasted text by hand and how often the guard falls back to the raw transcript. If either number stays high after a week, the speech model or the prompt needs a bigger change.
Send a request to the keyless free-ai endpoint from the home page and see how it fits your project, no sign-up needed.
Read also
- How to Build a Document Q&A Service With FastAPI and an LLM API
- What Is Graph RAG, and When Does It Beat Plain Vector Search?
- LangChain vs the Plain OpenAI SDK: Which Should Your LLM App Use?
- Can an LLM Predict Markets or Conflicts? The Limits of AI Forecasts
- Should Simple Tasks Go to a Smaller Model? LLM Routing Explained