---
title: "Friday fun: live speech to text from the terminal"
description: Pipe rec into websocat and get live speech to text in your terminal as you talk. Two CLI tools, one WebSocket, no GUI and no upload-and-wait loop.
canonical: https://lukeocodes.dev/friday-fun-live-speech-to-text-terminal
type: article
locale: en_GB
published: 2026-04-17T00:00:00.000Z
modified: 2026-04-17T00:00:00.000Z
authors:
  - Luke Oliff
section: TIL
tags:
  - TIL
  - Engineering
  - Voice AI
feed: https://lukeocodes.dev/rss.xml
search: https://lukeocodes.dev/search.json?q={query}
schema:
  - "@context": https://schema.org
    "@graph":
      - "@type": Organization
        "@id": https://ably.com/#organization
        name: Ably
        url: https://ably.com
      - "@type": WebSite
        "@id": https://lukeocodes.dev/#website
        url: https://lukeocodes.dev
        name: Luke Oliff
        alternateName: lukeocodes
        inLanguage: en
        publisher:
          "@id": https://lukeocodes.dev/authors/luke#person
        description: Personal blog and writing by Luke Oliff — developer relations, voice AI, developer experience.
        potentialAction:
          - "@type": SearchAction
            target:
              "@type": EntryPoint
              urlTemplate: https://lukeocodes.dev/blog/search?q={search_term_string}
            query-input: required name=search_term_string
      - "@type": Person
        "@id": https://lukeocodes.dev/authors/luke#person
        name: Luke Oliff
        url: https://lukeocodes.dev/authors/luke
        description: Staff engineer and Staff Tech Lead for Developer Experience at Ably. Writing about developer relations, AI, and the voice industry, from the UK.
        mainEntityOfPage: https://lukeocodes.dev/authors/luke
        givenName: Luke
        familyName: Oliff
        image: https://lukeocodes.dev/authors/luke.jpg
        jobTitle: Staff Tech Lead, Developer Experience
        worksFor:
          "@id": https://ably.com/#organization
        sameAs:
          - https://www.linkedin.com/in/lukeocodes
          - https://github.com/lukeocodes
          - https://bsky.app/profile/lukeocodes.dev
          - https://x.com/lukeocodes
          - https://hashnode.com/@lukeocodes
          - https://dev.to/lukeocodes
        knowsAbout:
          - Developer Relations
          - Developer Experience
          - Voice AI
          - Text-to-Speech
          - Answer Engine Optimisation
          - Search Engine Optimisation
          - Open Source
          - Developer Tooling
          - API Design
          - Speech-to-Text
          - Voice Agents
          - Community Building
        knowsLanguage:
          - English
        nationality: British
        alumniOf:
          - "@type": Organization
            name: The Open University
  - "@context": https://schema.org
    "@graph":
      - "@type": Organization
        "@id": https://ably.com/#organization
        name: Ably
        url: https://ably.com
      - "@type": Person
        "@id": https://lukeocodes.dev/authors/luke#person
        name: Luke Oliff
        url: https://lukeocodes.dev/authors/luke
        description: Staff engineer and Staff Tech Lead for Developer Experience at Ably. Writing about developer relations, AI, and the voice industry, from the UK.
        mainEntityOfPage: https://lukeocodes.dev/authors/luke
        givenName: Luke
        familyName: Oliff
        image: https://lukeocodes.dev/authors/luke.jpg
        jobTitle: Staff Tech Lead, Developer Experience
        worksFor:
          "@id": https://ably.com/#organization
        sameAs:
          - https://www.linkedin.com/in/lukeocodes
          - https://github.com/lukeocodes
          - https://bsky.app/profile/lukeocodes.dev
          - https://x.com/lukeocodes
          - https://hashnode.com/@lukeocodes
          - https://dev.to/lukeocodes
        knowsAbout:
          - Developer Relations
          - Developer Experience
          - Voice AI
          - Text-to-Speech
          - Answer Engine Optimisation
          - Search Engine Optimisation
          - Open Source
          - Developer Tooling
          - API Design
          - Speech-to-Text
          - Voice Agents
          - Community Building
        knowsLanguage:
          - English
        nationality: British
        alumniOf:
          - "@type": Organization
            name: The Open University
      - "@type": BlogPosting
        "@id": https://lukeocodes.dev/friday-fun-live-speech-to-text-terminal#article
        headline: "Friday fun: live speech to text from the terminal"
        alternativeHeadline: "Friday fun: live speech to text from the terminal"
        description: Pipe rec into websocat and get live speech to text in your terminal as you talk. Two CLI tools, one WebSocket, no GUI and no upload-and-wait loop.
        datePublished: 2026-04-17T00:00:00.000Z
        dateModified: 2026-04-17T00:00:00.000Z
        url: https://lukeocodes.dev/friday-fun-live-speech-to-text-terminal
        mainEntityOfPage: https://lukeocodes.dev/friday-fun-live-speech-to-text-terminal
        inLanguage: en
        author:
          - "@id": https://lukeocodes.dev/authors/luke#person
        isPartOf:
          "@id": https://lukeocodes.dev/#website
        keywords: TIL, Engineering, Voice AI
        articleSection: TIL
        about:
          - "@type": Thing
            name: Voice AI
        abstract: "Friday fun: I got tired of recording test audio files, uploading them, and waiting for a response before I could see if my STT integration was working. There had to be a faster loop."
        speakable:
          "@type": SpeakableSpecification
          cssSelector:
            - .post-tldr
            - h1
        image: https://lukeocodes.dev/blog/friday-fun-live-speech-to-text-terminal/hero.png
        wordCount: 614
        timeRequired: PT4M
        publisher:
          "@id": https://ably.com/#organization
      - "@type": BreadcrumbList
        itemListElement:
          - "@type": ListItem
            position: 1
            name: Home
            item: https://lukeocodes.dev
          - "@type": ListItem
            position: 2
            name: Writing
            item: https://lukeocodes.dev/blog
          - "@type": ListItem
            position: 3
            name: "Friday fun: live speech to text from the terminal"
            item: https://lukeocodes.dev/friday-fun-live-speech-to-text-terminal
