Recursive AI

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.

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.

Terminal
dotnet add package RecursiveAI.OneSpeech

Requires .NET 10 (net10.0); .NET 9 and earlier aren’t supported.

C#
using OneSpeech;
var json = File.ReadAllBytes("transcript.json");
var transcript = Transcript.FromJson(json);
Console.WriteLine($"Valid: {transcript.Text}");

The example 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

C#
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.

C#
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.

The short answer

Pass UTF-8 bytes or a JSON string to Transcript.FromJson. It reads OneSpeech’s version 1 transcript format 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 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.

All onespeech recipes