RanzQ / hyperion-audio-effects

Hyperion audio effects dev kit using Gstreamer
MIT License
47 stars 8 forks source link

Auto turn off #25

Closed pete111 closed 7 years ago

pete111 commented 7 years ago

Hello, I would like to turn off audio efects automatically after 5 minutes of inactivity. How can I detect in program if no audio was detected within last 5 minutes? (by "no audio was detected" I mean something like for example no or very low intensity of audio was detected so it means we can turn off main.py - because it drains CPU a lot)

Many thanks

RanzQ commented 7 years ago

The script relies on gstreamer's pipeline which has a static interval parameter. Automatic stop could be implemented but turning on again would be tricky.

pete111 commented 7 years ago

What is "static interval parameter" please? For me is great just to have auto turn off available (so to know how to implement it) - so no need for auto turning it on again.

RanzQ commented 7 years ago

Answered via email.

pete111 commented 7 years ago

Hi RanzQ, many thanks. It looks great for manual job. But I am trying to program it on auto approach, so it means I will be able just to turn off music and go to bed and after some time it will automatically shutdown python main.py when no sound is there. This is great especially for two reasons - no need to manually do it, and it will dramatically reduce CPU load and produced heat, too (if Pi is in enclosure). :) So I am continuing in finding the right solution for this.

RanzQ commented 7 years ago

Just ask here if you can't figure something out. The program is multithreaded so if you are new to programming it's something that makes things a bit more complicated. :)

pete111 commented 7 years ago

thanks for your help :) I thing this is out of my programming skills - I spent several hours on receive_magnitudes functions. I thing I should save magnitudes for example during one minute and check them each time they update if they are the same during one minute. If yes, then I execute terminating of script. BUT I can be completely wrong of course.

RanzQ commented 7 years ago

I would do something like this:


# init these in file start for example

silent_samples = 0
magnitude_threshold = 100
silence_threshold = 500

# check this before the callback (`...callback(magnitudes)`):

mag_sum = sum(magnitudes)

if mag_sum < magnitude_threshold:
    silent_samples += 1
else:
    silent_samples = 0

if silent_samples > silence_threshold:
    stop()

# for debug
print "mag_sum: " + str(mag_sum) + " silent_samples: " + str(silent_samples)

Adjust the thresholds until it works (just wrote it, didn't check for errors). :)

There's a lot to be improved in performance which I should do when I find some time. That should reduce the CPU hogging.