alphacep / vosk-api

Offline speech recognition API for Android, iOS, Raspberry Pi and servers with Python, Java, C# and Node
Apache License 2.0
7.7k stars 1.08k forks source link

How to make response fast with Hindi full model #1297

Open helpinghandindia1 opened 1 year ago

helpinghandindia1 commented 1 year ago

Hi pls tell me make it more faster with vosk-model-hi-0.22 model. it is taking few seconds for result. pls see thanks I am using 16 gb ddr4 and ssd hdd with I5 processor.

nshmyrev commented 1 year ago

Can you share a video? How do you test it exactly?

helpinghandindia1 commented 1 year ago

@nshmyrev shmyrev)

We are using Centos and Asterisk for our users. Can we edit any setting for faster response or should we consider hardware.

Set(tempvalue${digitp}=${SHELL(/usr/local/bin/python3 /opt/vosk-api/python/example/./test_ffmpeg.py /root/tempfiles/20222/${callerdatafile${digitp}}.wav | grep '"text" :' | cut -d'"' -f4)})

nshmyrev commented 1 year ago

Set(tempvalue${digitp}=${SHELL(/usr/local/bin/python3 /opt/vosk-api/python/example/./test_ffmpeg.py /root/tempfiles/20222/${callerdatafile${digitp}}.wav | grep '"text" :' | cut -d'"' -f4)})

This is certainly a wrong way to use it, you need to use server with https://github.com/alphacep/vosk-server/blob/master/websocket/test_ffmpeg.py from the server, not the demo that loads the model every time.

helpinghandindia1 commented 1 year ago

@nshmyrev Thank you for your reply.

As you suggested to replace test_ffmpeg.py with updated version. But I don't see line model = Model(lang="hi") in updated file as we are using two different model for our users.

kindly see.

thanks

nshmyrev commented 1 year ago

You have to start two servers and adjust websocket address accordingly

helpinghandindia1 commented 1 year ago

Thanks , I will test soon and update.

helpinghandindia1 commented 1 year ago

@nshmyrev

I just try to implement new source as file but some socket error, can you guide how to implement it.

python3 test_ffmpegV1.py abc77.wav

websockets.exceptions.InvalidURI: localhost://localhost:2700 isn't a valid URI: scheme isn't ws or wss

complete error details is as follows [root@localhost example]# python3 test_ffmpegV1.py abc77.wav Traceback (most recent call last): File "test_ffmpegV1.py", line 31, in asyncio.run(run_test('localhost://localhost:2700')) File "/usr/local/lib/python3.7/asyncio/runners.py", line 43, in run return loop.run_until_complete(main) File "/usr/local/lib/python3.7/asyncio/base_events.py", line 587, in run_until_complete return future.result() File "test_ffmpegV1.py", line 8, in run_test async with websockets.connect(uri) as websocket: File "/usr/local/lib/python3.7/site-packages/websockets/legacy/client.py", line 490, in init wsuri = parse_uri(uri) File "/usr/local/lib/python3.7/site-packages/websockets/uri.py", line 77, in parse_uri raise exceptions.InvalidURI(uri, "scheme isn't ws or wss") websockets.exceptions.InvalidURI: localhost://localhost:2700 isn't a valid URI: scheme isn't ws or wss

nshmyrev commented 1 year ago

You edited the source incorrectly, return back ws: as it was in original code

helpinghandindia1 commented 1 year ago

@nshmyrev Yes , I have little edited, but error is same in both case.

[root@localhost example]# python3 test_ffmpegV1.py abc77.wav Traceback (most recent call last): File "test_ffmpegV1.py", line 31, in asyncio.run(run_test('ws://localhost:2700')) File "/usr/local/lib/python3.7/asyncio/runners.py", line 43, in run return loop.run_until_complete(main) File "/usr/local/lib/python3.7/asyncio/base_events.py", line 587, in run_until_complete return future.result() File "test_ffmpegV1.py", line 8, in run_test async with websockets.connect(uri) as websocket: File "/usr/local/lib/python3.7/site-packages/websockets/legacy/client.py", line 642, in aenter return await self File "/usr/local/lib/python3.7/site-packages/websockets/legacy/client.py", line 659, in await_impl_timeout return await asyncio.wait_for(self.await_impl(), self.open_timeout) File "/usr/local/lib/python3.7/asyncio/tasks.py", line 442, in wait_for return fut.result() File "/usr/local/lib/python3.7/site-packages/websockets/legacy/client.py", line 663, in await_impl _transport, _protocol = await self._create_connection() File "/usr/local/lib/python3.7/asyncio/base_events.py", line 971, in create_connection ', '.join(str(exc) for exc in exceptions))) OSError: Multiple exceptions: [Errno 111] Connect call failed ('::1', 2700, 0, 0), [Errno 111] Connect call failed ('127.0.0.1', 2700), [Errno 111] Connect call failed ('192.168.1.14', 2700)

helpinghandindia1 commented 1 year ago

I was using vosk api not vosk server, Is there any issue , pls see.

helpinghandindia1 commented 1 year ago

@nshmyrev pls see following error and also guide me to start server with Hindi model

[root@localhost ~]# docker run -d -p 2700:2700 alphacep/kaldi-en:latest Emulate Docker CLI using podman. Create /etc/containers/nodocker to quiet msg. ✔ docker.io/alphacep/kaldi-en:latest Trying to pull docker.io/alphacep/kaldi-en:latest... Getting image source signatures Copying blob be8c940edafd done Copying blob be8c940edafd done Copying blob be8c940edafd done Copying blob be8c940edafd done Copying blob be8c940edafd done Copying blob df5590a8898b done Copying blob b07d59199e84 done Copying blob 0e4f6ce137fd done Copying config e9683c9af0 done Writing manifest to image destination Storing signatures conmon: option parsing failed: Unknown option --full-attach Error: write child: broken pipe

helpinghandindia1 commented 1 year ago

@nshmyrev We are not highly trained in this, kindly guide with steps to proceed.

yum install docker yum install websocket*

[root@10 websocket]# ./test.py test.wav Traceback (most recent call last): File "./test.py", line 4, in import websockets ModuleNotFoundError: No module named 'websockets'

nshmyrev commented 1 year ago

pls see following error and also guide me to start server with Hindi model

You have to use docker, not podman

ModuleNotFoundError: No module named 'websockets'

pip3 install websockets

helpinghandindia1 commented 1 year ago

@nshmyrev Thanks , seems now it is working. I have installed new docker. [root@10 websocket]# ./test.py test.wav { "partial" : "" } { "partial" : "" } { "partial" : ""

Now pls guide how to use Hindi model with it and some related use. At present our Hindi module path is /root/.cache/vosk/

And this is not working docker run -d -p 2700:2700 -v /opt/model:/root/.cache/vosk/vosk-model-hi-0.22/ alphacep/kaldi-en:latest

thanks

nshmyrev commented 1 year ago

Try

docker run -p 2700:2700 -v /opt/vosk-model-en/model:/root/.cache/vosk/vosk-model-hi-0.22 alphacep/kaldi-en:latest
helpinghandindia1 commented 1 year ago

@nshmyrev No sir , this command is not working. docker run -p 2700:2700 -v /opt/vosk-model-en/model:/root/.cache/vosk/vosk-model-hi-0.22 alphacep/kaldi-en:latest

no result with this.

nshmyrev commented 1 year ago

What is "not working". What do you see in the output.

helpinghandindia1 commented 1 year ago

There is no result when I tried wav Hindi file.

nshmyrev commented 1 year ago

Which file did you try exactly? Does it have proper sample rate and format?

helpinghandindia1 commented 1 year ago

Yes it is well working with vosk-api but not showing output with vosk-server

nshmyrev commented 1 year ago

What is the format of the file, vosk server is more strict about it

helpinghandindia1 commented 1 year ago

@nshmyrev Here I am sharing both output, First one is vosk api and second one is vosk server.

file /opt/vosk-api/python/example/test1.wav /opt/vosk-api/python/example/test1.wav: RIFF (little-endian) data, WAVE audio, Microsoft PCM, 16 bit, mono 8000 Hz

/opt/vosk-api/python/example/test_ffmpeg.py /opt/vosk-api/python/example/test1.wav { "text" : "आपका नाम क्या है" }

docker run -d -p 2700:2700 -v /opt/vosk-model-en/model:/root/.cache/vosk/vosk-model-hi-0.22 alphacep/kaldi-en:latest

[root@10 websocket]# ./test_ffmpeg.py /opt/vosk-api/python/example/test1.wav "conf" : 1.000000, "end" : 1.380000, "start" : 0.900000, "word" : "yahoo" }], "text" : "opta nam yahoo"

helpinghandindia1 commented 1 year ago

@nshmyrev pls tell me how to use Hindi with vosk server.

nshmyrev commented 1 year ago

Try

docker run -p 2700 alphacep/kaldi-hi

i've just pushed it

