soundrecorder

soundrecorder

Sound Recorder

Recording Sound( Linux FC2, Qt, sox )

If you want to record sound you can do so on linux systems using rec command which is very common.If you want to record something you speak to a file test.wav use the following at cmd prompt:

rec test.wav

Now it is quite obvious that you might want to read the input from microphone into your application, so here is what you do:

  1. start a new process( using fork( ) or something )

  2. exectute the "sox -t ossdsp /dev/dsp test.wav" in that process( using execvp )

  3. say something in the microphone

  4. send SIGINT to that process using kill( ) syscall

  5. the output is saved in test.wav

How to do the above?

here is how you start the process and record(In Linux using Qt).

#include <sys/types.h>

#include <signal.h>

extern int kill( pid_t pid, int sig );

QProcess *rec = NULL;

//This will start recording whatever you say to test.wav

void startRecord( void )

{

QString str = "sox -t ossdsp /dev/dsp test.wav";

QStringList args = QStringList::split(" ", str);

rec = new QProcess(args);

}

void stopRecord( void )

{

//This will stop recording

int pId = rec->processIdentifier( );

::kill( pId, SIGINT ); //System call

}

Note: The above is only the part of code not full Its' just to give you and idea of how to do it using Qt in Linux.