wip
This commit is contained in:
parent
c165442acc
commit
3b483805df
1 changed files with 10 additions and 6 deletions
16
process
16
process
|
@ -26,6 +26,7 @@ MIN_SIGNAL_QUALITY = 1000.0 # maximum noise level (relative DB) to consider a de
|
||||||
PLOT_PADDING_START_SECONDS = 2 # seconds (padding before and after the event in the plot)
|
PLOT_PADDING_START_SECONDS = 2 # seconds (padding before and after the event in the plot)
|
||||||
PLOT_PADDING_END_SECONDS = 3 # seconds (padding before and after the event in the plot)
|
PLOT_PADDING_END_SECONDS = 3 # seconds (padding before and after the event in the plot)
|
||||||
|
|
||||||
|
|
||||||
def process_recording(filename):
|
def process_recording(filename):
|
||||||
print('processing', filename)
|
print('processing', filename)
|
||||||
|
|
||||||
|
@ -108,13 +109,19 @@ def process_recording(filename):
|
||||||
sample_num += samples_per_block - overlapping_samples
|
sample_num += samples_per_block - overlapping_samples
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def write_event(current_event, sound, samplerate):
|
|
||||||
# write a spectrogram using the sound from start to end of the event
|
# write a spectrogram using the sound from start to end of the event
|
||||||
|
def write_event(current_event, sound, samplerate):
|
||||||
event_start_sample = current_event['start_sample'] - samplerate * PLOT_PADDING_START_SECONDS
|
event_start_sample = current_event['start_sample'] - samplerate * PLOT_PADDING_START_SECONDS
|
||||||
event_end_sample = current_event['end_sample'] + samplerate * PLOT_PADDING_END_SECONDS
|
event_end_sample = current_event['end_sample'] + samplerate * PLOT_PADDING_END_SECONDS
|
||||||
event_clip = sound[event_start_sample:event_end_sample]
|
event_clip = sound[event_start_sample:event_end_sample]
|
||||||
event = current_event['start_at'] - datetime.timedelta(seconds=PLOT_PADDING_START_SECONDS)
|
event = current_event['start_at'] - datetime.timedelta(seconds=PLOT_PADDING_START_SECONDS)
|
||||||
|
filename_prefix = current_event['start_at'].strftime('%Y-%m-%d_%H-%M-%S.%f%z')
|
||||||
|
|
||||||
|
# write flac
|
||||||
|
flac_path = os.path.join(DETECTIONS_DIR, f"{filename_prefix}.flac")
|
||||||
|
soundfile.write(flac_path, event_clip, samplerate, format='FLAC')
|
||||||
|
|
||||||
|
# write spectrogram
|
||||||
plt.figure(figsize=(8, 6))
|
plt.figure(figsize=(8, 6))
|
||||||
plt.specgram(event_clip, Fs=samplerate, NFFT=samplerate, noverlap=samplerate//2, cmap='inferno', vmin=-100, vmax=-10)
|
plt.specgram(event_clip, Fs=samplerate, NFFT=samplerate, noverlap=samplerate//2, cmap='inferno', vmin=-100, vmax=-10)
|
||||||
plt.title(f"Bootshorn @{event.strftime('%Y-%m-%d %H:%M:%S')}")
|
plt.title(f"Bootshorn @{event.strftime('%Y-%m-%d %H:%M:%S')}")
|
||||||
|
@ -122,12 +129,9 @@ def write_event(current_event, sound, samplerate):
|
||||||
plt.ylabel("Frequency (Hz)")
|
plt.ylabel("Frequency (Hz)")
|
||||||
plt.colorbar(label="Intensity (dB)")
|
plt.colorbar(label="Intensity (dB)")
|
||||||
plt.ylim(50, 1000)
|
plt.ylim(50, 1000)
|
||||||
spectrogram_path = os.path.join(DETECTIONS_DIR, f"{current_event['start_at'].strftime('%Y-%m-%d_%H-%M-%S.%f%z')}.png")
|
spectrogram_path = os.path.join(DETECTIONS_DIR, f"{filename_prefix}.png")
|
||||||
plt.savefig(spectrogram_path)
|
plt.savefig(spectrogram_path)
|
||||||
plt.close()
|
plt.close()
|
||||||
# write flac
|
|
||||||
flac_path = os.path.join(DETECTIONS_DIR, f"{current_event['start_at'].strftime('%Y-%m-%d_%H-%M-%S.%f%z')}.flac")
|
|
||||||
soundfile.write(flac_path, event_clip, samplerate, format='FLAC')
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|
Loading…
Reference in a new issue