Easiest way to play a sound effect when a block is minted?

Does anyone have some shellscript or ideas how to quickly and easily implement a program/script that would play a sound effect when either nud or bcexchanged has found a new block (ignoring stales/orphans).

Should the script poll the wallet for new incoming TXs or should it monitor the debug.log file for some specific strings?

1 Like

Monitor debug.log and look for string “new block”, then text to speech “Just what do you think you’re doing, Dave?”

1 Like

I’d be happy with just aplay and a wav file of my choice.

https://docs.nubits.com/nu-client-commands/

you can probably use blocknotify in your conf file.

just add blocknotify=<script name> in your conf file to a script that plays a sound.

I think he only wants to hear his own blocks.

ohhhh… then ignore me… here’s a cat :cat:

1 Like

Cat confirmed

2 Likes

But what about walletnotify=<script name>?

1 Like

i’m not sure if that works with block reward transactions, but he could test it.

ok this sounds more plausible than blocknotify. will investigate

Here’s some partly pseudo code for a blocknotify script (in case walletnotify doesn’t work) to start with:

#!/bin/bash
if [ ! -f tx_id_old ]; then
        touch tx_id_old
else
        tx_id_old=$(cat tx_id_old)
        tx_id_new=$(nud listtransactions | tail -n 4 | head -n 1 | awk -F':' '{print $2}')
        if [ "$tx_id_old" == "$tx_id_new" ]; then
        else
#               <execute play sound file script>
        fi
fi

Here’s what I came up with.

nu.conf file:

rpcusername=xxxxx
rpcpassword=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
server=1
walletnotify=/home/pi/Desktop/scripts/money.sh

money.sh:

#!/bin/bash

#Only if current time is more than `first_active_hour` audio will be played. This is to be quiet during the night.
first_active_hour=10

snd=$(( ( RANDOM % 3 )  + 1 ))
sfx_path="/home/pi/Desktop/scripts/sfx/gold_$snd.wav"
hour=`date +%H`

test "$hour" -gt "$first_active_hour" && (timeout --signal=SIGKILL 5s aplay -q "$sfx_path")

exit 0

This worked with blocknotify, played the sound and all, but I haven’t yet managed to find a block so I don’t know if it works with walletnotify.

1 Like

When this is done and figured you could make a gist and we can link it from the raspi tutorial :wink:

1 Like

TIP: if somebody is doing this under MacOS, there is no need to play a wav file, you could execute something like

$ say You minted a new block, congrats

Just reporting that walletnotify seems to do the job very well. I’m still downloading the block chain from scratch but I am constantly hearing this sound effect already, probably because the node receives blocks that include transactions to my wallet that I have minted in the past.