Author

Topic: Play a sound every time /anyone/ finds a new block. (Perl script inside). (Read 1749 times)

newbie
Activity: 32
Merit: 0
Neat.  Works for me.  you can also change the mplayer line to use a text to speech robot voice to tell you about the new block :

Quote
`echo 'new block' | espeak 2> /dev/null`;

here's a "fembot"
Quote
`echo 'bit coins!' | fembot 2> /dev/null`;

requires this  espeak hack.  


Cool patch Wink. Thanks!
full member
Activity: 140
Merit: 100
BitVapes.com
Neat.  Works for me.  you can also change the mplayer line to use a text to speech robot voice to tell you about the new block :

Quote
`echo 'new block' | espeak 2> /dev/null`;

here's a "fembot"
Quote
`echo 'bit coins!' | fembot 2> /dev/null`;

requires this  espeak hack.  
newbie
Activity: 32
Merit: 0
Hello everyone,

I made a Perl script that I want to share with you. It plays a sound every time anyone finds a new block. It's very short and you can download it here:

https://gist.github.com/1155780

It's written for GNU/Linux. I'll cut-n-paste the instructions from the file itself:

Quote
## Program name: make_sound_on_new_block.pl v1.0 (for GNU/Linux).
## (c) 2011, Tomislav Dugandzic (neo101.org).
## License: GPLv2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html).

## Description:
## This Perl script plays a sound each time anyone has found a new Bitcoin block. Run it in a terminal and leave it running.
## It does these checks once a second.
## The purpose for this program to exist is so that Bitcoin users can do others things while waiting for transaction verifications to complete. A sound will be played when done.
## That way we don't have to stare at the bitcoin client to see the block count increase slowly and intermittently. Bitcoin exchanges tend to not let you use your bitcoins until
## a certain number of new blocks have been generated, after your transaction. Ideally this kind of audio notification would be integrated in the bitcoin client. But you can
## use this until someone implements it in the main client.
##
## What you need for this to work:
## 1. You need the Perl interpreter program installed.
## 2. You need to have the "mplayer" program installed.
## 3. You need to have this perl script file in your ~/.bitcoin/ directory.
## 4. You need to have your bitcoin client update the debug.log file. This is currently (2011-08-19) already so by default.
## 5. You need to have the mp3 file you want to be played, in the ~/.bitcoin/ directory.
## 6. You need to have your bitcoin client running.
## 7. You need to run this perl script from a terminal and leave it running.
##
## I commented this program in great detail so that programmers who don't speak Perl more easily can verify that this
## doesn't try to steal your wallet.dat file or tries to be bad in other ways.

Oh, and it seems like this forum allows code to be posted inline as well. So I'll do that too:

Code:
#!/usr/bin/perl

## Program name: make_sound_on_new_block.pl v1.0 (for GNU/Linux).
## (c) 2011, Tomislav Dugandzic (neo101.org).
## License: GPLv2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html).

## Description:
## This Perl script plays a sound each time anyone has found a new Bitcoin block. Run it in a terminal and leave it running.
## It does these checks once a second.
## The purpose for this program to exist is so that Bitcoin users can do others things while waiting for transaction verifications to complete. A sound will be played when done.
## That way we don't have to stare at the bitcoin client to see the block count increase slowly and intermittently. Bitcoin exchanges tend to not let you use your bitcoins until
## a certain number of new blocks have been generated, after your transaction. Ideally this kind of audio notification would be integrated in the bitcoin client. But you can
## use this until someone implements it in the main client.
##
## What you need for this to work:
## 1. You need the Perl interpreter program installed.
## 2. You need to have the "mplayer" program installed.
## 3. You need to have this perl script file in your ~/.bitcoin/ directory.
## 4. You need to have your bitcoin client update the debug.log file. This is currently (2011-08-19) already so by default.
## 5. You need to have the mp3 file you want to be played, in the ~/.bitcoin/ directory.
## 6. You need to have your bitcoin client running.
## 7. You need to run this perl script from a terminal and leave it running.
##
## I commented this program in great detail so that programmers who don't speak Perl more easily can verify that this
## doesn't try to steal your wallet.dat file or tries to be bad in other ways.

while (){

  $cli_data = `tail -n 1000 debug.log | grep -i best | tail -n 1`; ## Look at the last 1000 lines in the debug.log file, pick the last line, and see if there are any lines that describe a newly found block.
  
  $latest_block = $cli_data;
  
  ## The commented line below is how a row we want to find looks like:
  ## SetBestChain: new best=00000000000007ac4781  height=141545  work=85257364198960066368
  $latest_block =~ /new best.* height=(\d{1,16})/; ## This and the next line tries to filter out only the block number from the found line. It looks for any numbers that contain 1-16 digits.
  $latest_block = $1;
  
  if ($previous_block == undef){ ## The first time we run this while-loop, there are no older block numbers that we can compare the latest block number with.
  print "A sound notification will be played each time anyone has found a new block. The currently latest block in your blockchain is: \"$latest_block\".\n";
  $previous_block = $latest_block; ## From here on, we will have an older block number to compare newly found ones with.
  }
  
  if ($latest_block > $previous_block){
  print "Someone found a new block: \"$latest_block\".\n";
  `mplayer ./make_sound_on_new_block.mp3 2> /dev/null`; ## This is the command that uses mplayer to play the mp3 file.
  $previous_block = $latest_block;
  }
    
  sleep 1; ## Wait one second before looking at the debug.log file again.
 
}

I hope you like it Smiley.
Jump to: