Skip to content

Commit c5d1484

Browse files
authored
Merge pull request #9 from SEPIA-Framework/dev
updated README, requirements and added test script
2 parents 93311a4 + cd90638 commit c5d1484

File tree

3 files changed

+57
-12
lines changed

3 files changed

+57
-12
lines changed

src/README.md

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,22 @@
22

33
### Requirements
44

5-
Python 3.7 is recommended.
5+
Python 3.7 is recommended, 3.9 has been tested as well.
66
Please see 'requirements.txt' for more details or check out the **Dockerfile** inside the engines folder (`../engines/`).
7-
Basic setup (the Vosk part might not work on all machines out-of-the-box):
7+
8+
Install recommended Linux packages (Debian 10|11 example):
9+
```
10+
sudo apt-get install -y python3-pip python3-dev python3-setuptools python3-wheel libffi-dev
11+
```
12+
13+
Basic Pip setup (the Vosk part might not work on all machines out-of-the-box):
814

915
```
10-
pip install fastapi
11-
pip install uvicorn[standard]
12-
pip install aiofiles
13-
pip install vosk
16+
pip3 install cffi
17+
pip3 install fastapi
18+
pip3 install uvicorn[standard]
19+
pip3 install aiofiles
20+
pip3 install vosk
1421
```
1522

1623
### Download the Server and ASR Models
@@ -51,4 +58,6 @@ To see all commandline options run `python -m launch --help`.
5158

5259
### Test
5360

54-
Open: `http://localhost:20741/www/index.html`
61+
Open browser: `http://localhost:20741/www/index.html`
62+
63+
Local test (Vosk): `python test_vosk.py [model-path] [test-WAV-path]`

src/requirements.txt

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
fastapi ~= 0.65 # tested: 0.65.1 - newer versions should generally be no problem
2-
uvicorn[standard]
3-
aiofiles
4-
vosk ~= 0.3 # tested: 0.3.30 - result API changes have been announced
5-
# text2num ~= 2.5 # currently included custom version for German support
1+
# Last tested 2021.12.29 with Python 3.9.2
2+
#
3+
cffi ~= 1.15 # tested: 0.15.0
4+
fastapi ~= 0.70 # tested: 0.70.1
5+
uvicorn[standard] ~= 0.16 # tested: 0.16.0
6+
aiofiles ~= 0.8 # tested: 0.8.0
7+
vosk ~= 0.3 # tested: 0.3.32
8+
# text2num ~= 2.5 # custom version already included

src/test_vosk.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/usr/bin/env python3
2+
3+
from vosk import Model, KaldiRecognizer, SetLogLevel
4+
import sys
5+
import os
6+
import wave
7+
8+
SetLogLevel(0)
9+
10+
model_path = sys.argv[1]
11+
if not os.path.exists(model_path):
12+
print ("The model folder'", model_path, "'does not exist.")
13+
exit (1)
14+
15+
wf = wave.open(sys.argv[2], "rb")
16+
if wf.getnchannels() != 1 or wf.getsampwidth() != 2 or wf.getcomptype() != "NONE":
17+
print ("Audio file must be WAV format mono PCM.")
18+
exit (1)
19+
20+
model = Model(model_path)
21+
rec = KaldiRecognizer(model, wf.getframerate())
22+
rec.SetWords(True)
23+
24+
while True:
25+
data = wf.readframes(4000)
26+
if len(data) == 0:
27+
break
28+
if rec.AcceptWaveform(data):
29+
print(rec.Result())
30+
else:
31+
print(rec.PartialResult())
32+
33+
print(rec.FinalResult())

0 commit comments

Comments
 (0)