sandrohanea / whisper.net

Whisper.net. Speech to text made simple using Whisper Models
MIT License
572 stars 89 forks source link

Support getting current detected locale of audio file #150

Closed GewoonJaap closed 11 months ago

GewoonJaap commented 11 months ago

I think it would be nice to be able to get the current detected locale of the audio file. When using the auto detect locale function you sadly can't retrieve what the detected locale is. I see that the detected locale is being logged, so it should be available somewhere in the WinWhisper framework, but I guess it isn't exposed in C# yet :(

GewoonJaap commented 11 months ago

image Afaik know, after executing whisper_full_with_state, the variable language inside the state variable is updated to the auto detected language. However in C# the state is a IntPtr and not bound to a object, I haven't researched yet how to convert this to an object..

sandrohanea commented 11 months ago

Hello @GewoonJaap , Yes, it is possible to get the detected language, using the property: https://github.com/sandrohanea/whisper.net/blob/main/Whisper.net/WhisperProcessorEvents.cs#L73C5-L73C36 on the SegmentData.

You can only retrieve that when a segment is returned, there is not faster callback that you can register. Would that be enough for your use-case?

E.g.:

        // Creating Processor etc...
        await foreach (var result in processor.ProcessAsync(fileStream))
        {
            Console.WriteLine($"The spoken language is: {result.Language}");
            Console.WriteLine($"{result.Start}->{result.End}: {result.Text}");
        }
GewoonJaap commented 11 months ago

Oh that's really nice! Didn't know it was possible. Thank you :)