SOUND_ON_ALARM still doesn't work

Forum for questions and support relating to the 1.34.x releases only.
Post Reply
kennbr34
Posts: 48
Joined: Sat Jan 14, 2017 6:43 pm

SOUND_ON_ALARM still doesn't work

Post by kennbr34 »

I've had trouble getting this to work since 1.30.4

My 'ZM_DIR_SOUNDS' directory equals 'sounds'. I'm not sure if that means it should be relative to ZM's root or my apache web server's root? (/var/www/html/) But I have a directory called 'sounds' in both and it still does not play any sound.

I have seen lots of other people with issue getting this working too so I'm wondering if someone with it actually working can share their config options.
User avatar
bkjaya1952
Posts: 282
Joined: Sat Aug 25, 2018 3:24 pm
Location: Sri Lanka

Re: SOUND_ON_ALARM still doesn't work

Post by bkjaya1952 »

Please try the method used in the following link

https://bkjaya.wordpress.com/2020/11/08 ... -a-motion/
jperkins
Posts: 50
Joined: Sat Jan 23, 2021 11:08 am

Re: SOUND_ON_ALARM still doesn't work

Post by jperkins »

interesting. thanks for posting

just to clarify:

the sound is being played on the zoneminder server. not thru the zoneminder web interface ?

my server is in the basement but having the zoneminder webpage popup with a sound would be cool.
kennbr34
Posts: 48
Joined: Sat Jan 14, 2017 6:43 pm

Re: SOUND_ON_ALARM still doesn't work

Post by kennbr34 »

Yeah that would be a server-side beep rather than through the client you're viewing from. I did something similar before but need something to play on my laptop when I'm away from home.

The hack I'm using currently utilizes Web Sound API...

Code: Select all

//Make a beep function with the new Web Sound API
var audioContext = AudioContext && new AudioContext();
function beep(amp, freq, ms){//amp:0..100, freq in Hz, ms
  if (!audioContext) return;
  var osc = audioContext.createOscillator();
  var gain = audioContext.createGain();
  osc.connect(gain);
  osc.value = freq;
  gain.connect(audioContext.destination);
  gain.gain.value = amp/100;
  osc.start(audioContext.currentTime);
  osc.stop(audioContext.currentTime+ms/1000);
}
Then I just edit the rest of the javascript in 'views/js/montag.js' to run the 'beep' function...

So instead of...

Code: Select all

if ( false && SOUND_ON_ALARM )
                {
                    // Enable the alarm sound
                    $('alarmSound').removeClass( 'hidden' );
                }
I have...

Code: Select all

if ( SOUND_ON_ALARM ) {
                // Enable the alarm sound
                //Use our new beep function instead
                beep(25,750,500);
          }
Which works (in Chrome at least) but is clunky and I don't like having to redo it every time ZM updates or upgrades.
jperkins
Posts: 50
Joined: Sat Jan 23, 2021 11:08 am

Re: SOUND_ON_ALARM still doesn't work

Post by jperkins »

thanks for the response. I need to get eventserver going before I start making a bunch of noise in my living room . :D Headlights from cars coming down the street at night are an issue I havent resolved yet even using preclusive zones.

for my use case this got me thinking just to modify bkjaya1952 example and have the server ssh via public keys to my linux box in the living room and play the sound. then it would be independent of even the browser. In your case as a road warrior / laptop it probably wouldnt work as well

EDIT - yea my ssh idea was a little more involved. Had to allow the www-data user to ssh to the computer in the living room using public keys.

so in zoneminder the filter called this local bash script which ran a remote script to create the sound in my living room ( yea the sound is barking dogs )

Code: Select all

ssh -o StrictHostKeyChecking=no -i /home/user/zoneminder_keys/id_rsa_zoneminder remote_user@living_room '/home/remote_user/barkme.sh  &>/dev/null'
yes had to use ssh-keygen and ssh-copy-id and change permissions on the new key dir to allow this to happen.

and this snippet helped a lot for debugging as I wasnt able to get debugging working with zmfilter.pl. the issue was probably at my end. you would need a different filter_id

Code: Select all

sudo su -l www-data -s /bin/bash -c ' /usr/bin/perl -wT /usr/bin/zmfilter.pl --filter_id=37'
and for completeness the script that actually plays the dog barking sound. yes I play it 3 times cause pulse audio will sometimes miss the first one if it is currently idle

Code: Select all

#!/bin/bash
for each in 1 2 3;do $(aplay bark.wav );done
Last edited by jperkins on Tue Feb 16, 2021 1:35 am, edited 1 time in total.
kennbr34
Posts: 48
Joined: Sat Jan 14, 2017 6:43 pm

Re: SOUND_ON_ALARM still doesn't work

Post by kennbr34 »

Heh that's one way to get it done. Yeah unfortunately that won't work for my situation though because my biggest need for having an alert sound is when I'm away from home, so no way to predict what host SSH would need to connect to unless I setup a dynamic DNS script at all the places I go, and I have a feeling most won't let me do that lol

