alphacep / vosk-server

WebSocket, gRPC and WebRTC speech recognition server based on Vosk and Kaldi libraries
Apache License 2.0
882 stars 243 forks source link

Disable partial results #155

Open danishkhan3621 opened 2 years ago

danishkhan3621 commented 2 years ago

When it execute websocket/test.py file which getting repeated text :

{
  "partial" : ""
}
{
  "partial" : ""
}
{
  "partial" : ""
}
{
  "partial" : ""
}
{
  "partial" : ""
}
{
  "partial" : ""
}
{
  "partial" : "one"
}
{
  "partial" : "one zero"
}
{
  "partial" : "one zero"
}
{
  "partial" : "one zero zero"
}
{
  "partial" : "one zero zero"
}
{
  "partial" : "one zero zero zero"
}
{
  "partial" : "one zero zero zero one"
}
{
  "partial" : "one zero zero zero one"
}
{
  "partial" : "one zero zero zero one"
}
{
  "partial" : "one zero zero zero one"
}
{
  "partial" : "one zero zero zero one"
}
{
  "partial" : "one zero zero zero one"
}
{
  "partial" : "one zero zero zero one"
}
{
  "result" : [{
      "conf" : 0.988995,
      "end" : 1.080000,
      "start" : 0.840000,
      "word" : "one"
    }, {
      "conf" : 1.000000,
      "end" : 1.530000,
      "start" : 1.140000,
      "word" : "zero"
    }, {
      "conf" : 1.000000,
      "end" : 1.920000,
      "start" : 1.530000,
      "word" : "zero"
    }, {
      "conf" : 1.000000,
      "end" : 2.310000,
      "start" : 1.920000,
      "word" : "zero"
    }, {
      "conf" : 1.000000,
      "end" : 2.610000,
      "start" : 2.310000,
      "word" : "one"
    }],
  "text" : "one zero zero zero one"
}
{
  "partial" : ""
}
{
  "partial" : "nine"
}
{
  "partial" : "i know what"
}
{
  "partial" : "i know what you"
}
{
  "partial" : "i know what you want to"
}
{
  "partial" : "i know what you want to"
}
{
  "partial" : "i know what you want to"
}
{
  "partial" : "i know what you want to"
}
{
  "partial" : "i know what you want to"
}
{
  "partial" : "i know what you want to"
}
{
  "result" : [{
      "conf" : 0.398616,
      "end" : 4.034006,
      "start" : 3.930000,
      "word" : "yeah"
    }, {
      "conf" : 1.000000,
      "end" : 4.080000,
      "start" : 4.034006,
      "word" : "i"
    }, {
      "conf" : 0.993436,
      "end" : 4.206610,
      "start" : 4.080000,
      "word" : "know"
    }, {
      "conf" : 0.841279,
      "end" : 4.379774,
      "start" : 4.206610,
      "word" : "what"
    }, {
      "conf" : 0.453946,
      "end" : 4.500000,
      "start" : 4.379774,
      "word" : "your"
    }, {
      "conf" : 0.548845,
      "end" : 4.980000,
      "start" : 4.500000,
      "word" : "window"
    }],
  "text" : "yeah i know what your window"
}
{
  "partial" : ""
}
{
  "partial" : ""
}
{
  "partial" : ""
}
{
  "partial" : "serial"
}
{
  "partial" : "serial one eight"
}
{
  "partial" : "serial one eight six"
}
{
  "partial" : "serial one eight zero"
}
{
  "partial" : "serial one eight zero"
}
{
  "partial" : "serial one eight zero three"
}
{
  "partial" : "serial one eight zero three"
}
{
  "partial" : "serial one eight zero three"
}
{
  "result" : [{
      "conf" : 0.496589,
      "end" : 6.689431,
      "start" : 6.270000,
      "word" : "serial"
    }, {
      "conf" : 0.979614,
      "end" : 6.870000,
      "start" : 6.689431,
      "word" : "one"
    }, {
      "conf" : 0.994316,
      "end" : 7.140000,
      "start" : 6.900000,
      "word" : "eight"
    }, {
      "conf" : 1.000000,
      "end" : 7.500000,
      "start" : 7.140170,
      "word" : "zero"
    }, {
      "conf" : 1.000000,
      "end" : 7.980000,
      "start" : 7.500000,
      "word" : "three"
    }],
  "text" : "serial one eight zero three"
}

i want to remove that blank and repeated text is it possible to only print result array

Code:

async def run_test(uri):
    async with websockets.connect(uri) as websocket:

        wf = wave.open(sys.argv[1], "rb")
        await websocket.send('{ "config" : { "sample_rate" : %d } }' % (wf.getframerate()))
        buffer_size = int(wf.getframerate() * 0.2) # 0.2 seconds of audio
        while True:
            data = wf.readframes(buffer_size)

            if len(data) == 0:
                break

            await websocket.send(data)
            print (await websocket.recv())

        await websocket.send('{"eof" : 1}')
        print (await websocket.recv())

asyncio.get_event_loop().run_until_complete(
    run_test('ws://localhost:2700'))