alphacep / alphacep/vosk-api

How to catch the json format result in C#?

Abierto
#1,013 3 comentarios 0 reacciones 0 asignados Ver en GitHub
Lenguaje dominante
Jupyter Notebook
Estrellas
15.1k
Forks
1.8k
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

Hello:
I want to use C# to save all the voice recognized text in a file, so I can edit it later.
I found to use Console.WriteLine to show the result, for all NON-English text, the words look like garbage, but using Debug.WriteLine the shown text is correct. So I write some code trying to show NON-English text in debug output window. The following is my code:

public static void DemoBytes(Model model)
{
// Demo byte buffer
VoskRecognizer rec = new(model, 16000.0f);
rec.SetMaxAlternatives(0);
rec.SetWords(true);
using (Stream source = File.OpenRead(UA_Wav_File1))
{
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());
string json_data = rec.Result().ToString();
if (json_data.Contains("["))
{
Debug.WriteLine(json_data);
Console.Beep();
}
}
else
{
Console.WriteLine(rec.PartialResult());
}
}
}
Console.WriteLine(rec.FinalResult());
}

But my code didn’t catch any Json format result. However, from console window, I can see quite a lot of text output, like the following:
{
"partial" : "????? ???? ?????? ????? ?? ?? ??? ??? ?????? ?????? ?? ??????? ????? ????? ?? ????? ?? ?????????? ???? ???????????"
}
{
"result" : [{
"conf" : 0.953055,
"end" : 287.400000,
"start" : 287.071523,
"word" : "?????"
}, {
"conf" : 0.936494,
"end" : 287.820000,
"start" : 287.400000,
"word" : "????"
}, {
"conf" : 0.399469,
"end" : 288.329795,
"start" : 287.878682,
"word" : "??????"
}, {
"conf" : 0.545751,
"end" : 288.780000,
"start" : 288.329795,
"word" : "?????"
}, {
"conf" : 0.982125,
"end" : 289.203750,
"start" : 288.810000,
"word" : "??"
}, {
"conf" : 0.633553,
"end" : 289.410117,
"start" : 289.230000,
"word" : "??"
}, {
"conf" : 0.240568,
"end" : 289.768037,
"start" : 289.533633,
"word" : "???"
}, {
"conf" : 0.177813,
"end" : 290.100000,
"start" : 289.770000,
"word" : "???"
}, {
"conf" : 0.939531,
"end" : 290.730293,
"start" : 290.490000,
"word" : "???"
}, {
"conf" : 0.681968,
"end" : 291.180000,
"start" : 290.939971,
"word" : "???"
}, {
"conf" : 0.992080,
"end" : 291.600000,
"start" : 291.180117,
"word" : "??????"
}, {
"conf" : 1.000000,
"end" : 292.200000,
"start" : 291.900000,
"word" : "??"
}, {
"conf" : 1.000000,
"end" : 292.710000,
"start" : 292.200000,
"word" : "???????"
}, {
"conf" : 0.868925,
"end" : 293.187158,
"start" : 292.770293,
"word" : "?????"
}, {
"conf" : 0.280664,
"end" : 293.519912,
"start" : 293.190000,
"word" : "?????"
}, {
"conf" : 0.253797,
"end" : 293.845635,
"start" : 293.558174,
"word" : "??"
}, {
"conf" : 0.510191,
"end" : 294.779912,
"start" : 294.565898,
"word" : "?"
}, {
"conf" : 0.502767,
"end" : 294.870000,
"start" : 294.779912,
"word" : "??"
}, {
"conf" : 0.430731,
"end" : 295.518984,
"start" : 294.870000,
"word" : "??????????"
}, {
"conf" : 0.758802,
"end" : 295.770000,
"start" : 295.519980,
"word" : "????"
}, {
"conf" : 0.526706,
"end" : 296.730000,
"start" : 296.248740,
"word" : "???????????"
}],
"text" : "????? ???? ?????? ????? ?? ?? ??? ??? ??? ??? ?????? ?? ??????? ????? ????? ?? ? ?? ?????????? ???? ???????????"
}
{
"partial" : ""
}

Let me know if I made any mistake, I simply want to catch those Json format rec.Result() in C#.
Please advise,
Thanks,

Guía de contribución

No hay ninguna guía de contribución indexada para este repositorio

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.