Python Speech to Text Integration With Streaming Audio Sources
Learn the three-layer architecture every Python streaming speech system needs.

A batch transcription job processes a complete audio file, but a streaming session has to produce usable text while the speaker is still talking. That difference is architectural. Real-time speech recognition means you capture audio from a microphone or stream, push it to an API in chunks, and show results as they arrive, so it's a pipeline rather than a single request and response. The budget for that pipeline is unforgiving: voice-to-voice interactions need to stay under 800 milliseconds round-trip across speech-to-text, the language model, and text-to-speech combined, which leaves the STT layer only a sliver of that window.
Whisper is the clearest illustration of why this gap matters. It remains the most widely used open-source model and sets the bar for multilingual accuracy, but it was not built for real-time transcription, since its encoder-decoder Transformer architecture chops audio into 30-second chunks and feeds a log-Mel spectrogram to the encoder, a design tuned for getting a complete segment right, not for emitting words as they're spoken. That mismatch between a state-of-the-art model and a real-time requirement is what spawned an entire ecosystem of workarounds, wrapper libraries, and competing commercial APIs, which the rest of this piece maps layer by layer.
The three-layer model every Python streaming STT pipeline must implement
Every working real-time STT pipeline in Python needs three distinct layers, and if any one of them is weak, it degrades the whole system no matter how good the underlying model is. The first layer is audio capture: getting raw audio into the right format before transcription ever starts. Nearly every production API expects PCM16 mono audio at 16 kHz, a constraint so universal that it dictates how the capture code gets configured from the very first line. The format flag, channel count, sample rate, and buffer size chosen at capture time aren't incidental, because they decide whether anything downstream can parse the audio at all.
The second layer is transport: moving that audio to the transcription engine incrementally, over a connection that stays open for the duration of the session rather than closing after a single request. Cloud providers handle this over WebSocket or gRPC rather than conventional HTTP, and Google Cloud Speech-to-Text's streaming mode is gRPC-only. SDKs handle most of the connection plumbing, but you still have to pick a chunk size, and roughly 100 milliseconds per chunk is a reasonable place to start. This layer is also where non-microphone sources enter the picture: a method like client.stream() accepts raw audio bytes or any iterable that yields PCM chunks, so a telephony bridge, a file stream, or an RTMP feed piped through FFmpeg all connect exactly the same way a live microphone would.
The third layer is incremental result handling, the logic that acts on partial and final transcripts as they come back from the engine. This is where end-of-turn detection lives: deciding when a speaker has actually stopped talking is a consequential design choice that belongs here, not in capture or transport. Get the first two layers right and the third layer still has to make a judgment call about silence, tone, and timing, and that judgment call is what separates a pipeline that feels responsive from one that feels like talking to a very polite answering machine.
Capturing and formatting audio correctly in Python
A misconfigured audio stream doesn't throw an error; it just produces bytes that parse fine and transcribe into nonsense, which is a worse failure mode than a crash because nothing tells the developer where to look. PyAudio, the standard library for this job, wraps PortAudio and requires explicit configuration on every stream: format=pyaudio.paInt16, channels=1, rate=16000, and a frames_per_buffer value matched to the chunk duration the pipeline wants. If you set FRAMES_PER_BUFFER to 800, you get 50 milliseconds of audio at 16 kHz, so keep that number on hand when you tune chunk size.
Getting to the point of running that code is its own small ordeal. PyAudio depends on PortAudio, and installing it requires a platform-specific step before pip install pyaudio will succeed:
# macOS
brew install portaudio
pip install pyaudio
# Windows
# download the matching PyAudio .whl from a trusted wheel index, then:
pip install PyAudio‑0.2.11‑cp311‑cp311‑win_amd64.whl
# Linux (Debian/Ubuntu)
sudo apt-get install portaudio19-dev
pip install pyaudio
The same capture layer accepts more than a live microphone. Anything that yields an iterable of PCM bytes satisfies the contract, whether that's a loop reading a file, a bridge pulling audio off a phone line, or an FFmpeg subprocess decoding an RTMP stream. For deployments where audio can't leave the device, Picovoice Cheetah processes speech locally and runs on Linux, macOS, Windows, Raspberry Pi, Android, iOS, and the web, using the same capture contract described above without ever sending audio off the machine. The case for that architecture is straightforward: on-device processing supports GDPR- and HIPAA-compliant deployments by keeping user audio off third-party servers entirely. This piece covers the tradeoffs that choice carries, against what you get back from a cloud API, later on.
Streaming audio to a transcription endpoint and handling the connection lifecycle
If capture is where pipelines fail quietly, transport is where they fail loudly, usually in production, usually at the worst time. If a WebSocket connection drops mid-session, the pipeline doesn't pause; it silently discards whatever audio was in flight unless you explicitly handle reconnection and a clean session teardown.
AssemblyAI's SDK is the clearest Python illustration of how this layer is supposed to work. Its RealTimeTranscriber abstracts away the WebSocket handling, and the developer's job shrinks to attaching event handlers, on_begin, on_turn, on_terminated, and on_error, before calling client.stream() in a loop. Wiring a function to the error event handles unexpected failures without wrapping the whole session in nested try/except blocks for every possible WebSocket exception. On the way out, a terminate_timeout value paired with client.disconnect(terminate=True) closes the session cleanly, and that matters both for correctness and for billing, since providers typically meter how long audio was processed.
Other providers build this layer with different mechanics, so you can see how well the layer survives the translation. Google Cloud Speech-to-Text uses gRPC bidirectional streaming: the first message on the stream must contain only the streaming configuration, and every message after that must contain only audio content. In a Python client, you typically need one thread or async task to read audio and push chunks into the stream, while the main thread or task consumes StreamingRecognizeResponse objects as they arrive, and this goes on until the stream ends. Azure's SDK handles the same problem differently again, offering a PushAudioInputStream that separates frame receipt from transcription: the calling code converts frames to mono 16 kHz PCM and writes them to the push stream, and the transcriber reads from that stream on its own schedule. That design suits browser-based or WebRTC audio sources well, because frames rarely arrive from a browser as tidily as they do from a local microphone.
Chunk size reappears at this layer as a tuning knob rather than a fixed constant. Smaller chunks get the first word to the engine faster, but each chunk still carries fixed overhead, so providers document a starting range that runs from 50 to 250 milliseconds. Picking a number inside that range, rather than guessing, is most of what separates a pipeline that feels instant from one that feels like it's thinking it over.
Handling partial results, turn detection, and end-of-speech events
Once audio is captured and flowing, the question of what to do with the results that come back is where most of the actual application logic lives, having a bigger effect on how a system feels to use than the accuracy of the model underneath it. APIs return two kinds of results: interim results that are provisional and subject to revision, and final results that are confirmed. Google Cloud STT exposes this directly through an interim_results=True flag, paired with a configurable speech_end_timeout that governs its voice activity detection. AssemblyAI's TurnEvent bundles the transcript text together with an end_of_turn boolean in a single object, which gives a voice-agent application a cleaner signal for exactly the moment it needs to know: has the user stopped talking, yes or no.
How you detect that moment varies enormously across providers, and that variation is the whole ballgame. Universal-3.5 Pro Realtime uses a neural end-of-turn model that reads tonality and pacing instead of waiting for a gap in the audio, and it lands on a decision in around 300 milliseconds. Older silence-based voice activity detection, by contrast, tacked on an extra 200 to 600 milliseconds of latency before neural EOT detection became available, eating a sizable chunk of that 800-millisecond total budget mentioned earlier.
On-device engines tend to simplify this contract rather than complicate it. Picovoice Cheetah's handle.process() call returns a tuple of a partial transcript and an is_endpoint flag, and once that flag comes back true, you call handle.flush() once to get the final confirmed transcript, with no event routing or WebSocket callbacks involved. For Whisper, which has no native streaming mode to begin with, the whisper_streaming project works around the gap by processing new audio chunks one after another, only emitting a transcript once it has been confirmed across two consecutive iterations, and advancing its buffer at the timestamp of the last fully confirmed sentence, a design that reaches about 3.3 seconds of latency on long-form speech. That number is fine for live conference captioning, where a few seconds of lag goes unnoticed, and unworkable for a voice agent that's supposed to respond like it's listening in real time. The whisper_streaming repository itself notes that it's becoming outdated and is being superseded by a project called SimulStreaming.
None of the three layers, capture, transport, or result handling, can be evaluated in isolation. Once all three are understood, choosing a specific tool means matching each layer's demands, latency tolerance, data residency, and accuracy requirements, to what a given API or engine actually offers.
Choosing between cloud streaming APIs and local on-device engines
The choice between a cloud streaming API and a local on-device engine is a matter of which constraint, latency budget, data sovereignty, raw accuracy, or infrastructure overhead, is least negotiable for a given deployment.
Cloud providers, among them AssemblyAI's Universal-3.5 Pro Realtime, Google Cloud STT, and Azure Cognitive Services, offer neural end-of-turn detection, speaker diarization, and models that keep improving without anyone having to manage a GPU fleet. The cost of that convenience is that every byte of audio leaves the network perimeter on its way to be transcribed. These providers also tend to post stronger real-world accuracy on proper nouns and noisy audio, and that matters directly to any enterprise customer-experience deployment where a misheard name is a bad first impression.
Local engines, among them Faster-Whisper, Vosk, and Picovoice Cheetah, keep every byte of audio on the device, which makes them the only realistic option for regulated industries and genuinely privacy-sensitive workloads. Faster-Whisper, built on CTranslate2, runs with a vad_filter=True flag to strip out silence, and scales from a tiny model that runs fine on modest hardware up to large-v3, which is recommended for GPU hardware.
Neither path wins. If a deployment has a hard latency floor and no regulatory constraint, it has every reason to reach for a cloud API with neural turn detection. If a deployment handles medical or financial audio, it has little choice but to keep that audio local, accuracy tradeoffs and all. The three-layer model, capture, transport, result handling, doesn't tell a developer which provider to pick, but it does tell them exactly which layer to interrogate first when the answer isn't obvious.
Sources
- Real-Time Speech Recognition in Python with PyAudio
- Real-Time Transcription in Python — Picovoice
- How to Convert Speech to Text in Python - The Python Code
- Transcribe audio from streaming input | Cloud Speech-to-Text | Google Cloud Documentation
- GitHub - ufal/whisper_streaming: Whisper realtime streaming for long speech-to-text transcription and translation · GitHub
- Python Streamlit Real-time Speech-to-Text with Azure SDK Issues - Microsoft Q&A
- How to Use Real-Time Streaming Speech Recognition with Cloud Speech-to-Text


