Archive for December, 2009

Changing the speed of an audio file with sox

A nice and versatile tool for command-line audio processing is sox. This tool allows applying several filters among which a filter to do time scale modification.

First install sox:

apt-get install sox libsox-fmt-all lame

To speed up a filewith a factor 1.5 you can use the following command:

sox original.wav speedy.wav tempo 1.5

When using this method for speeding up speech, the resulting speech sounds like slurring. To get better results put the optional argument segment size to 30 (see manual) for example:

sox original.wav speedy.wav tempo 1.5 30

When sox is compiled without mp3 encoding support (default in ubuntu) the following command allows a conversion between mp3 files

sox original.mp3 -t wav - tempo 1.5 30| lame --abr 128 - speedy.mp3

Using multiple input files to generate one large output file is also possible in the following way:

sox 1.mp3 2.mp3 3.mp3 combined.mp3 tempo 1.5 30

or even

sox *.mp3 combined.mp3 tempo 1.5 30

Tags: ,

Thursday, December 17th, 2009 Uncategorized No Comments

Knowing the thread ID of a thread (gettid)

The following piece of code prints the gettid (which is the same as the PID, since this is the only thread).

#include <unistd.h>
#include <sys/syscall.h>
#include <sys/types.h>
#include <stdio.h>

int main()
  printf("Hello World! I am thread %d\n", syscall(SYS_gettid));
Tuesday, December 15th, 2009 Uncategorized No Comments

Checking admissable values in a C++ template

The following piece of example code checks the values passed to a template. If the instantiation value is not 1, the BOOST_STATIC_ASSERT will generate a compiler error.


template class Beeblebrox
//BOOST_STATIC_ASSERT((T == boost::mpl::int_<2>::type::value)); // "official" way of doing it; no idea if you really need this to be so complex; the above line works fine

int main()
Beeblebrox<1> b; // this will pass the static assert
Beeblebrox<2> b; // this will fail
std::cout << "Hello World!\n";

Tags: , ,

Sunday, December 13th, 2009 Uncategorized No Comments

GRUB (version 1) boot a kernel only once if it fails

To specify to GRUB that it boots a kernel only once and if it fails, it should boot another one, use the fallback option. Given some kernel “linux-” that you are sure works, you add.


to menu.lst.

Tuesday, December 8th, 2009 Uncategorized No Comments

Getting MBROLA voices to work with espeak

Install espeak and MBROLA:

sudo apt-get install espeak mbrola

Download an MBROLA voice from: For example the german de5 voice.

Extract the voice to /usr/share/mbrola. Find out the location of your voice file (e.g. /usr/share/mbrola/de5/de5.)

Check if espeak knows your newly installed MBROLA voice. For the de5 check if  the following file exists:


To convert a text file to a wave file with a speed of 250 words per minute, you can use the following command:

 espeak -v mb-de5 -f test.txt -s 250 | mbrola -e /usr/share/mbrola/de5/de5 - test.wav 

Tags: , ,

Sunday, December 6th, 2009 Uncategorized No Comments

Creating a self signed SSL certificate for dovecot and postfix

The script below helps creating a self signed SSL certificate for use with dovecot and postfix.

When using the script consider the following:

  • Dovecot and Postfix use key: /etc/ssl/private/ssl-mail.key
  • Dovecot and Postfix use certificate: /etc/ssl/certs/ssl-mail.pem
  • Enter a password that is at least 4 characters long
  • When filling in the content of the certificate, make sure the Common Name (CN) contains your domain name.
  • The paths are currently hard-coded in the script, if you want different results, please adjust the script.

The script was created for an ubuntu 9.10 environment.

This is the shell script for generation of the self-signed certificate: When you use it


echo Enter private key password, 4 characters or more, if this is done incorrect, the rest of the process will fail.
export KPASSWD

echo Changing working directory to temporary path ~/certtmp
mkdir certtmp
cd certtmp

echo Backing up old keys...
DATE=`date +%y%m%d`
cp /etc/ssl/certs/ssl-mail.pem /etc/ssl/certs/ssl-mail.pem.bcp$DATE
cp /etc/ssl/private/ssl-mail.key /etc/ssl/private/ssl-mail.key.bcp$DATE

echo Stopping affected services...
service dovecot stop
service postfix stop

echo Generating certificate...
openssl genrsa -out server.key -des3 -passout pass:$KPASSWD 1024
mv server.key
mv server.key.insecure server.key

openssl rsa -in server.key -out server.key.insecure -passin pass:$KPASSWD
openssl req -new -key server.key -out server.csr -passin pass:$KPASSWD

openssl x509 -req -days 3650 -in server.csr -signkey server.key -out server.crt -passin pass:$KPASSWD

echo Installing certificate to /etc/ssl/certs/server.pem ...
sudo cp server.crt /etc/ssl/certs/server.pem
chown root:root /etc/ssl/certs/server.pem
chmod 644 /etc/ssl/certs/server.pem
ln -sf /etc/ssl/certs/server.pem /etc/ssl/certs/ssl-mail.pem

echo Installing private key /etc/ssl/private/server.key ...
sudo cp server.key /etc/ssl/private/server.key
chown root:ssl-cert /etc/ssl/private/server.key
chmod 640 /etc/ssl/private/server.key
ln -sf /etc/ssl/private/server.key /etc/ssl/private/ssl-mail.key

echo Restarting services...
service postfix start
service dovecot start

echo Clean up...
export KPASSWD

echo "Key file installed to /etc/ssl/private/server.key (with alias /etc/ssl/private/ssl-mail.key)"
echo "Certificate installed to /etc/ssl/certs/server.pem (with alias /etc/ssl/certs/ssl-mail.pem)"
echo "Please make sure postfix and dovecot use /etc/ssl/certs/ssl-mail.pem and /etc/ssl/private/ssl-mail.key"
echo If there are errors, see and please correct this script

Tags: , , ,

Saturday, December 5th, 2009 Uncategorized No Comments