Сам код:
using System;
using System.IO;
using Vosk;
public class VoskDemo
{
public static void DemoBytes(Model model)
{
// Demo byte buffer
VoskRecognizer rec = new VoskRecognizer(model, 16000.0f);
rec.SetMaxAlternatives(0);
rec.SetWords(true);
using (Stream source = File.OpenRead("\"C:\\Users\\123\\Downloads\\Я-тебя-люблю_ (mp3cut.net) (1).wav\""))
{
byte[] buffer = new byte[4096];
int bytesRead;
while ((bytesRead = source.Read(buffer, 0, buffer.Length)) > 0)
{
if (rec.AcceptWaveform(buffer, bytesRead))
{
Console.WriteLine(rec.Result());
}
else
{
Console.WriteLine(rec.PartialResult());
}
}
}
Console.WriteLine(rec.FinalResult());
}
public static void DemoFloats(Model model)
{
// Demo float array
VoskRecognizer rec = new VoskRecognizer(model, 16000.0f);
using (Stream source = File.OpenRead("\"C:\\Users\\123\\Downloads\\Я-тебя-люблю_ (mp3cut.net) (1).wav\""))
{
byte[] buffer = new byte[4096];
int bytesRead;
while ((bytesRead = source.Read(buffer, 0, buffer.Length)) > 0)
{
float[] fbuffer = new float[bytesRead / 2];
for (int i = 0, n = 0; i < fbuffer.Length; i++, n += 2)
{
fbuffer[i] = BitConverter.ToInt16(buffer, n);
}
if (rec.AcceptWaveform(fbuffer, fbuffer.Length))
{
Console.WriteLine(rec.Result());
}
else
{
Console.WriteLine(rec.PartialResult());
}
}
}
Console.WriteLine(rec.FinalResult());
}
public static void DemoSpeaker(Model model)
{
// Output speakers
SpkModel spkModel = new SpkModel("\"C:\\Users\\123\\Downloads\\vosk-model-spk-0.4\\vosk-model-spk-0.4\"");
VoskRecognizer rec = new VoskRecognizer(model, 16000.0f);
rec.SetSpkModel(spkModel);
using (Stream source = File.OpenRead("\"C:\\Users\\123\\Downloads\\Я-тебя-люблю_ (mp3cut.net) (1).wav\""))
{
byte[] buffer = new byte[4096];
int bytesRead;
while ((bytesRead = source.Read(buffer, 0, buffer.Length)) > 0)
{
if (rec.AcceptWaveform(buffer, bytesRead))
{
Console.WriteLine(rec.Result());
}
else
{
Console.WriteLine(rec.PartialResult());
}
}
}
Console.WriteLine(rec.FinalResult());
}
public static void Main()
{
// You can set to -1 to disable logging messages
Vosk.Vosk.SetLogLevel(0);
Model model = new Model("\"C:\\Users\\123\\Downloads\\vosk-model-small-ru-0.22\"");
DemoBytes(model);
DemoFloats(model);
DemoSpeaker(model);
}
}
Ошибка(исключение):
System.AccessViolationException: "Attempted to read or write protected memory. This is often an indication that other memory is corrupt."
Не могу понять что за ошибка? не нашёл в инете