That's funny with the dogs... Maybe you could have the zone by your back door or windows play a shotgun racking sound haha

Yeah I had that problem with headlights too. What I found worked really well in that situation was setting the preclusive zone on a highly reflective area of the zone. For me, it's on the white-paint of my window sil. I noticed it was lighting up way before any of the other parts of the zone when cars were still very far away. So I set the preclusive zone on that spot and it cut the false alarms way down. If you can't find a reflective spot like that while analyzing the videos, you could even hang something reflective up to catch the light and then paint the preclusive zone on that in ZM.
Flumpy
Posts: 4
Joined: Mon Mar 08, 2021 3:57 pm

Re: SOUND_ON_ALARM still doesn't work

Post by Flumpy »

bkjaya1952 wrote: Mon Feb 15, 2021 6:02 am Please try the method used in the following link

https://bkjaya.wordpress.com/2020/11/08 ... -a-motion/
I tried this solution and it doesn’t seem to work. I can run the mpg123 command from terminal and sound plays fine but when try and have the command run when the filter is executed no sound is played.

I can’t get my head around the fact that ZM has built in support for sound alerts but it doesn’t work :|
kennbr34
Posts: 48
Joined: Sat Jan 14, 2017 6:43 pm

Re: SOUND_ON_ALARM still doesn't work

Post by kennbr34 »

Flumpy wrote: Mon Mar 08, 2021 4:13 pm
bkjaya1952 wrote: Mon Feb 15, 2021 6:02 am Please try the method used in the following link

https://bkjaya.wordpress.com/2020/11/08 ... -a-motion/
I tried this solution and it doesn’t seem to work. I can run the mpg123 command from terminal and sound plays fine but when try and have the command run when the filter is executed no sound is played.

I can’t get my head around the fact that ZM has built in support for sound alerts but it doesn’t work :|
I think it might be kind of a niche feature and there's probably a lot of issues with browser compatibility. I've read somewhere that it actually works in Internet Explorer.

I've been meaning to just offer up the 'Web Sound API' hack I figured out as a custom skin in 'User Contributions' since all the modifications necessary are only against the skin files.
Flumpy
Posts: 4
Joined: Mon Mar 08, 2021 3:57 pm

Re: SOUND_ON_ALARM still doesn't work

Post by Flumpy »

kennbr34 wrote: Tue Mar 09, 2021 2:35 pm
Flumpy wrote: Mon Mar 08, 2021 4:13 pm
bkjaya1952 wrote: Mon Feb 15, 2021 6:02 am Please try the method used in the following link

https://bkjaya.wordpress.com/2020/11/08 ... -a-motion/
I tried this solution and it doesn’t seem to work. I can run the mpg123 command from terminal and sound plays fine but when try and have the command run when the filter is executed no sound is played.

I can’t get my head around the fact that ZM has built in support for sound alerts but it doesn’t work :|
I think it might be kind of a niche feature and there's probably a lot of issues with browser compatibility. I've read somewhere that it actually works in Internet Explorer.

I've been meaning to just offer up the 'Web Sound API' hack I figured out as a custom skin in 'User Contributions' since all the modifications necessary are only against the skin files.
I am using a raspberry PI with Firefox but could try internet explorer on windows laptop to see if that works. I did discover that on Firefox when using developer tools that the webpage was loading the mp3 file so it’s definitely been recognised in the webpage coding but it doesn’t do anything with it when a motion is detected. I’ll have a try with the web sound API hack and see how I get on
Flumpy
Posts: 4
Joined: Mon Mar 08, 2021 3:57 pm

Re: SOUND_ON_ALARM still doesn't work

Post by Flumpy »

Flumpy wrote: Tue Mar 09, 2021 4:10 pm
kennbr34 wrote: Tue Mar 09, 2021 2:35 pm
Flumpy wrote: Mon Mar 08, 2021 4:13 pm

I tried this solution and it doesn’t seem to work. I can run the mpg123 command from terminal and sound plays fine but when try and have the command run when the filter is executed no sound is played.

I can’t get my head around the fact that ZM has built in support for sound alerts but it doesn’t work :|
I think it might be kind of a niche feature and there's probably a lot of issues with browser compatibility. I've read somewhere that it actually works in Internet Explorer.

I've been meaning to just offer up the 'Web Sound API' hack I figured out as a custom skin in 'User Contributions' since all the modifications necessary are only against the skin files.
I am using a raspberry PI with Firefox but could try internet explorer on windows laptop to see if that works. I did discover that on Firefox when using developer tools that the webpage was loading the mp3 file so it’s definitely been recognised in the webpage coding but it doesn’t do anything with it when a motion is detected. I’ll have a try with the web sound API hack and see how I get on
I have tried the websound API hack with no success, so I tried the following code :-

Code: Select all

 if ( newAlarm ) {
          
            var audioElement = document.createElement('audio');
audioElement.setAttribute('src', '/sounds/tarzan.ogg');
audioElement.load()
audioElement.addEventListener("canplay", function() { 
  audioElement.play(); 
}, true);


alert('play');


          
          if ( POPUP_ON_ALARM ) {
            windowToFront();
          }
        }
