mirror of
https://github.com/SubtitleEdit/subtitleedit.git
synced 2024-11-25 04:33:04 +01:00
Merge pull request #8900 from ivandrofly/feature/voskdistate
Feature/voskdistate
This commit is contained in:
commit
ecaa9972f3
@ -69,44 +69,46 @@ namespace Nikse.SubtitleEdit.Forms.AudioToText
|
|||||||
_model = new Model(modelFileName);
|
_model = new Model(modelFileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
var rec = new VoskRecognizer(_model, 16000.0f);
|
using (var rec = new VoskRecognizer(_model, 16000.0f))
|
||||||
rec.SetMaxAlternatives(0);
|
|
||||||
rec.SetWords(true);
|
|
||||||
var list = new List<ResultText>();
|
|
||||||
var buffer = new byte[4096];
|
|
||||||
using (var source = File.OpenRead(WaveFileName))
|
|
||||||
{
|
{
|
||||||
int bytesRead;
|
rec.SetMaxAlternatives(0);
|
||||||
while ((bytesRead = source.Read(buffer, 0, buffer.Length)) > 0)
|
rec.SetWords(true);
|
||||||
|
var list = new List<ResultText>();
|
||||||
|
var buffer = new byte[4096];
|
||||||
|
using (var source = File.OpenRead(WaveFileName))
|
||||||
{
|
{
|
||||||
if (rec.AcceptWaveform(buffer, bytesRead))
|
int bytesRead;
|
||||||
|
while ((bytesRead = source.Read(buffer, 0, buffer.Length)) > 0)
|
||||||
{
|
{
|
||||||
var res = rec.Result();
|
if (rec.AcceptWaveform(buffer, bytesRead))
|
||||||
var results = VoskAudioToText.ParseJsonToResult(res);
|
{
|
||||||
list.AddRange(results);
|
var res = rec.Result();
|
||||||
}
|
var results = VoskAudioToText.ParseJsonToResult(res);
|
||||||
else
|
list.AddRange(results);
|
||||||
{
|
}
|
||||||
var res = rec.PartialResult();
|
else
|
||||||
|
{
|
||||||
|
_ = rec.PartialResult();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
var finalResult = rec.FinalResult();
|
var finalResult = rec.FinalResult();
|
||||||
var finalResults = VoskAudioToText.ParseJsonToResult(finalResult);
|
var finalResults = VoskAudioToText.ParseJsonToResult(finalResult);
|
||||||
list.AddRange(finalResults);
|
list.AddRange(finalResults);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
File.Delete(WaveFileName);
|
File.Delete(WaveFileName);
|
||||||
WaveFileName = null;
|
WaveFileName = null;
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
// ignore
|
// ignore
|
||||||
}
|
}
|
||||||
|
|
||||||
return ResultListToText(list);
|
return ResultListToText(list);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static string ResultListToText(List<ResultText> list)
|
private static string ResultListToText(List<ResultText> list)
|
||||||
|
Loading…
Reference in New Issue
Block a user