Tips'n'Scripts


Table of Contents

What its all about
1. Text to speech
Base System
Program integration
Opera
KMouth
emerge
2. Misc programs
Mozilla Thunderbird
Opera
XMMS
Current song in mail signature
Broadcasting the song information with icecast
3. Multimedia keys
play
stop
forward
rewind
4. Video editing
Getting the files off the video camera
Removing useless files

List of Examples

1.1. /home/cweiske/scripts/say
1.2. /home/cweiske/scripts/say-de5
1.3. /home/cweiske/scripts/sayparam
1.4. /home/cweiske/scripts/saytime
1.5. /opt/opera/share/opera/ini/standard_menu.ini
1.6. /home/scripts/cweiske/em
2.1. /home/cweiske/scripts/start-tb
2.2. /scripts/mail-popfile
2.3. /home/cweiske/.thunderbird/default/9sm8x38r.slt/prefs.js
2.4. /home/cweiske/scripts/browser
2.5. /home/cweiske/scripts/tb-compose
2.6. /home/cweiske/Documents/mailsignature_song.txt
2.7. /home/cweiske/scripts/mailsignature_song.sh
2.8. /home/cweiske/Documents/mailsignature_song.txt
2.9. /home/cweiske/scripts/xmms_icecast.pl
2.10. /home/cweiske/scripts/xmms_songtitle
3.1. /home/cweiske/.Xmodmap for the Logitech Internet Keyboard
3.2. $KDEDIR/share/config/kdm/Xsession
3.3. /home/cweiske/scripts/play
3.4. /home/cweiske/scripts/stop
3.5. /home/cweiske/scripts/forward
3.6. /home/cweiske/scripts/rewind

What its all about

This document is a collection of settings and scripts I am using on my gentoo laptop and on my former SuSE PC (now a Gentoo one, too). Most time it took some fiddling to get it all working; and I hope I can reduce your time when wanting to achieve the same goals.

It has been written by Christian Weiske and is available at cweiske.de.

There are two versions of this document: Multi-page and all-in-one

Revision History
Revision 1.02004-07-17 
Initial version
Revision 1.12005-11-20 
Video editing

Chapter 1. Text to speech

I use a basic Text-to-Speech system (TTS) for the purpose that the computer can tell me pieces of information instead of that I have to look on the screen.

This is helpful if I e.g. emerge (download & compile) a program in a console the background and work on something different in the foreground. Normally I don't know when the compile process is done; but if the computer tells you that all is done, you don't have always to look onto the console.

Base System

I use the txt2pho program to convert the text into phonemes, and mbrola for transforming the phonemes into spoken audio. I do some extra preprocessing of the text to fit my needs:

Example 1.1. /home/cweiske/scripts/say

#!/bin/sh
if [ x"$#" = x"0" ]; then
  file=/dev/stdin
  else
        file=${1}
fi
cat $file \
| sed 's/\.com/ dot comm /g' \
| sed -r 's/00:([0-9]+)/0 Uhr \1/g' \
| sed -r 's/([0-9]+):00/genau \1 Uhr/g' \
| /usr/share/txt2pho/preproc/preproc /usr/share/txt2pho/preproc/Rules.lst /usr/local/txt2pho/preproc/Hadifix.abk \
| sed 's/cweiske/ c weiske /g' \
| /usr/bin/txt2pho -m \
| /home/cweiske/scripts/say-de5 \
| aplay -

You can pipe your text into the program, e.g. via echo "hello you there" | say or just give a filename which is read. Then there are some conversions to my liking; adresses ending with ".com" are pronounced "dot com" while german addresses ".de" are pronounced "Punkt de", which is the german speak. Then some time conversion is done as the normal is suboptimal. And of course "cweiske" is spoken "c weiske".

The say-de5 is the script for converting the phonemes into audio with the german voice number 5. For fast changing I put this in an extra script so that the pitch and loudness can be specific for every voice.

Example 1.2. /home/cweiske/scripts/say-de5

#!/bin/sh
#german female voice
cat /dev/stdin \
| /usr/bin/mbrola -v3 -f2 -t1 /usr/share/txt2pho/voices/german/de5 - -.au

Now I made another script which just passes all the parameters to the say script, as some programs just can call one program with the text as the parameter (like Opera)

Example 1.3. /home/cweiske/scripts/sayparam

#!/bin/sh
echo $* | say

Last but not least there is a script which tells the time. I put it in a cron job which is called every ten minutes.

Example 1.4. /home/cweiske/scripts/saytime

#!/bin/sh
echo Es ist jetzt `date '+%H:%M'` | say

Program integration

Here is a description of how I integrated the tts scripts into some programs for speech output

Opera

At the beginning, I used to copy the text out of Opera, pasted it into KMouth and let it speak. Then I remembered that one can customize the menus, and now I just have to select the text, right click on it and select "say"...

Example 1.5. /opt/opera/share/opera/ini/standard_menu.ini

...
[Hotclick Popup Menu]
Item, 50872 = Copy
Item, "Say" = "Copy & Execute program,"/home/cweiske/scripts/sayparam","%c"" 
Item, 67652 = Copy to note
...

The only thing missing is a second entry for english text, but that is coming soon I think.

KMouth

The KMouth program is for mutely people, but one can use it for easy tts reading. The only thing you have to set up is

Settings/KMouth/Text to speech/Command for talking. I set it to

echo "%t" | say

emerge

Like described in the tts introduction, I use the tts to tell me that emerging is done. For that I wrote a script called "em" and made a symlink into the bin directory so that I can use it everywhere.

Example 1.6. /home/scripts/cweiske/em

#!/bin/sh
# emerge it
emerge $*

#now say it
#we add a space before so that we can be sure to have a standalone -f parameter
allparams=" $* "

if [ `echo "$allparams" | grep -e ' -f ' | wc -l` = 1 ]; then
    #all downloaded
    text="Es wurde alles herunter geladen"
