---
title: "Read and validate speech transcript JSON in C#"
url: https://recursiveai.org/onespeech/cookbook/read-transcript-json/
description: "Load OneSpeech transcript JSON in C# and reject invalid documents, unsupported versions, and bad word timing without downloading a speech model."
version: "1.1.0"
---

# Read and validate speech transcript JSON 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/read-transcript-json/read-transcript-json.zip)

Validate a `transcript.json` file (sample below; also in the ZIP). `Transcript.FromJson` reads OneSpeech’s version 1 transcript format, not JSON from other speech tools. No speech model is needed.

```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 OneSpeech;
var json = File.ReadAllBytes("transcript.json");
var transcript = Transcript.FromJson(json);
Console.WriteLine($"Valid: {transcript.Text}");
```

[The example](https://recursiveai.org/onespeech/cookbook/read-transcript-json/read-transcript-json.zip) is the full program below: unzip it and `dotnet run`. To run only the code above, paste it into Program.cs of a new `dotnet new console` project and `dotnet run`.

Prints:

```text
Valid: Hello.
```

Here is the entire input file, `transcript.json`:

```json
{
  "schemaVersion": 1,
  "transcript": {
    "text": "Hello.",
    "words": [
      { "text": "Hello.", "start": 0.25, "end": 0.75 }
    ]
  }
}
```

## The full program

```csharp
using OneSpeech;

var json = File.ReadAllBytes("transcript.json");
try
{
    var transcript = Transcript.FromJson(json);
    Console.WriteLine($"Valid: {transcript.Text}");
}
catch (InvalidTranscriptJsonException ex)
{
    Console.Error.WriteLine(ex.Message);
    Environment.ExitCode = 1;
}
```

```text
Valid: Hello.
```

The full program prints a validation error and exits with status 1 if `Transcript.FromJson` throws `InvalidTranscriptJsonException`. A missing file or denied read is a file I/O error, not a transcript validation error.

## Variations

If your app already has the JSON as a string, use the string overload. Replace the read line in the snippet at the top; the parse call stays the same.

```csharp
var json = File.ReadAllText("transcript.json");
```

To see a semantic rejection rather than a JSON syntax error, change the word’s `end` to `0.1` and run the full program again. The JSON is still well formed, but the word would end before it starts.

## Related recipes

- [Save a speech transcript as JSON](https://recursiveai.org/onespeech/cookbook/save-transcript-as-json/)
- [Serialize transcripts with Native AOT](https://recursiveai.org/onespeech/cookbook/serialize-transcript-with-nativeaot/)

## The short answer

Pass UTF-8 bytes or a JSON string to `Transcript.FromJson`. It reads OneSpeech’s [version 1 transcript format](https://recursiveai.org/onespeech/docs/transcript-json/) and checks both the structure and the values before returning a `Transcript`. If the input is valid JSON but isn’t a valid transcript, `Transcript.FromJson` throws `InvalidTranscriptJsonException`. It doesn’t translate documents from other speech systems into OneSpeech’s shape.

## How do you validate a transcript JSON file?

Start with the envelope: `schemaVersion` must be the integer `1`, and `transcript` must contain `text`. Property names are case-sensitive, and unknown properties are rejected. Optional arrays such as `words` may be omitted (the result uses an empty array), but an explicit `null` isn’t an array. OneSpeech also checks values such as confidence, which must be between 0 and 1 when supplied.

A successful read means the document satisfies this schema, not that the transcription is accurate or belongs to the recording you have open. The top-level text isn’t rebuilt from the word array. If an editor depends on a specific recording revision, keep that association separately rather than expecting validation to listen to the audio.

## Do transcripts have timestamps?

They can. In this schema, `start` and `end` are seconds from the beginning of the original audio, not milliseconds or wall-clock times. A value of `0.25` means a quarter of a second into that audio. Intervals include the start but not the end. OneSpeech rejects negative times and reversed intervals. It also rejects a word that supplies only one endpoint. Both endpoints can be null for an untimed word; the reader doesn’t guess where it belongs. That distinction lets you show the text even if you can’t jump to that word during playback.

For imported files or uploads, enforce a size cap before loading the entire body into memory. The [reader’s budgets](https://recursiveai.org/onespeech/docs/transcript-json/#reader-limits-and-failures) are format limits, not a suggested upload allowance. In particular, the sample’s `File.ReadAllBytes` allocates the input before validation; use it for files you already know are small enough for your app.
