Add try except clauses to make more robust

pull/10/head
Matthew D. Scholefield 2018-03-08 19:21:32 -06:00
parent b5c38ee71a
commit 09e8b91ad2
2 changed files with 10 additions and 3 deletions

View File

@ -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)

View File

@ -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: