wip
This commit is contained in:
parent
da4d78aa8f
commit
6c06c42e85
1 changed files with 14 additions and 6 deletions
20
process
20
process
|
@ -19,7 +19,8 @@ DETECT_FREQUENCY_FROM = DETECT_FREQUENCY - DETECT_FREQUENCY_TOLERANCE # Hz
|
||||||
DETECT_FREQUENCY_TO = DETECT_FREQUENCY + DETECT_FREQUENCY_TOLERANCE # Hz
|
DETECT_FREQUENCY_TO = DETECT_FREQUENCY + DETECT_FREQUENCY_TOLERANCE # Hz
|
||||||
ADJACENCY_FACTOR = 2 # area to look for the frequency (e.g. 2 means 100Hz to 400Hz for 200Hz detection)
|
ADJACENCY_FACTOR = 2 # area to look for the frequency (e.g. 2 means 100Hz to 400Hz for 200Hz detection)
|
||||||
BLOCK_SECONDS = 3 # seconds (longer means more frequency resolution, but less time resolution)
|
BLOCK_SECONDS = 3 # seconds (longer means more frequency resolution, but less time resolution)
|
||||||
DETECTION_DISTANCE = 30 # seconds (minimum time between detections)
|
DETECTION_DISTANCE_SECONDS = 30 # seconds (minimum time between detections)
|
||||||
|
DETECTION_DISTANCE_BLOCKS = DETECTION_DISTANCE_SECONDS // BLOCK_SECONDS # number of blocks to skip after a detection
|
||||||
BLOCK_OVERLAP_FACTOR = 0.9 # overlap between blocks (0.2 means 20% overlap)
|
BLOCK_OVERLAP_FACTOR = 0.9 # overlap between blocks (0.2 means 20% overlap)
|
||||||
MIN_SIGNAL_QUALITY = 1000.0 # maximum noise level (relative DB) to consider a detection valid
|
MIN_SIGNAL_QUALITY = 1000.0 # maximum noise level (relative DB) to consider a detection valid
|
||||||
|
|
||||||
|
@ -32,7 +33,7 @@ def process_recording(filename):
|
||||||
|
|
||||||
# get data and metadata from recording
|
# get data and metadata from recording
|
||||||
path = os.path.join(RECORDINGS_DIR, filename)
|
path = os.path.join(RECORDINGS_DIR, filename)
|
||||||
samplerate = soundfile.info(path).samplerate
|
sound, samplerate = soundfile.read(path)
|
||||||
samples_per_block = int(BLOCK_SECONDS * samplerate)
|
samples_per_block = int(BLOCK_SECONDS * samplerate)
|
||||||
overlapping_samples = int(samples_per_block * BLOCK_OVERLAP_FACTOR)
|
overlapping_samples = int(samples_per_block * BLOCK_OVERLAP_FACTOR)
|
||||||
|
|
||||||
|
@ -41,8 +42,11 @@ def process_recording(filename):
|
||||||
|
|
||||||
# read blocks of audio data with overlap from sound variable
|
# read blocks of audio data with overlap from sound variable
|
||||||
sample_num = 0
|
sample_num = 0
|
||||||
for block in soundfile.blocks(path, blocksize=samples_per_block, overlap=overlapping_samples):
|
while sample_num < len(sound):
|
||||||
sample_num += samples_per_block - overlapping_samples
|
# get block of audio data
|
||||||
|
block_start = sample_num
|
||||||
|
block_end = min(sample_num + samples_per_block, len(sound))
|
||||||
|
block = sound[block_start:block_end]
|
||||||
|
|
||||||
# calculate FFT
|
# calculate FFT
|
||||||
labels = rfftfreq(len(block), d=1/samplerate)
|
labels = rfftfreq(len(block), d=1/samplerate)
|
||||||
|
@ -95,9 +99,10 @@ def process_recording(filename):
|
||||||
write_plot()
|
write_plot()
|
||||||
|
|
||||||
current_event = None
|
current_event = None
|
||||||
#block_num += (DETECTION_DISTANCE // BLOCK_SECONDS) * samples_per_block
|
sample_num += DETECTION_DISTANCE_BLOCKS * samples_per_block
|
||||||
|
|
||||||
|
sample_num += samples_per_block - overlapping_samples
|
||||||
|
|
||||||
#block_num += 1
|
|
||||||
|
|
||||||
|
|
||||||
def write_clip():
|
def write_clip():
|
||||||
|
@ -118,6 +123,9 @@ def main():
|
||||||
process_recording(filename)
|
process_recording(filename)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Error processing {filename}: {e}")
|
print(f"Error processing {filename}: {e}")
|
||||||
|
# print stacktrace
|
||||||
|
import traceback
|
||||||
|
traceback.print_exc()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
Loading…
Reference in a new issue