Custom Search

Tuesday, November 17, 2009

Interfacing the Medical Transcription
Foot Pedal With Mplayer

Those of you who are hearing mplayer for the first
time should certainly see this article.

It is the best multimedia application out there and
it is written in pure C. It is amazing stuff. A grand
old project with an amazing cornucopia of features.

Those of you who have not heard of the footpedal
do not need to worry. It is a footrest with three
buttons which you can press with the toe.
Here is a picture.

It connects via the 9 pin serial connector to the
serial port of the computer. Before we get to the
technical details we do need to know something
about the medical transcription industry.

Every technical problem needs a business goal to
meet. Sometimes it is not very obvious as in the
case of academic UNIX tools, but without having
an appreciation of the real purpose of the project,
one cannot do well in business. Technical solutions
do not exist in isolation.

Medical transcription is the process of converting
a doctor's voice recordings into English text. The
doctor would have spoken at varying speeds and
with different accents. A medical transcriptionist
has the job of translating his spoken words into
the written word.

I am sure you can imagine that this is no easy task.
The transcriptionist has to listen to the dictation
multiple times at various speeds to figure out what
on earth the doctor is trying to say.

His/her fingers are typing the message in the audio,
and you wish to be able to rewind, pause/play and
fast forward the recording with the foot. That is
where a footpedal comes in. You can't use the mouse
or keyboard for this since the hands are busy typing
out text.

While the hand is typing the foot will be interacting
with the audio player to help the transcriptionist to
accurately translate the dictation into English text.

The footpedal is a passive device with no power and
no moving parts. There are 3 switches as you can see
above. The left pedal is connected to the DSR pin(8),
the middle pedal is connected to the CTS pin(6), and
the right pedal is connected to the DCD pin(1).

I figured this out using a perl script given here.


use Device::Modem;

  my $modem = new Device::Modem( port => '/dev/tty00' );

        /*
         if( $modem->connect( baudrate => 9600 ) ) {
             print "connected!\n";
         } else {
             print "sorry, no connection with serial port!\n";
         }
        */

        my %sig = $modem->status();
        for ('CTS','DSR','RLSD')
        {
                if($_ =~ /RLSD/) {
                        print "Signal DCD is: ", ($sig{$_} > 0 ? 'on'
: 'off'), "\n";
                } else {
                        print "Signal $_  is: ", ($sig{$_} > 0 ? 'on'
: 'off'), "\n";
                }
        }

The next thing to do was figure out a way to do this
in C. That was the hard part but I got there. Check
out the code in this page to interface with the serial
port on Windows and OpenBSD to recognize the pedal
presses.

Okay now we are halfway through. We can recognize
the pedal presses. But how to interface with the
audio player?

Before that we have an even more important question
to tackle.

Which player should we use?

I started working on audacity but quickly realized that
it does not have the rewind and forward feature. Plus
I realized that most audio players don't have this at all.
Except of course mplayer. But before that I considered
and rejected sox and vlc.

I looked at the mplayer input.c file, the way it interfaced
with the joystick and LIRC remote control. I know I could
copy the semantics and match it with key presses. I did the
project first on OpenBSD and then got it working under
Windows. It was a great project, I thoroughly enjoyed it.

All the code in beautiful syntax highlighted fashion with
black background is here

However the work is not over yet. You need to recognize
the pedal presses with more care. Right now it is too
sensitive so to speak. It has to have some back pressure
and hysteresis. I need to understand the needs of the
medical transcriptionist better. I shall finish this
project and add these details later. At the moment, I
can say that the project is nearly over.