---
title: "Transcribe a float PCM array without a WAV file in C#"
url: https://recursiveai.org/onespeech/cookbook/transcribe-in-memory-pcm-samples/
description: "Pass a mono 16 kHz float PCM array directly to a local recognizer in C# with OneSpeech. No WAV header, audio encoding, or temporary WAV file is needed."
version: "1.1.0"
---

# Transcribe a float PCM array without a WAV file in C#

**OneSpeech** is a free, open-source speech recognition library for .NET from Recursive AI. MIT or Apache-2.0, no native dependencies.

[NuGet](https://www.nuget.org/packages/RecursiveAI.OneSpeech) · [GitHub](https://github.com/recursive-ai-oss/onespeech-csharp) · [Docs](https://recursiveai.org/onespeech/docs/) · [Download example (.zip)](https://recursiveai.org/onespeech/cookbook/transcribe-in-memory-pcm-samples/transcribe-in-memory-pcm-samples.zip)

Wrap mono 16 kHz samples normalized to −1..1 in `AudioBuffer`. The zip supplies example samples in `sample.f32le`.

```shell
dotnet add package RecursiveAI.OneSpeech
```

Requires [.NET 10](https://dotnet.microsoft.com/download/dotnet/10.0) (net10.0); .NET 9 and earlier aren’t supported.

```csharp
using System.Runtime.InteropServices;
using OneSpeech;
using OneSpeech.Whisper;

var bytes = File.ReadAllBytes("sample.f32le");
var samples = MemoryMarshal
    .Cast<byte, float>(bytes).ToArray();
var audio = new AudioBuffer(samples, 16_000);
using var asr = await WhisperRecognizer
    .LoadAsync(model: "openai/whisper-tiny");
var result = asr.Transcribe(audio, "en");
Console.WriteLine(result.Text);
```

Paste the code above into Program.cs of a new `dotnet new console` project and `dotnet run`, or unzip [the example](https://recursiveai.org/onespeech/cookbook/transcribe-in-memory-pcm-samples/transcribe-in-memory-pcm-samples.zip) and `dotnet run`.

```text
Stuffed into you, his belly, cowtled him.
```

`WhisperRecognizer` throws `ArgumentException` if the buffer is not mono 16 kHz; creating an `AudioBuffer` does not resample it.

If you already have a `float[]`, pass it as `samples` instead of reading the example file. The sample loader assumes a little-endian machine. The example input is the audio of [LibriSpeech test-clean](https://www.openslr.org/12) utterance `1089-134686-0001` by Vassil Panayotov, Guoguo Chen, Daniel Povey, and Sanjeev Khudanpur ([CC BY 4.0](https://creativecommons.org/licenses/by/4.0/)), decoded from FLAC to raw float PCM. The first three floats are approximately `0.001038`, `0.001099`, and `0.000916`; the full array holds 52,400 samples. The transcript above is the model’s output, including its misheard words.

The first `LoadAsync` downloads missing model files; the recognition call itself uses the local model.

## Variations

**Don’t specify English.** With this multilingual checkpoint, you can omit the language argument. Replace the `Transcribe` line with:

```csharp
var result = asr.Transcribe(audio);
```

## Related recipes

- [Transcribe an encoded audio stream](https://recursiveai.org/onespeech/cookbook/transcribe-encoded-audio-stream/)
- [Transcribe an audio file](https://recursiveai.org/onespeech/cookbook/transcribe-audio-file/)
- [Configure the speech model cache](https://recursiveai.org/onespeech/cookbook/configure-speech-model-cache/)

## The short answer

Wrap a mono, normalized 16 kHz `float[]` in `new AudioBuffer(samples, 16_000)` and call `WhisperRecognizer.Transcribe` with that buffer. `AudioBuffer` holds a view of the input, not a copy, so don’t modify or recycle the array while inference is using it. You can keep the loaded recognizer for sequential calls; don’t call the same instance concurrently.

## What is the difference between PCM audio and WAV audio?

PCM is the sequence of sampled audio amplitudes. WAV is a container that can store PCM and describe it in a header. A `float[]` has no such header: it doesn’t say whether the samples are at 16 kHz or 48 kHz, or whether they are mono or stereo. The sample rate and channel count you pass to `AudioBuffer` describe the array you already have. They don’t transform it.

If your app already has PCM from a decoder or recording buffer, there’s no reason to put it in a WAV container before recognition. If you have a WAV, FLAC, or other encoded byte stream instead, don’t reinterpret its bytes as floats. Use the [encoded audio stream recipe](https://recursiveai.org/onespeech/cookbook/transcribe-encoded-audio-stream/) so the decoder reads the format and produces samples.

## How do you convert 16-bit PCM to normalized floats in C#?

For mono, 16 kHz signed PCM already decoded into `short` samples, divide by `32768f`. That maps −32768 to −1 and 32767 to just below +1. The conversion changes the sample scale, not the rate or number of channels. This tiny buffer illustrates the conversion; use real speech as the input to the recognizer.

```csharp
short[] pcm16 = [-32768, 0, 16384];
float[] normalized = Array.ConvertAll(pcm16,
    sample => sample / 32768f);
Console.WriteLine(string.Join(", ", normalized));
```

```text
-1, 0, 0.5
```

For input at another rate, resample before creating the buffer. For stereo input, downmix or select the channel you want first: simply passing `channels: 1` doesn’t make interleaved stereo data mono.
