Add try except clauses to make more robust
parent
b5c38ee71a
commit
09e8b91ad2
|
@ -59,8 +59,12 @@ def test_pocketsphinx(listener: PocketsphinxListener, data_files) -> Stats:
|
|||
print('===', name, '===')
|
||||
negatives, positives = [], []
|
||||
for filename in filenames:
|
||||
with wave.open(filename) as wf:
|
||||
frames = wf.readframes(wf.getnframes())
|
||||
try:
|
||||
with wave.open(filename) as wf:
|
||||
frames = wf.readframes(wf.getnframes())
|
||||
except (OSError, EOFError):
|
||||
print('?', end='', flush=True)
|
||||
continue
|
||||
out = listener.found_wake_word(frames)
|
||||
{False: negatives, True: positives}[out].append(filename)
|
||||
print('!' if out else '.', end='', flush=True)
|
||||
|
|
|
@ -36,7 +36,10 @@ def load_audio(file: Any) -> np.ndarray:
|
|||
samples: Sample rate and audio samples from 0..1
|
||||
"""
|
||||
import wavio
|
||||
wav = wavio.read(file)
|
||||
try:
|
||||
wav = wavio.read(file)
|
||||
except EOFError:
|
||||
wav = wavio.Wav(np.array([[]], dtype=np.int16), 16000, 2)
|
||||
if wav.data.dtype != np.int16:
|
||||
raise ValueError('Unsupported data type: ' + str(wav.data.dtype))
|
||||
if wav.rate != pr.sample_rate:
|
||||
|
|
Loading…
Reference in New Issue