Skip to content

Commit 97c788d

Browse files
committed
Merged master into improved auto detection
2 parents 05c94e6 + 55e7375 commit 97c788d

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

lib/record_data.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def record_controls( key_poller, recordQueue=None ):
6363
if index == 0:
6464
main_state = recorders[mic_index].get_detection_state()
6565
else:
66-
secondary_states[index - 1] = secondary_states[index - 1].get_detection_state()
66+
secondary_states[index - 1] = recorders[mic_index].get_detection_state()
6767
index += 1
6868
print_status(main_state, secondary_states)
6969

@@ -145,7 +145,7 @@ def record_controls( key_poller, recordQueue=None ):
145145
if index == 0:
146146
main_state = recorders[mic_index].get_detection_state()
147147
else:
148-
secondary_states[index - 1] = secondary_states[index - 1].get_detection_state()
148+
secondary_states[index - 1] = recorders[mic_index].get_detection_state()
149149
index += 1
150150
print_status(main_state, secondary_states)
151151
main_state.state = "paused"

lib/stream_recorder.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,10 @@ def resume(self):
108108

109109
def pause(self):
110110
self.stream.stop_stream()
111+
111112
self.index -= len(self.total_audio_frames)
113+
if self.index != 0 and len(self.total_audio_frames) > 0:
114+
self.detection_frames = self.detection_frames[:-len(self.total_audio_frames)]
112115
self.total_audio_frames = []
113116
self.audio_frames = []
114117

@@ -126,14 +129,14 @@ def clear(self, seconds: float) -> bool:
126129
self.current_occurrence = []
127130
self.false_occurrence = []
128131

129-
self.detection_frames = self.detection_frames[:-frames_to_remove]
132+
self.detection_frames = self.detection_frames[:-frames_to_remove]
130133
self.detection_state.ms_recorded = len(self.detection_frames) * ms_per_frame
131134
for label in self.detection_state.labels:
132135
label.ms_detected = 0
133136
for frame in self.detection_frames:
134137
if frame.label == label.label:
135138
label.ms_detected += ms_per_frame
136-
139+
137140
# Just completely overwrite the file if we go back to the start for simplicities sake
138141
if clear_file:
139142
totalWaveFile = wave.open(self.total_wav_filename, 'wb')

lib/wav.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,10 @@ def load_wav_data_from_srt(srt_file: str, source_file: str, feature_engineering_
8989
halfframe_offset = round( frames_to_read * number_channels * 0.5 )
9090
start_offsets = [0, -halfframe_offset] if with_offset else [0]
9191

92-
transition_events = parse_srt_file(srt_file, ms_per_frame)
92+
transition_events = parse_srt_file(srt_file, ms_per_frame)
93+
if len(transition_events) < 2:
94+
print( "Empty .SRT file for " + source_file + " - Consider deleting " + srt_file + " to resegment the audio file" )
95+
9396
for index, transition_event in enumerate(transition_events):
9497
next_event_index = total_frames / frames_to_read if index + 1 >= len(transition_events) else transition_events[index + 1].start_index
9598
audioFrames = []
@@ -108,6 +111,8 @@ def load_wav_data_from_srt(srt_file: str, source_file: str, feature_engineering_
108111
raw_wav = wf.readframes(frames_to_read * number_channels)
109112
except RuntimeError:
110113
raw_wav = ""
114+
print( "Error loading in all of the .SRT file for " + source_file + " - Consider deleting " + srt_file + " to resegment the audio file" )
115+
keep_collecting = False
111116

112117
# Reached the end of wav - do not keep collecting
113118
if (len(raw_wav) != SLIDING_WINDOW_AMOUNT * frames_to_read * number_channels ):

0 commit comments

Comments
 (0)