The alert pop up works with no problems when alarm status is activated but the sound doesn't play. I have tried various Firefox,Edge and Chrome browser and none played the sound. I feel I'm so close to resolving this one, if I have any success will feed back how I managed it.
User avatar
bkjaya1952
Posts: 282
Joined: Sat Aug 25, 2018 3:24 pm
Location: Sri Lanka

Re: SOUND_ON_ALARM still doesn't work

Post by bkjaya1952 »

Please try
sudo chown -R www-data:www-data /usr/share/zoneminder/www/sounds/alarm.mp3
kennbr34
Posts: 48
Joined: Sat Jan 14, 2017 6:43 pm

Re: SOUND_ON_ALARM still doesn't work

Post by kennbr34 »

Flumpy wrote: Tue Mar 09, 2021 9:42 pm
Flumpy wrote: Tue Mar 09, 2021 4:10 pm
kennbr34 wrote: Tue Mar 09, 2021 2:35 pm

I think it might be kind of a niche feature and there's probably a lot of issues with browser compatibility. I've read somewhere that it actually works in Internet Explorer.

I've been meaning to just offer up the 'Web Sound API' hack I figured out as a custom skin in 'User Contributions' since all the modifications necessary are only against the skin files.
I am using a raspberry PI with Firefox but could try internet explorer on windows laptop to see if that works. I did discover that on Firefox when using developer tools that the webpage was loading the mp3 file so it’s definitely been recognised in the webpage coding but it doesn’t do anything with it when a motion is detected. I’ll have a try with the web sound API hack and see how I get on
I have tried the websound API hack with no success, so I tried the following code :-

Code: Select all

 if ( newAlarm ) {
          
            var audioElement = document.createElement('audio');
audioElement.setAttribute('src', '/sounds/tarzan.ogg');
audioElement.load()
audioElement.addEventListener("canplay", function() { 
  audioElement.play(); 
}, true);


alert('play');


          
          if ( POPUP_ON_ALARM ) {
            windowToFront();
          }
        }
The alert pop up works with no problems when alarm status is activated but the sound doesn't play. I have tried various Firefox,Edge and Chrome browser and none played the sound. I feel I'm so close to resolving this one, if I have any success will feed back how I managed it.
Sorry not to side-track the issue, but what browser is the windowToFront() method working for you in?

That's unforatune the Web Sound API didn't work. It worked for me in Firefox and Chrome, but I'm also only using it on Linux desktops, no Windows.
Flumpy
Posts: 4
Joined: Mon Mar 08, 2021 3:57 pm

Re: SOUND_ON_ALARM still doesn't work

Post by Flumpy »

kennbr34 wrote: Wed Mar 10, 2021 10:10 am
Flumpy wrote: Tue Mar 09, 2021 9:42 pm
Flumpy wrote: Tue Mar 09, 2021 4:10 pm
I am using a raspberry PI with Firefox but could try internet explorer on windows laptop to see if that works. I did discover that on Firefox when using developer tools that the webpage was loading the mp3 file so it’s definitely been recognised in the webpage coding but it doesn’t do anything with it when a motion is detected. I’ll have a try with the web sound API hack and see how I get on
I have tried the websound API hack with no success, so I tried the following code :-

Code: Select all

 if ( newAlarm ) {
          
            var audioElement = document.createElement('audio');
audioElement.setAttribute('src', '/sounds/tarzan.ogg');
audioElement.load()
audioElement.addEventListener("canplay", function() { 
  audioElement.play(); 
}, true);


alert('play');


          
          if ( POPUP_ON_ALARM ) {
            windowToFront();
          }
        }
The alert pop up works with no problems when alarm status is activated but the sound doesn't play. I have tried various Firefox,Edge and Chrome browser and none played the sound. I feel I'm so close to resolving this one, if I have any success will feed back how I managed it.
Sorry not to side-track the issue, but what browser is the windowToFront() method working for you in?

That's unforatune the Web Sound API didn't work. It worked for me in Firefox and Chrome, but I'm also only using it on Linux desktops, no Windows.
I’ve not really done anything with the windowToFront method so don’t know what browsers it works in. The sound is now ok with the code I posted earlier once realised the path to the sound file was incorrect!
User avatar
bkjaya1952
Posts: 282
Joined: Sat Aug 25, 2018 3:24 pm
Location: Sri Lanka

Re: SOUND_ON_ALARM still doesn't work

Post by bkjaya1952 »

Please refer the following link https://bkjaya.wordpress.com/2020/11/08 ... -a-motion/ & try the following steps on the Ubuntu terminal

sudo chmod +x /usr/share/zoneminder/www/sounds/alarm.mp3

sudo vsudo

Then add the following line to the opened file and save

ALL ALL = (root) NOPASSWD: /usr/share/zoneminder/www/sounds/alarm.mp3
Screenshot from 2021-06-09 22-22-56.png
Screenshot from 2021-06-09 22-22-56.png (67.7 KiB) Viewed 3648 times
Post Reply