Method DetectLanguage
DetectLanguage(WaveFile, CancellationToken)
Synchronously detects the spoken language of the provided audio content.
public SpeechToText.LanguageDetectionResult DetectLanguage(WaveFile audioFile, CancellationToken cancellationToken = default)
Parameters
audioFile
WaveFileThe WAV-format audio content to analyze.
cancellationToken
CancellationTokenToken to cancel the operation.
Returns
- SpeechToText.LanguageDetectionResult
A SpeechToText.LanguageDetectionResult containing the detected ISO-639-1 language code (e.g. "en" for English) along with 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 = engine.DetectLanguage(audioFile);
Console.WriteLine($"Detected language: {lang}");
Exceptions
- ArgumentNullException
Thrown if
audioFile
is null.- NotSupportedException
Thrown if the model does not support language detection.