My own speech-to-text server, reachable over Tailscale
I talk to my computers a lot more than I used to. Most of what I write now starts as dictation, and I clean it up after.
It started on my desktop. I use OpenWhispr with NVIDIA’s Parakeet model running right on the graphics card: hold a key, talk, and the text shows up. It’s quick, and nothing leaves the machine.
Then I wanted the same thing when I’m not sitting at that desk. Without a decent graphics card, local dictation is slow. The cloud services are fast, but then my voice goes to somebody else’s server, and that’s the part I wanted to avoid.
The desktop already has the graphics card, so I put a small server on it. It takes audio, sends back text, and is only reachable over my Tailscale network. Since I started using it, a typical clip comes back as text in about 0.6 seconds.
What you need
- A Windows PC with a decent graphics card that stays on. Mine has an RTX 3060 with 12 GB.
- Tailscale on that PC and on every machine that will use it.
- uv to handle Python.
- A dictation app that can talk to an “OpenAI-compatible” transcription server. I use OpenWhispr, the same app I use locally.
The model
I’m using Parakeet TDT 0.6B v2. It only does English, but it’s small and very accurate for its size.
The nice surprise was onnx-asr. It runs Parakeet through ONNX Runtime, so there’s no PyTorch and no CUDA toolkit to install. With the DirectML package it uses the graphics card on Windows, and if that fails it falls back to the processor.
Step 1: set up the project
In PowerShell, in your user folder:
uv init parakeet-server
cd parakeet-server
uv python pin 3.12
uv add "onnx-asr[hub]" onnxruntime-directml fastapi uvicorn python-multipart av numpy
av is there to read whatever audio format the app sends (WAV, WebM, M4A, MP3) and turn it into what the model wants.
Step 2: the server
This is the whole thing, a little trimmed. Save it as server.py:
import io, os, time, logging
import av
import numpy as np
import onnx_asr
from fastapi import FastAPI, File, Form, Header, HTTPException, UploadFile
from fastapi.responses import JSONResponse, PlainTextResponse
MODEL_NAME = os.environ.get("PARAKEET_MODEL", "nemo-parakeet-tdt-0.6b-v2")
API_KEY = os.environ.get("PARAKEET_API_KEY", "")
SR = 16_000
logging.basicConfig(level=logging.INFO, format="%(asctime)s %(message)s")
log = logging.getLogger("parakeet")
try:
model = onnx_asr.load_model(MODEL_NAME, providers=["DmlExecutionProvider", "CPUExecutionProvider"])
PROVIDER = "DirectML (GPU)"
except Exception as e:
log.warning("GPU load failed (%s), using CPU", e)
model = onnx_asr.load_model(MODEL_NAME, providers=["CPUExecutionProvider"])
PROVIDER = "CPU"
# Warm-up, so the first real request isn't the slow one.
model.recognize(np.zeros(SR * 2, np.float32), sample_rate=SR)
app = FastAPI()
def check_key(authorization):
if API_KEY and authorization != f"Bearer {API_KEY}":
raise HTTPException(status_code=401, detail="Invalid or missing API key")
def decode(data: bytes) -> np.ndarray:
"""Any audio file in, 16 kHz mono out."""
with av.open(io.BytesIO(data)) as container:
stream = next(s for s in container.streams if s.type == "audio")
resampler = av.AudioResampler(format="flt", layout="mono", rate=SR)
chunks = []
for frame in container.decode(stream):
for out in resampler.resample(frame):
chunks.append(out.to_ndarray().reshape(-1))
for out in resampler.resample(None):
chunks.append(out.to_ndarray().reshape(-1))
return np.concatenate(chunks).astype(np.float32) if chunks else np.zeros(0, np.float32)
@app.get("/health")
def health():
return {"status": "ok", "model": MODEL_NAME, "provider": PROVIDER}
@app.get("/v1/models")
def models(authorization: str | None = Header(default=None)):
check_key(authorization)
return {"object": "list", "data": [{"id": MODEL_NAME, "object": "model", "owned_by": "local"}]}
@app.post("/v1/audio/transcriptions")
async def transcribe(
file: UploadFile = File(...),
response_format: str = Form(default="json"),
authorization: str | None = Header(default=None),
):
check_key(authorization)
try:
audio = decode(await file.read())
except Exception as e:
raise HTTPException(status_code=400, detail=f"Could not decode audio: {e}")
t = time.perf_counter()
text = model.recognize(audio, sample_rate=SR).strip() if audio.size else ""
log.info("audio %.1fs | asr %.0fms", audio.size / SR, (time.perf_counter() - t) * 1000)
if response_format == "text":
return PlainTextResponse(text)
return JSONResponse({"text": text})
if __name__ == "__main__":
import uvicorn
uvicorn.run(app, host=os.environ.get("PARAKEET_HOST", "127.0.0.1"),
port=int(os.environ.get("PARAKEET_PORT", "5092")))
The first time it starts, it downloads the model from Hugging Face. After that it loads in 5 to 15 seconds.
The default address is 127.0.0.1 on purpose, so out of the box nothing else can reach it. The settings (address, port and API key) come from environment variables, but you don’t set those yourself: the start script in the next step does it every time it launches the server.
Step 3: only listen on Tailscale
This is my favourite part. Instead of listening on every network card (0.0.0.0), the server only listens on the PC’s Tailscale address, the one that starts with 100.. Devices on my home Wi-Fi can’t reach it unless they’re on my tailnet, and there’s no port forward, so the internet can’t either. My own devices reach it from anywhere through Tailscale.
I added an API key anyway, so a device on the tailnet still needs the key to use it. Make one like this:
uv run python -c "import secrets; print(secrets.token_urlsafe(24))" | Set-Content api-key.txt
Keep that file to yourself. You’ll paste the key into your dictation app later.
Then save this as start-server.ps1 in the same folder. It asks Tailscale for the PC’s address, starts the server on it, and starts it again if it ever stops:
$dir = $PSScriptRoot
$tailscale = 'C:\Program Files\Tailscale\tailscale.exe'
$env:PARAKEET_API_KEY = (Get-Content (Join-Path $dir 'api-key.txt') -Raw).Trim()
$env:PARAKEET_PORT = '5092'
$log = Join-Path $dir 'server.log'
while ($true) {
$ip = $null
while (-not $ip) {
$ip = (& $tailscale ip -4 2>$null | Select-Object -First 1)
if (-not $ip) { Start-Sleep 10 }
}
$env:PARAKEET_HOST = $ip.Trim()
"$(Get-Date -Format s) starting on $($env:PARAKEET_HOST):5092" | Add-Content $log
& "$env:USERPROFILE\.local\bin\uv.exe" run --project $dir python (Join-Path $dir 'server.py') 2>&1 |
ForEach-Object { "$_" } | Out-File -Append -Encoding utf8 $log
"$(Get-Date -Format s) server exited, restarting in 15s" | Add-Content $log
Start-Sleep 15
}
The script expects uv in its default install spot (%USERPROFILE%\.local\bin\uv.exe). If you installed it another way, run (Get-Command uv).Source to find it and change that line.
Step 4: start it at login
I run it from Task Scheduler so it starts when I log in, with no window hanging around. Something like this, in PowerShell:
$script = "$env:USERPROFILE\parakeet-server\start-server.ps1"
$action = New-ScheduledTaskAction -Execute 'powershell.exe' `
-Argument "-NoProfile -WindowStyle Hidden -ExecutionPolicy Bypass -File `"$script`""
$trigger = New-ScheduledTaskTrigger -AtLogOn -User $env:USERNAME
$settings = New-ScheduledTaskSettingsSet -AllowStartIfOnBatteries -ExecutionTimeLimit ([TimeSpan]::Zero)
Register-ScheduledTask -TaskName 'Parakeet Speech Server' -Action $action -Trigger $trigger -Settings $settings
Useful commands for later:
- Stop it:
Stop-ScheduledTask 'Parakeet Speech Server', then end thepython.exeprocess. - Start it:
Start-ScheduledTask 'Parakeet Speech Server'. - New key: replace
api-key.txtand restart the task.
Step 5: check it works
From another machine on your tailnet:
curl http://your-pc.your-tailnet.ts.net:5092/health
You should see "provider": "DirectML (GPU)". If it says CPU, it still works, just slower.
Then send it some real audio:
curl http://your-pc.your-tailnet.ts.net:5092/v1/audio/transcriptions \
-H "Authorization: Bearer YOUR-KEY" \
-F [email protected]
If the other machine can’t connect at all, check that Windows Firewall isn’t blocking Python on that address.
Step 6: point your dictation app at it
In OpenWhispr I set the base URL to:
http://your-pc.your-tailnet.ts.net:5092/v1
Two things tripped me up here:
- Use the full Tailscale name. OpenWhispr rejected the short name (just
your-pc), but the full.ts.netname and the100.x.x.xaddress both work. - The API key box is hard to find. It doesn’t show up in the “local” or “self-hosted” setup, only under the cloud provider setup.
OpenWhispr can also post-process the text after it comes back, to tidy punctuation or fix the odd misheard word. That’s optional, and separate from the speech-to-text this server does.
How fast is it?
The server logs how long each request takes (not what was said), so I pulled the numbers from the time I’ve been using it:
- Median time to turn speech into text: 0.6 seconds.
- 9 out of 10 came back in under a second.
- My longest clip was almost a minute of talking. It took 1.3 seconds.
A couple of clips took much longer, one about 20 seconds. I haven’t pinned down why yet. My guess is the graphics card was busy with something else at that moment, but I haven’t proven it.
Was it worth it?
Yes. It’s maybe a hundred lines of code and a script, and it runs on hardware I already had. Now I get fast dictation wherever I am, and my voice stays in my house.
If I did it again, I’d add the restart loop from day one, and I’d make the server log where each request came from, so I could tell which machine was talking to it.