I did some quick test to import the lib whisper.net into vl. Like often in these days the lib makes a havy use of Tasks. I know the common Threads about Tasks and await:
But i could not find anything about the IAsyncEnumerable Interface which is used in the lib for example here.
Basically i want to do something like this.
public static async Task Process(WhisperProcessor processor, String FilePath)
{
using var fileStream = File.OpenRead(FilePath);
await foreach (SegmentData result in processor.ProcessAsync(fileStream))
{
}
}
But then i just get information, when the Task finished, but i do not get how to access/ return the SegementData from the await foreach. Any ideas on this?
edit:
Creating an public Event an then just Invoke this Event seems to work, but is that the right way?
public static event EventHandler<SegmentData> OnReceivedSegementData;
public static async Task Process(WhisperProcessor processor, String FilePath)
{
using var fileStream = File.OpenRead(FilePath);
await foreach (SegmentData result in processor.ProcessAsync(fileStream))
{
OnReceivedSegementData?.Invoke(new object(), result);
}
}