---

[Luke Oliff.](/)

- [Blog](/blog)
- [CV](/cv)
- [Uses](/uses)
- [User manual](/user-manual)
- [Living with ADHD](/living-and-working-with-adhd)
- [RSS](/rss.xml)

[Luke Oliff · Writing](/blog)

# Friday fun: live speech to text from the terminal

Apr 2026 · [TIL](/blog/category/til) · 4 min read · [Luke Oliff](/authors/luke)

Friday fun: I got tired of recording test audio files, uploading them, and waiting for a response before I could see if my STT integration was working. There had to be a faster loop.

Turns out there is. Two CLI tools and a pipe operator give you a live speech-to-text pipeline that prints transcripts to the terminal as you speak.

```bash
rec -q -t raw -r 16000 -e signed -b 16 -c 1 - | websocat wss://api.deepgram.com/v1/listen?encoding=linear16&sample_rate=16000
```

Speak into your mic. Watch the transcript appear.

## How it works

`rec` (part of the sox suite) captures audio from the default microphone. The flags tell it exactly what format to use: raw PCM at 16kHz, signed 16-bit samples, single channel. The `-` at the end means write to stdout instead of a file.

That raw audio stream gets piped directly into `websocat`, a command-line WebSocket client. It opens a persistent connection to the STT API's streaming endpoint and forwards every byte it receives on stdin as a binary WebSocket message.

The STT API processes the audio in real time and sends back JSON transcription results. Those print to your terminal as they arrive. No files, no uploads, no clicking around a dashboard.

## Why this matters for SDK work

I maintain SDKs for this kind of API. The debugging loop for a streaming integration usually goes: write code, build, run, speak, check the output, edit the code, repeat. That loop takes a couple of minutes per iteration.

The `rec` + `websocat` pipeline collapses it to zero lines of SDK code. You can test whether the API accepts your audio format before you write a single line of integration code. You can check latency by watching how fast words appear after you say them. You can verify that reconnection logic works by killing the websocat process and watching the API surface handle the dropped connection.

It is the fastest possible way to answer "does my audio format work with this API".

## What I learned building it

The raw PCM format flag order matters. `sox` expects the encoding before the bit depth. `-e signed -b 16` is the correct order. Swap them and you get a silent error because sox parses `-b` as a command, not a format flag.

The sample rate needs to match what the API expects. Most streaming STT APIs accept 8kHz and 16kHz. 16kHz gives better accuracy for speech. The `-r 16000` flag matches the default rate for most voice APIs.

Binary WebSocket messages are more efficient than base64-encoded ones. `websocat` detects raw binary input and sends it as binary frames automatically. No encoding overhead.

### FAQ

#### Do I need to install anything?

`rec` comes with sox (`brew install sox`). `websocat` is `cargo install websocat` or `brew install websocat`. Both are small, fast, and have no dependencies beyond what the package manager handles.

#### Can I change the microphone source?

`rec` picks the default system input. On macOS you can override it with `rec -t coreaudio "Built-in Microphone"`. On Linux use `rec -t alsa "hw:0,0"`. Check your available devices with `rec -D`.

#### What happens if the WebSocket drops?

The pipe breaks and both processes exit. The STT API treats the dropped connection as an end of stream. Any transcription results that were in flight when the connection dropped are lost. For a testing pipeline this is fine. Just run the command again.

#### Can I use this with a TTS API instead?

You would need a different approach. TTS receives text and outputs audio. You would pipe text into websocat and capture the binary audio output into a file or speaker. The pattern is similar but the direction reverses.

[← Newer: Five WebSocket patterns for real-time audio streaming](/five-websocket-patterns-real-time-audio-streaming)

[All posts](/blog) →

## Search this site

`GET https://lukeocodes.dev/search.json?q=<words>` returns matching posts as JSON, each with its page URL and its markdown URL. Add `&limit=<1-50>` for more than 10. How it works: [/blog/search](https://lukeocodes.dev/blog/search.md).

```sh
curl "https://lukeocodes.dev/search.json?q=developer+relations"
```

---

© 2026 Luke Oliff. Posts live at the root of this site.

- [GitHub](https://github.com/lukeocodes)
- [LinkedIn](https://www.linkedin.com/in/lukeocodes)
- [X](https://x.com/lukeocodes)
- [Bluesky](https://bsky.app/profile/lukeocodes.dev)
- [Email](mailto:luke@lukeoliff.com)
- [RSS](/rss.xml)

## Cookies

This site sets one analytics cookie, from Google Analytics, and only in a browser that accepts the cookie banner. A client that does not run scripts sets no cookies, so there is nothing to accept or decline here.

[Cookie policy](/cookies)