elif [ $# -eq 1 ] && [ $allparams = "sync" ]; then
    #sync complete
    text="Synchronisation abgeschlossen"
elif [ $1 = "search" ]; then
    #search complete, tell the number of found applications
    number=`emerge $* 2> /dev/null | grep "Applications found :" | sed 's/^.*: //' | sed 's/ ]//'`
    number=`echo $number | sed s/^0$/keine/`
    text="Bei der Suche wurden $number Programme gefunden"
else
    #normal installation
    text="Installation abgeschlossen"
fi
echo "$text" | /home/cweiske/scripts/say &> /dev/null &

I know that the thing with the number of found applications is really bad implemented, but I don't know how to display the output of emerge in color and capuring it the same time...

Chapter 2. Misc programs

Here are some tips and settings I use to integrate programs into each other.

Mozilla Thunderbird

My favourite email program.

When I call thunderbird while there is an open instance, a new instance is started and the "select profile" dialog is shown. I don't like this behaviour, and so here is a script which just activates a running instance if there is one.

Example 2.1. /home/cweiske/scripts/start-tb

#!/bin/sh
sudo /scripts/mail-popfile

if [ `ps -u cweiske | grep thunderbird-bin | wc -l` -eq 0 ]; then
        #echo "start thunderbird new"
        /usr/bin/thunderbird &
else
        #echo "thunderbird is running, just activating"
        thunderbird -remote "xfeDoCommand(openInbox)"
fi

The mail-popfile scripts takes care that stunnel (ssh program) and popfile (spam filter) is started, so that I can filter my mails with popfile and use a SSL connection to the mail server at the same time.

Note

This script has to be run as root, so use sudo from your normal profile

Example 2.2. /scripts/mail-popfile

#!/bin/sh

#stunnel - already running?
numstunnel=`ps uax | grep stunnel | wc -l`
if [ $numstunnel -ge 2 ]; then
        echo "stunnel is running"
else
        echo "starting stunnel"
        /usr/sbin/stunnel
fi

#popfile
numpopfile=`ps uax | grep popfile | grep perl | wc -l`
if [ $numpopfile -ge 1 ]; then
        echo "popfile is running"
else
        echo "starting popfile"
        cd /usr/share/popfile
        ./popfile.pl &
fi

echo "mail-popfile done"

Normally firefox is started when there is a link in an email in thunderbird, but I am addicted to Opera... So I changed the http protocol handler that it starts Opera now

Example 2.3. /home/cweiske/.thunderbird/default/9sm8x38r.slt/prefs.js

...
user_pref("network.protocol-handler.app.http", "/home/cweiske/scripts/browser");
...

with the browser script being the following

Example 2.4. /home/cweiske/scripts/browser

#!/bin/sh
# opens opera with the given url

url="$1"
if [ "x$url" = "x" ]; then
        url="about:blank"
fi

exec opera -newpage "$url"

Now it is comfortable with thunderbird, but I am still missing some things:

  • Tell me the number of newly arrived, non-spam mails

Opera

To call thunderbird on mailto: Links, I set the the email program setting to "Use specific e-mail client" which is set to /home/cweiske/scripts/tb-compose

Example 2.5. /home/cweiske/scripts/tb-compose

#!/bin/sh
# dont' rename it to "thunderbird-compose" or so
# cause the thunderbird will be found in the process list

if pgrep -u `whoami` thunderbird
then
        /opt/MozillaThunderbird/thunderbird -remote "mailto($1)"
else
        /opt/MozillaThunderbird/thunderbird -compose mailto:$1
fi

Here is the predefined subject and text missing, but that's got to be made another time...

XMMS

Current song in mail signature

I use XMMS for playing all my mp3s and oggs; and I like it to have the currently played song appended to my email signature.

For this purpose I have 2 files:

  • One template file with the signature text to which the song title is appended

    Example 2.6. /home/cweiske/Documents/mailsignature_song.txt

    Regards/MfG,
    Christian Weiske
    --
    XMMS is playing now:
  • A script, which appends the song title to the template and saves it as the final signature file

    Example 2.7. /home/cweiske/scripts/mailsignature_song.sh

    #!/bin/sh
    cat /home/cweiske/Documents/mailsignature_song.tpl > /home/cweiske/Documents/mailsignature_song.txt
    echo $1 >> /home/cweiske/Documents/mailsignature_song.txt
  • And the resulting file is set as signature in thunderbird

    Example 2.8. /home/cweiske/Documents/mailsignature_song.txt

    Regards/MfG,
    Christian Weiske
    --
    XMMS is playing now:
    Christina Aguilera - Impossible

Now all I did was to use the songchange plugin in XMMS to call the mailsignature_song.sh script every time a new title is played.

Broadcasting the song information with icecast

I use icecast in connection with XMMS to broadcast the currently played song over the network to have control about what is played at the computer with the sound system at work...

One doesn't need to do this, but it is a nice feature to see the song title and author in the remote player. Once again I used the songchange plugin for XMMS to write title and author into a file

Example 2.9. /home/cweiske/scripts/xmms_icecast.pl

#!/usr/bin/perl
@trackinfo=split(/ - /, $ARGV[0]);
system("echo \"TITLE=$trackinfo[1]\" > /home/cweiske/trackinfo.txt");
system("echo \"ARTIST=$trackinfo[0]\" >> /home/cweiske/trackinfo.txt");
system("killall -USR1 ices");

Note

I didn't write this script; it is from the icecast website.

Now there are 2 scripts which are to be called by the songchange plugin, and as this can call only one script, there is a third one to call those two (nice sentence, isn't it?)

Example 2.10. /home/cweiske/scripts/xmms_songtitle

#!/bin/sh
/home/cweiske/scripts/xmms_icecast.pl "$1"
/home/cweiske/scripts/mailsignature_song.sh "$1"

Chapter 3. Multimedia keys

Table of Contents

play
stop
forward
rewind

I've got a Logitech Internet Keyboard on my SuSE PC, and there are some multimedia keys like play, forward and so.

First I had to activate them by using my own Xmodmap

Example 3.1. /home/cweiske/.Xmodmap for the Logitech Internet Keyboard

keycode 160 = XF86AudioMute
keycode 174 = XF86AudioLowerVolume
keycode 176 = XF86AudioRaiseVolume
keycode 162 = XF86AudioPlay
keycode 164 = XF86AudioStop
keycode 144 = XF86AudioPrev
keycode 153 = XF86AudioNext
keycode 236 = XF86Mail
keycode 229 = XF86Search
keycode 230 = XF86Go
keycode 178 = XF86HomePage
keycode 223 = XF86Sleep

Now the keys were automatically loaded on my SuSE system, but not on my gentoo; I had to find a way that the modmap is started when X is started. I changed the file $KDEDIR/share/config/kdm/Xsession and inserted the following code after the shebang (#!/bin/sh):

Example 3.2. $KDEDIR/share/config/kdm/Xsession

...
if [ -f $HOME/.Xmodmap ]; then
    /usr/X11R6/bin/xmodmap $HOME/.Xmodmap
fi
...

Now the Xmodmap should be loaded everytime you log into your KDE.

As I use several programs to play videos, music and TV I made some scripts which control every program - but not at the same time, only the one which is active. All of the scripts are activated by the KHotkeys daemon from KDE.

play

Example 3.3. /home/cweiske/scripts/play

#!/bin/sh
#check if kaffeine is running
kaffeine=`dcop | grep kaffeine -c`
if [ $kaffeine = '1' ]; then
    #kaffeine is running, control it
    dcop kaffeine Kaffeine togglePlayPause
elif [ `pgrep tvtime` ]
then
    #tvtime
    tvtime-command TOGGLE_PAUSE
    tvtime-command TOGGLE_MUTE
else
    #no kaffeine, no tvtime
    #xmms play-pause
   xmms -t
fi

This code does the following: - if Kaffeine (KDE video player) is running, a play/pause signal is sent to it - if tvtime (TV application) is running (but not kaffeine), the picture is paused and the sound is muted in tvtime - if none of the above, XMMS shall play/pause.

stop

Example 3.4. /home/cweiske/scripts/stop

#!/bin/sh
kaffeine=`dcop | grep kaffeine -c`
if [ $kaffeine = '1' ]
then
    dcop kaffeine Kaffeine stop
elif [ `pgrep tvtime` ]
then
    tvtime-command TOGGLE_PAUSE
tvtime-command TOGGLE_MUTE
else
    xmms -s
fi

forward

Example 3.5. /home/cweiske/scripts/forward

#!/bin/sh
if [ `dcop | grep kaffeine -c` = '1' ]
then
    dcop kaffeine PlaybackControl posPlus
elif [ `pgrep tvtime` ]
then
    tvtime-command CHANNEL_UP
elif [ `dcop | grep kwintv -c` -gt 0 ]
then
    dcop kwintv KWinTVIface channelUp
else
    #xmms forward
    xmms -f
fi

rewind

Example 3.6. /home/cweiske/scripts/rewind

#!/bin/sh
if [ `dcop | grep kaffeine -c` -gt 0 ]
then
    dcop kaffeine PlaybackControl posMinus
elif [ `pgrep tvtime` ]
then
    tvtime-command CHANNEL_DOWN
elif [ `dcop | grep kwintv -c` -gt 0 ]
then
    dcop kwintv KWinTVIface channelDown
else
    xmms -r
fi

Chapter 4. Video editing

After my last vacation there were three hours of digital video waiting for cutting and editing. My laptop had no problems connecting the FireWire camcorder, and I used dvgrab to copy the videos to harddisk.

Getting the files off the video camera

Main problem was that the notebook disk is only 30 gigabytes, and there were only 4 of them free. The space was filled up after 15 minutes digital video were transferred... As the desktop pc had about 50 gig free, I tried to mount the free drive via nfs on the laptop and directly grab the files over network. Unfortunately the connection wasn't fast enough (100mbit network), but I had dropped frames every now and then. So I grabbed to the laptop disk and moved the files with another console to the nfs drive. No problems with dropped frames.

I wanted to use the desktop pc for copying the other two tapes to disk, so I bought a FireWire card and compiled the FireWire modules into the kernel. After a restart I could open Kino and control the camcorder - but I didn't see any video. dvgrab didn't give any results either, although gscanbus allowed me to control (play/pause/stop) the camera, too. Searching the net brought up another user with the same problem, but no solution. I subscribed to the FireWire mailing list at linux1394.org and told them my problem. I had an answer in my mailbox the next morning telling that some users got it working if they removed the FireWire ethernet driver eth1394. And after re-compiling the firewire kernel drivers as modules it worked as long as eth1394 was not loaded!

After copying one hour of video (16 gigabytes of disk space used!), I used Kino to arrange the files and cut the scenes down to usable ones. As I used dvgrab --autosplit --timestamp for grabbing the video from the digital camcorder, I had about 200 single files to import into Kino. As Kino doesn't support opening multiple files, dragging them from Konqueror helped to get them at once. Now there was no button to delete scenes, so I used Trim to set the beginning and the end mark to the same position. After doing that for about 100 of the 200 scenes, I noted that one could use the Cut command to get them out. But the program is somewhat slow cutting them (as it recreated the index or somewhat), I closed it and tried to do that by hand: The project files are in SMIL format, an XML dialect for audio and video sceneries. So it's human readable, and I opened it in my favorite editor and cut out all the lines which had the same beginning and ending position. That was done after one minute, compared to the four scenes you can cut with Kino in that time.

Removing useless files

The next problem was getting rid of all the files I didn't need any more because I cut them out: The shell was my friend in that case.

At first I needed a list with all files that were in use:

fgrep src kinoproject.smil | cut -b 17-63 > files_video

wrote all the filenames used in the project file into files_video. It could be that the "63" is different for you if the dvgrab filenames have another length.

The next was to get a list with all files not in the video:

ls -1 video/ | grep -v -f files_video > files_to_move

That one lists the files in video/ directory, one each line and compares them with the lines in the file created previously. The result is a list with all files not in the project.

Now all I had to do was moving the files to another directory:

for i in `cat files_to_move`; do mv video/$i /mnt/otherdrive/; done

You could delete the files here, too.