helpinghandindia1 commented 1 year ago

@nshmyrev I tried and following is output , pls see.

[root@10 ~]# docker run -p 2700 alphacep/kaldi-hi LOG (VoskAPI:ReadDataFiles():model.cc:213) Decoding params beam=13 max-active=7000 lattice-beam=6 LOG (VoskAPI:ReadDataFiles():model.cc:216) Silence phones 1:2:3:4:5:11:12:13:14:15 LOG (VoskAPI:RemoveOrphanNodes():nnet-nnet.cc:948) Removed 0 orphan nodes. LOG (VoskAPI:RemoveOrphanComponents():nnet-nnet.cc:847) Removing 0 orphan components. LOG (VoskAPI:ReadDataFiles():model.cc:249) Loading i-vector extractor from /opt/vosk-model-hi/model/ivector/final.ie LOG (VoskAPI:ComputeDerivedVars():ivector-extractor.cc:183) Computing derived variables for iVector extractor LOG (VoskAPI:ComputeDerivedVars():ivector-extractor.cc:204) Done. LOG (VoskAPI:ReadDataFiles():model.cc:282) Loading HCLG from /opt/vosk-model-hi/model/graph/HCLG.fst LOG (VoskAPI:ReadDataFiles():model.cc:300) Loading words from /opt/vosk-model-hi/model/graph/words.txt LOG (VoskAPI:ReadDataFiles():model.cc:311) Loading winfo /opt/vosk-model-hi/model/graph/phones/word_boundary.int LOG (VoskAPI:ReadDataFiles():model.cc:318) Loading subtract G.fst model from /opt/vosk-model-hi/model/rescore/G.fst LOG (VoskAPI:ReadDataFiles():model.cc:320) Loading CARPA model from /opt/vosk-model-hi/model/rescore/G.carpa LOG (VoskAPI:ReadDataFiles():model.cc:326) Loading RNNLM model from /opt/vosk-model-hi/model/rnnlm/final.raw

[root@10 websocket]# ./test_ffmpeg.py /opt/vosk-api/python/example/test1.wav Traceback (most recent call last): File "./test_ffmpeg.py", line 31, in asyncio.run(run_test('ws://localhost:2700')) File "/usr/local/lib/python3.7/asyncio/runners.py", line 43, in run return loop.run_until_complete(main) File "/usr/local/lib/python3.7/asyncio/base_events.py", line 587, in run_until_complete return future.result() File "./test_ffmpeg.py", line 8, in run_test async with websockets.connect(uri) as websocket: File "/usr/local/lib/python3.7/site-packages/websockets/legacy/client.py", line 642, in aenter return await self File "/usr/local/lib/python3.7/site-packages/websockets/legacy/client.py", line 659, in await_impl_timeout return await asyncio.wait_for(self.await_impl(), self.open_timeout) File "/usr/local/lib/python3.7/asyncio/tasks.py", line 442, in wait_for return fut.result() File "/usr/local/lib/python3.7/site-packages/websockets/legacy/client.py", line 663, in await_impl _transport, _protocol = await self._create_connection() File "/usr/local/lib/python3.7/asyncio/base_events.py", line 971, in create_connection ', '.join(str(exc) for exc in exceptions))) OSError: Multiple exceptions: [Errno 111] Connect call failed ('::1', 2700, 0, 0), [Errno 111] Connect call failed ('127.0.0.1', 2700), [Errno 111] Connect call failed ('192.168.1.12', 2700)

helpinghandindia1 commented 1 year ago

@nshmyrev

thanks

docker run -d -p 2700:2700 alphacep/kaldi-hi
above is working, I am testing more thanks

helpinghandindia1 commented 1 year ago

@nshmyrev

thanks it is now working. It seems connecting with internet not offline ? In our case we was working with complete model for good accuracy not light weight .

pls suggest for better use or improvement to use vosk server with asterisk , as we are not fully aware. thanks

nshmyrev commented 1 year ago

It seems connecting with internet not offline ?

It does not require internet

pls suggest for better use or improvement to use vosk server with asterisk , as we are not fully aware.

You can update vocabulary as described in https://alphacephei.com/vosk/lm

helpinghandindia1 commented 1 year ago

@nshmyrev

Thanks for your suggestion and guidance, Vosk server Hindi is working now. We also need to implement English model also in same server, should we change port?

Helping Hand India NGO

nshmyrev commented 1 year ago

We also need to implement English model also in same server, should we change port?

Yes, you can run on different port

helpinghandindia1 commented 1 year ago

