Added error checking for alsa read errors
This commit is contained in:
parent
5682590ced
commit
d7e879f312
@ -1,3 +1,4 @@
|
|||||||
|
import logging
|
||||||
from typing import Optional, Tuple
|
from typing import Optional, Tuple
|
||||||
import alsaaudio
|
import alsaaudio
|
||||||
import tempfile
|
import tempfile
|
||||||
@ -44,10 +45,24 @@ class SlicedRecorder(Thread):
|
|||||||
current_working_file_name, current_working_file = self._request_new_file()
|
current_working_file_name, current_working_file = self._request_new_file()
|
||||||
current_samples_saved = 0
|
current_samples_saved = 0
|
||||||
|
|
||||||
|
read_failures = 0
|
||||||
|
|
||||||
while self._active:
|
while self._active:
|
||||||
length, data = self._inp.read()
|
try:
|
||||||
|
length, data = self._inp.read()
|
||||||
|
except alsaaudio.ALSAAudioError as e:
|
||||||
|
logging.exception(e)
|
||||||
|
|
||||||
|
read_failures += 1
|
||||||
|
if read_failures >= 30:
|
||||||
|
logging.error("Too many ALSA Read errors. Bailing out...")
|
||||||
|
self._active = False
|
||||||
|
return
|
||||||
|
|
||||||
|
continue
|
||||||
|
|
||||||
if length > 0: # will be always larger than zero (except on error)
|
if length > 0: # will be always larger than zero (except on error)
|
||||||
|
read_failures = 0
|
||||||
file_size_after_append = current_samples_saved + length
|
file_size_after_append = current_samples_saved + length
|
||||||
|
|
||||||
if file_size_after_append > self._samples_per_slice: # Appending this would cause a too big slice
|
if file_size_after_append > self._samples_per_slice: # Appending this would cause a too big slice
|
||||||
|
Loading…
Reference in New Issue
Block a user