2006-09-02

About a script, chinesetape2ogg

Last year, during an attempt of ogg enconding of my father old Blues Vinyls I wrote a script in order to encode on the fly sound from the line in of my sound card.

It worked well until today when I tried again with some chinese lessons on a tape bought in Shanghai . Maybe because I am not a surfer, I gave my old aiwa walkman to a friend. Consequently, I have no other means than converting these lesson to ogg in order to enjoy mobile chinese lessons on my Iops !

Here was the old script :

    #!/bin/sh
    mkfifo lak7.wav

    oggenc -b 190 lak7.wav -o lak7.ogg &
    sox -t ossdsp -w -s -c 2 /dev/dsp -r 44100 -c 2 -f lak7.wav


The idea is to create a fifo file, then encode on the fly this file which is feeded by sox listening to the output of the mixer. You launch the script and do a CTRL + C to stop it.
It worked until now, but today, with short recordings, the results were awfull when I tried to listen to the resulting ogg file. Just like if it was played in low motion !

I found the solution and my mistake here.

In fact, there problem comes from the fact that I end the recording by sending SIGINT (CTRL+C). But, this is received by oggenc and then its parent (sox) is receiving a SIGPIPE and terminates. As a result, the end of stream marker of the off file is missing which seems to be a problem on my short chinese lessons. In order to solve this, the web site above propose to trap SIGINT in order to send it to sox.

Here is the proposed script (rec is the sox frontend)
    trap cleanup INT
    (
    trap "" INT

    exec rec -t raw -c 2 -w -r 44100 - | oggenc -r -B 16 -C 2 -R 44100 -q 5 -o "$file_name" - ;

    )

0 Comments:

Post a Comment

<< Home