> ## Documentation Index
> Fetch the complete documentation index at: https://docs.runanywhere.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Streaming STT

> Transcribe speech as it arrives

Two shapes. Pick by where your audio comes from.

## Push: openStream

```ts theme={null}
const stream = await RunAnywhere.stt.openStream({
  encoding: 'pcmF32Le',
  sampleRate: 16000,
  channels: 1,
})

// per buffer
stream.pushFrame({ samples, sampleCount })

// when the utterance ends
stream.flush()
stream.finish()
await stream.close()
```

## Pull: transcribeStream

```ts theme={null}
for await (const event of RunAnywhere.stt.transcribeStream(audioIterable)) {
  if (event.type === 'partial') preview = event.text
  if (event.type === 'final') transcript += event.transcription.text
}
```

## Signatures

```ts theme={null}
openStream(format: AudioFormatSpec, options?: SttOptions): Promise<SttStream>
transcribeStream(audio: AsyncIterable<AudioInput>, options?: SttOptions): AsyncIterableIterator<TranscriptionEvent>
```

## Capturing in the renderer, transcribing in the host

The microphone lives in the renderer, where `getUserMedia` works. Inference lives in the
utility host. Forward frames across the bridge:

```ts theme={null}
// renderer
const media = await navigator.mediaDevices.getUserMedia({ audio: true })
// … convert to PCM frames, then
window.runanywhere.stt.pushFrame(frame)
```

Keep the conversion in the renderer. Sending raw `MediaStream` data across IPC per callback is
far more traffic than sending the PCM you actually need.

## Closing

Always `flush()`, `finish()`, and `close()`. A stream left open holds the model and the
microphone, and on a desktop app that outlives a window close.

```ts theme={null}
win.on('closed', () => {
  void stream.close()
})
```

## Choosing between them

Push suits a live microphone, since the capture API already hands you frames in a callback.
Pull suits a source you can express as an async iterable, such as a file read in chunks or
audio arriving over the network.
