---
title: "Detect spoken language from audio in C#"
url: https://recursiveai.org/onespeech/cookbook/detect-audio-language/
description: "Detect spoken language from audio in C# with OneSpeech. Download a .NET 10 example with a real audio sample, runnable code and the actual output."
version: "1.1.0"
---

# Detect spoken language from audio 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/detect-audio-language/detect-audio-language.zip)

Detect the first speech chunk’s language. `sample.flac` is in the zip.

```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;
Console.WriteLine(Speech.DetectLanguage(
    "sample.flac"));
```

First run downloads Whisper large-v3-turbo weights (about 1.62 GB). [Change the model cache](https://recursiveai.org/onespeech/cookbook/configure-speech-model-cache/).

The zip contains the unmodified LibriSpeech test-clean utterance 1089-134686-0001: “stuff it into you his belly counselled him”. Credit: Vassil Panayotov, Guoguo Chen, Daniel Povey and Sanjeev Khudanpur ([LibriSpeech](https://www.openslr.org/12)), [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/).

`dotnet run` prints:

```text
en
```

`en` is the detected language tag, not a check of every language change in the recording. `Speech.DetectLanguage` uses the default Whisper large-v3-turbo recognizer and the embedded speech detector; it does not need the timing or speaker companion models. Missing recognizer files download on first use; prepare the cache using the [model download guide](https://recursiveai.org/onespeech/docs/model-downloads/).

Silent or invalid audio throws `UnsupportedAudioException`; a selected model without language detection raises `CapabilityNotSupportedException`. Leave the `language` argument null: detection refuses a language hint instead of ignoring it.

## Variations

**Handle an unsupported model.** Moonshine’s English checkpoints do not identify languages, even when the recording happens to be English.

```csharp
using OneSpeech;
try
{
    Speech.DetectLanguage("sample.flac",
        model: "moonshine-ai/moonshine-tiny");
}
catch (CapabilityNotSupportedException)
{
    Console.WriteLine("This model cannot detect languages.");
}
```

```text
This model cannot detect languages.
```

## Related recipes

[Label speakers in live audio in C#](https://recursiveai.org/onespeech/cookbook/label-speakers-in-live-audio/) · [Display partial speech recognition results in C#](https://recursiveai.org/onespeech/cookbook/display-revisable-live-transcript/) · [Limit live speech utterance duration in C#](https://recursiveai.org/onespeech/cookbook/configure-live-utterance-endpoints/)

<!-- article -->

## The short answer

Call `Speech.DetectLanguage(path)` on an audio file with detectable speech. The result is a language tag, such as `en`. OneSpeech selects the first detected speech chunk, runs a recognizer with language-identification capability and returns its result. This is not text-language detection or continuous language-change tracking.

## How can I identify language spoken from audio?

The downloadable program prints the detected tag for a real FLAC recording. The speech detector skips input without speech and supplies the first speech chunk to the language-capable recognizer. Leave the `language` parameter null: providing a language hint contradicts detection, so the API refuses it rather than silently accepting it.

The default recognizer is Whisper large-v3-turbo. Selecting a different catalog ID is explicit; the library does not silently substitute another model when a requested capability is unavailable. The [transcribing-files documentation](https://recursiveai.org/onespeech/docs/transcribing-files/) shows `DetectLanguage` alongside transcription, but the two calls have different jobs. Detection returns the language tag without requiring you to display or save recognized words.

A single result describes the first detected chunk, not proof that the entire file uses that language. A multilingual conversation, an introductory announcement or a brief foreign-language opening may therefore need a different application policy. Do not assign the returned tag to every speaker or claim that later language changes were checked.

## Is there a way to find out what language someone is speaking?

Yes, when the selected recognizer supports identification and the audio contains usable speech. This recipe works from a recording path. The library decodes supported audio and resamples for its speech pipeline; it does not open a microphone or identify the person speaking. A speaker identity and a spoken language are separate outputs.

Silence has no detectable spoken language. The API raises `UnsupportedAudioException` for silent audio rather than returning an invented language or a default English value. Invalid encoded audio raises the same exception category, while filesystem errors and canceled work remain separate. Your application should distinguish “no usable speech” from an asserted language in its own presentation.

Moonshine’s English checkpoints illustrate another important distinction. A null hint selects their fixed English task; it does not run identification. The variation catches `CapabilityNotSupportedException` when explicitly asking that family to detect a language. A successful English transcription from an English-only model is not evidence that it identified English among alternatives. Check capabilities before building a language-selection workflow around a model.

## How do I recognize an audio language offline in C#?

Prepare the language-capable recognizer in the model cache before taking the application offline. First use acquires missing tier-1 files, verifies publisher data and installs verified runtime graphs. Existing verified files require no network requests. Detection needs the recognizer and embedded speech detector, not the optional word-timing or speaker companion models used by whole-file transcription.

Use `ONESPEECH_MODEL_CACHE` when deployment needs a chosen cache location. Plan space for both publisher and converted runtime files, and use the [model preparation documentation](https://recursiveai.org/onespeech/docs/models/) rather than bundling an incomplete directory copied during a download. A model integrity failure is an error to resolve, not a reason to use corrupt files.

The output here is deliberately only `en`. Do not turn it into an accuracy percentage or a confidence threshold: the convenience method returns a string, not a confidence score. If you need a fallback language for product behavior, label it as your application’s fallback, separate from a successful detection result.
