Table of Contents

Method DetectLanguageAsync

Namespace
LMKit.Speech
Assembly
LM-Kit.NET.dll

DetectLanguageAsync(WaveFile, CancellationToken)

Asynchronously detects the spoken language of the provided audio content.

public Task<SpeechToText.LanguageDetectionResult> DetectLanguageAsync(WaveFile audioFile, CancellationToken cancellationToken = default)

Parameters

audioFile WaveFile

The WAV-format audio content to analyze.

cancellationToken CancellationToken

Token to cancel the operation.

Returns

Task<SpeechToText.LanguageDetectionResult>

A task that produces a SpeechToText.LanguageDetectionResult, containing the detected ISO-639-1 language code and a confidence score between 0.0 and 1.0.

Examples

var model = LM.LoadFromModelID("whisper-large-turbo3");
var engine = new SpeechToText(model);
var audioFile = new WaveFile("audio.wav");
var lang = await engine.DetectLanguageAsync(audioFile);
Console.WriteLine($"Detected language: {lang}");

Exceptions

ArgumentNullException

Thrown if audioFile is null.

NotSupportedException

Thrown if the model does not support language detection.