@nshmyrev

Hi, Tried to run Microphone.py but following error, Our requirement would be like , user can speak digit in between 1-10 to reach directly to their goal ivr.

[root@localhost websocket]# pip3 install sounddevice Requirement already satisfied: sounddevice in /usr/local/lib/python3.7/site-packages (0.4.6) Requirement already satisfied: CFFI>=1.0 in /usr/local/lib/python3.7/site-packages (from sounddevice) (1.15.1) Requirement already satisfied: pycparser in /usr/local/lib/python3.7/site-packages (from CFFI>=1.0->sounddevice) (2.21)

./test_microphone.py -u ws://localhost:2700 or [root@localhost websocket]# python3 test_microphone.py Traceback (most recent call last): File "test_microphone.py", line 9, in import sounddevice as sd File "/usr/local/lib/python3.7/site-packages/sounddevice.py", line 57, in from ctypes.util import find_library as _find_library File "/usr/local/lib/python3.7/ctypes/init.py", line 7, in from _ctypes import Union, Structure, Array ModuleNotFoundError: No module named '_ctypes'

Kindly suggest its usage to start with asterisk. thanks

I have tried following but only two modules showing in menuselect list.

./bootstrap ./configure --with-asterisk=/usr --prefix=/usr make

load = res_speech.so -- showing load = res_http_websocket.so -showing load = res_speech_vosk.so -not showing in menuselect.

nshmyrev commented 1 year ago

ModuleNotFoundError: No module named '_ctypes'

Seems like you installed python from source, not from the repo. You need to install libffi-dev and recompile python then. You can find more details here:

https://stackoverflow.com/questions/27022373/python3-importerror-no-module-named-ctypes-when-using-value-from-module-mul

load = res_speech_vosk.so -not showing in menuselect.

You can edit file manually with a text editor

helpinghandindia1 commented 1 year ago

@nshmyrev

docker run -d -p 2700:2700 alphacep/kaldi-hi:latest docker run -d -p 2702:2702 alphacep/kaldi-en:latest

[root@10 websocket]# docker container ls CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 4844f3a9c820 alphacep/kaldi-en:latest "python3 ./asr_serve…" 15 minutes ago Up 15 minutes 2700/tcp, 0.0.0.0:2702->2702/tcp, :::2702->2702/tcp sharp_elion 24f84267f32a alphacep/kaldi-hi:latest "python3 ./asr_serve…" 19 minutes ago Up 19 minutes 0.0.0.0:2700->2700/tcp, :::2700->2700/tcp distracted_galois

Can you suggest how to use test_ffmpeg.py for two different model/language on same server ?

helpinghandindia1 commented 1 year ago

@nshmyrev test_microphone.py seems working now /usr/local/bin/python3 test_microphone.py { "partial" : "" } { "partial" : ""

can you guide how to use microphone.py with asterisk dialplan so that users can take benefit of direct speaking.

nshmyrev commented 1 year ago

We have separate module for asterisk, see vosk-asterisk project. See also eagi example in vosk-server project.

helpinghandindia1 commented 1 year ago

@nshmyrev

thanks

docker run -d -p 2700:2700 alphacep/kaldi-hi:latest docker run -d -p 2702:2702 alphacep/kaldi-en:latest

[root@10 websocket]# docker container ls CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 4844f3a9c820 alphacep/kaldi-en:latest "python3 ./asr_serve…" 15 minutes ago Up 15 minutes 2700/tcp, 0.0.0.0:2702->2702/tcp, :::2702->2702/tcp sharp_elion 24f84267f32a alphacep/kaldi-hi:latest "python3 ./asr_serve…" 19 minutes ago Up 19 minutes 0.0.0.0:2700->2700/tcp, :::2700->2700/tcp distracted_galois

pls guide how to use two different model/language on same server ? One model is working fine but we need two languages . pls see.

nshmyrev commented 1 year ago

It should be 2702:2700 since local port is still 2700

we have en-hi model between which recognizes both languages

helpinghandindia1 commented 1 year ago

thank @nshmyrev We appreciate your support.

We have already researched same and started.

Hindi model hi is working good but for Indian English we are using en-in, but en-in is not seems good in word recognize. can you suggest some better use/edit for smooth function.

we don't find en-hi model at https://hub.docker.com/u/alphacep

Additionally we appreciate if you able to guide microphone.py with asterisk dialplan step by step, so that users can take benefit directly, as of now we are making wav first for workings.

Again tried to recompile with vosk-asterisk but not found - res_speech_vosk.so

thanks