星期二, 6月 13, 2006

[Linux]Generate 5000 mp3 by script

5000 mp3 songs?!
Where can I get them? Hey, why do I use script to generate them?
The first version, I use a simple mp3 to be template. But I was afraid of there are patent issue, so I use Text to Speech tools to convert text to speech.

My environment: Fecora Core 5
Dependency: Festival (text2wave)、lame (convert wave to mp3)、id3tag (tag the converted mp3)。

The following is the script:
#!/bin/sh
#
# run2.sh
# This script is used to generate short songs.
# You can decide how many songs should be generated by modify LIMITSONGS variable.
#
# Dependency:
# festival (Text to speech by text2wave)
# lame (convert wave to mp3)
# id3tag (tag the generated mp3)
#
# Tested environment:
# Fedora Core 5
#
ITER=1
LIMITSONGS=5002
((TOTAL=LIMITEDSONGS - 1))

while (($ITER < $LIMITSONGS))
do
NEWFILENAME=`printf "./%04d.mp3" $ITER`
WAVEFILE=`printf "%d.wav" $ITER`
((ALBUMNUM=ITER / 20))
((ARTISTNUM=ITER / 20))
ALBUM=`printf "Album%04d" $ALBUMNUM`
ARTIST=`printf "Artist%04d" $ARTISTNUM`
TITLE=`printf "Song%04d" $ITER`
TEXT=`printf "Hello world! This is song %d which is generated by text2wave. Here are %d songs, enjoy them. See you later, baby." $ITER $TOTAL`

echo Processing $NEWFILENAME
echo $TEXT > text.txt
text2wave -F 19200 -o $WAVEFILE text.txt
lame $WAVEFILE $NEWFILENAME
id3tag --artist=$ARTIST --album=$ALBUM --song=$TITLE --genre=classic --track=$ITER --desc="generated by script." --total=$TOTAL $NEWFILENAME
((ITER = ITER + 1 ))

rm -f $WAVEFILE
done

rm -f text.txt
echo "done."


LIMITESONGS is used to control the song numbers.
TEXT is the text. Currently festival don't support chinese, so you have to use english.

After I wrote this script, I learn that I can calculate variables in script.
Before this, I believed that bash operate only string variables...
Yap, I learn it...

沒有留言:

您或許對這些文章有興趣

Related Posts Plugin for WordPress, Blogger...