Different results on same audio
- Vorherrschende Sprache
- Jupyter Notebook
- Sterne
- 15.1k
- Forks
- 1.8k
- PR-Merge-Kennzahlen
- Keine gemergten PRs in 30 T.
Beschreibung
When loading the model only once and running decoding on same file with each time new recognizer, results are different.
**Setup**
* `vosk==0.3.32`
* `vosk-model-en-us-0.22`
**Test**
Run decoding on each file 3 times, for every run and file the new recognizer is instantiated. The model is loaded only once.
Now, results of every run is slightly **DIFFERENT** from another.
File: `sample_full.wav`
Example 1
* Run 1 `"... history of the world but i i i will tell you that",`
* Run 2 `"... history of the world i i i i will tell you that",`
Example 2
* Run 2 `love a good debate we love a good argument`
* Run 3 `love a good debate will have a good argument`
Example 3
* Run 2 `learned that thanks to the difficulties of this year`
* Run 3 `learned that thanks for the advice difficulties of this year`
More interesting, when running the script 3 times with one run (practically the model is loaded from disk each time) results are **SAME**!
**Question**
Is it possible that something is cached or not released in the recognizer / model?
**Script**
```python
import json
import os
import vosk # @UnresolvedImport
MODEL_VOSK = 'vosk-model-en-us-0.22'
FOLDER_WAV = 'files'
def vosk_shared(model_name: str, runid: str, num_runs: int=1) -> None:
print()
print('--- VOSK SHARED :: %s :: %s' % (model_name, runid))
path_root = os.path.abspath(os.path.dirname(__file__))
path_wav = os.path.join(path_root, FOLDER_WAV)
path_mdl = os.path.join(path_root, model_name)
_frame_ms = 100
sample_rate = 16_000
# vosk.SetLogLevel(-1)
model = vosk.Model(path_mdl)
chunk_size = (_frame_ms * sample_rate // 1000) * 2
try:
for n in range(num_runs):
c = n + 1
print('>>> RUN #%s' % c)
if num_runs == 1:
_name = 'vosk-%s' % (runid)
else:
_name = 'vosk-%s_%s' % (runid, c)
path_out = os.path.join(path_root, _name)
if not os.path.exists(path_out):
os.mkdir(path_out)
#
#
for wf in sorted(os.listdir(path_wav)):
if not wf.endswith('.wav'):
continue
print(wf)
wff = os.path.join(path_wav, wf)
results = []
rec = vosk.KaldiRecognizer(model, sample_rate)
rec.SetWords(True)
try:
with open(wff, 'rb') as f:
while True:
data = f.read(chunk_size)
if len(data) == 0:
break
if rec.AcceptWaveform(data):
r = json.loads(rec.Result())
if r['text']:
results.append(r['text'])
r = json.loads(rec.FinalResult())
if r['text']:
results.append(r['text'])
finally:
del rec
results = [r.strip() for r in results if r.strip()]
file_out = os.path.join(path_out, wf.replace('.wav', '.json'))
with open(file_out, 'w') as fout:
json.dump(dict(filename=wf, decoding=results), fout, indent=2)
finally:
del model
def main():
vosk_shared(MODEL_VOSK, 'shared', num_runs=3)
if __name__ == '__main__':
main()
```
[sample_full_results.zip](https://github.com/alphacep/vosk-api/files/8110727/sample_full_results.zip)
[files.zip](https://github.com/alphacep/vosk-api/files/8110728/files.zip)
Beitragsleitfaden
Für dieses Repository ist kein Beitragsleitfaden indexiert
Bewertung
Dieses Issue wurde noch nicht bewertet.