Groups
We are starting to monitor nest boxes located in far away remote locations without 5G, we wanted to place a CT but with the hatchlings movement will take up too much space and non esencial content will be recorded. Since the specie makes lots of noise during feeding hours, acoustic triggering might be the best. We would like to know if there's any chance that some CT models can be paired with acoustic recorders or something of the sort that can allow that, since the info on the internet seems very limited about the subject. I know that for some bats it's been used but not much more. If this option doesn't work we might have to install starlink but we would rather avoid solar panels and cables since local fauna will distrub it. Thanks!!
28 December 2024 6:37pm
Do you have tye acoustic model code that can detect the event ?
28 December 2024 6:37pm
Sadly Im no good at high level coding but the idea is that the microphone attached to the CT detecting the noises would trigger the camera with noises over 60db. With chat gpt help I managed to get this, but it might be full of mistakes (I can manage simple codes but not this haha):
import pyaudio
import numpy as np
# Constants
THRESHOLD_DB = 60 # Threshold in decibels
CHUNK = 1024 # Number of audio samples per frame
FORMAT = pyaudio.paInt16
CHANNELS = 1
RATE = 44100 # Sample rate
def db_from_rms(rms):
"""Convert RMS value to decibels."""
return 20 * np.log10(rms) if rms > 0 else -float('inf')
def noise_callback():
"""Function to execute when noise exceeds the threshold."""
print("Noise threshold exceeded! Activating event...")
# Initialize PyAudio
p = pyaudio.PyAudio()
# Open stream
stream = p.open(format=FORMAT,
channels=CHANNELS,
rate=RATE,
input=True,
frames_per_buffer=CHUNK)
print("Listening for noise...")
try:
while True:
# Read audio data
data = np.frombuffer(stream.read(CHUNK, exception_on_overflow=False), dtype=np.int16)
rms = np.sqrt(np.mean(np.square(data))) # Calculate RMS value
db = db_from_rms(rms) # Convert RMS to decibels
if db > THRESHOLD_DB:
noise_callback()
except KeyboardInterrupt:
print("Stopping...")
finally:
stream.stop_stream()
stream.close()
p.terminate()
28 December 2024 6:37pm
Ah okay. I have a platform that could in principle something like that. But it’s power hungry and you mentioned you can’t use solar cells.
28 December 2024 6:37pm
I only would modify slightly the python code
import pyaudio
import numpy as np
# Constants
THRESHOLD_DB = 10 # Threshold in decibels
CHUNK = 1024 # Number of audio samples per frame
FORMAT = pyaudio.paInt16
CHANNELS = 1
RATE = 44100 # Sample rate
NOISE_WINDOW = 4
INHIBIT_WINDOW = 44
threshold = 10 ** (THRESHOLD_DB / 10)
alpha = 2 / NOISE_WINDOW
def noise_callback(val,noise):
"""Function to execute when noise exceeds the threshold."""
print(val,noise,": Noise threshold exceeded! Activating event...")
# Initialize PyAudio
p = pyaudio.PyAudio()
# Open stream
stream = p.open(format=FORMAT,
channels=CHANNELS,
rate=RATE,
input=True,
frames_per_buffer=CHUNK)
print("Listening for noise...")
val = 0
noise = 0
inhibit: int = INHIBIT_WINDOW
try:
while True:
# Read audio data
data = np.frombuffer(stream.read(CHUNK, exception_on_overflow=False), dtype=np.int16)
data = data.astype(np.float64)
mean_squared = (data * data).mean()
if mean_squared > threshold * noise:
if inhibit == 0: # only trigger once in INHIBIT_WINDOW
noise_callback(mean_squared,noise)
inhibit = INHIBIT_WINDOW # reset inhibit counter
inhibit = max(0, inhibit - 1) # decrease inhibit counter
noise = noise + alpha * (mean_squared - noise)
except KeyboardInterrupt:
print("Stopping...")
finally:
stream.stop_stream()
stream.close()
p.terminate()
There are following changes (tried it on PC)
- For detection do not use rms and dB but only mean-squared (i.e. power domain)
- Use a proper threshold detector that uses Signal-to-Noise-Ratio
- Estimate background noise with a exponential moving average (4 is about 0.1 second)
- Ensure that trigger is only called once every x seconds (44 is about 1 second)
- To visualize the detection numbers they were passed to the callback
- reduced the THRESHOLD_DB to a reasonable value (maybe to be increased a little bit, but was good for testing)
28 December 2024 6:37pm
Wow so greatful!! thanks so much! We are exploring options so we definetly could try to set up solar panels and all. The thing is that it is very difficult to access to the area, so mantinance would be every 3-4 weeks . But please do elaborate about the platform you mention, because no solar panels is more of a preference, but if need it it could be done (hiding cables and maybe covering with a netted fence the solar panel).
28 December 2024 6:37pm
Well, I have an audio recording project (https://github.com/hcfman/sbts-aru), that records potentially with highly accurate clock if you want to do sound localization, but you can use it to both record sounds and process an audio pipeline at the same time. And I have an AI object detector and video alerting project that handles input and output I/O as well. But it has a flexible state machine build in. It doesn't have to trigger with video, it's trivial to make it trigger from anything else. Such as the audio reaching a certain level, or even an audio pipeline recognising a certain sound. It's just a rest http call to the state machine, then it can capture video frames, with pre-capture if needed as well.
It draws a lot of power though. But I haven't tested the power usage when not running with anb object detector though. The lowest power Pi it can run on is a Raspberry Pi 4.
I have intentions to combine the two of these projects at some point to make something that can trigger on both object detection and also audio detection. When I get time... which is the only barrier. Bit it's not my highest prio right now.
It would definately need solar panels though to make it run for a long time. But in principle it would likely not be very hard to tweak it to trigger on sound. If this becomes a really must have bit of functionality, you could reach out to me directly. But it might be a couple of months before I could put any time into something like this.
I know that various people are interested in things like detecting chainsaw sounds. This could do that sort of thing with the right pipeline, but I haven't even started to play with audio analysis pipelines yet.
28 December 2024 6:37pm
That's great, we are in no hurry since this would be for next year's reproduction season. We would also be interested in the Ai that you mention if it's able to detect big size birds (working with the southern ground hornbill). That way the camera would trigger whenever the parents enter the nestbox. I asked a little bit and solar panels shouldn't be an issue. But to explain it in a more detailed way (exactly what will be need it, which camereas can be paired with the program, anything else relevant, etc) maybe we could keep the conversation through email: quimagell@hotmail.com
Im trying to explain everything to my bosses and would be great to know exactly what will be needed besaides solar panels and the camera (since this kind of technology is really new we might need some clear instructions and guidance, my knowlodge extens to CT and solar panels to power survillance cameras at nests but that would be it..). Thanks so much before hand!
28 December 2024 6:37pm
Sounds good, will do.
Kim Hendrikse