Page 1 of 1

Five Linux and Sound

Posted: Thu Jul 02, 2009 1:34 am
by xProgrammer
This board is looking a little quiet with no new posts in more than 6 months.

I have a need to record voice for subsequent transcription and there wasn't a Linux package available that I could see that fitted my needs (gnome-voice-recorder didn't have pause functionality, Audacity made the process too complex although it is a wonderful package etc). Plus I would have had to shell out to those packages and then try to update the records that my software is keeping.

Then I came across ecasound which is a command line audio package with an interactive mode and a C library for accessing that interactive mode. I have quickly thrown together an (x)Harbour class and interface and shown that I can record audio direct from (x)Harbour. Playing audio files should be straight forward as well although I have yet to test that capability as I don't need it at the moment.

If anyone is interested in this let me know. ecasound only has partial support under windows through cygwin so it may well not be worth pursuing for FiveWin people.

For Ubuntu you need the following packages: ecasound libecasoundc2.2-dev

The C code for the interface is simple enough:

Code: Select all

/*
xecasound.c
*/

#include <hbapi.h>
#include </usr/include/libecasoundc/ecasoundc.h>

HB_FUNC( ECAS_INIT )
{
eci_init();
}

HB_FUNC( ECAS_CLEANUP )
{
eci_cleanup();
}

HB_FUNC( ECAS_COMMAND )
{ 
eci_command( hb_parc( 1 ) );
}

HB_FUNC( ECAS_LAST_INTEGER )
{
int last_return;
last_return = eci_last_integer();
hb_retni( last_return );
}

HB_FUNC( ECAS_LAST_STRING )
{
hb_retc( eci_last_string() );
}

HB_FUNC( ECAS_LAST_FLOAT )
{ 
double last_double;
last_double = (double) eci_last_float();
hb_retnd( last_double );
}
 
And the (x)Harbour class is pretty simple too

Code: Select all

/*
sound.prg
*/

#include <hbclass.ch>

CLASS TSound

METHOD New() 
METHOD Initialise()
METHOD Cleanup()
METHOD ExecuteCommand( str_command )
METHOD GetLastInteger()
METHOD GetLastString()
METHOD GetLastFloat()
METHOD GetError()
METHOD AddAudioInput( str_input )
METHOD AddAudioOutput( str_output )
METHOD LaunchEngine()
METHOD Start()
METHOD Stop()
METHOD Quit()
METHOD AddChainSet( str_chainsetname )
METHOD AddChain( str_chainname )
METHOD ConnectChainSet()
METHOD GetEngineStatus()
METHOD GetConnectedChainSet()
METHOD SetLogHistoryLength()
METHOD GetLog()
METHOD AudioInputList()
METHOD AudioOutputList()
METHOD AudioInputLength()
METHOD AudioInputPosition()
METHOD AudioOutputPosition()

ENDCLASS

METHOD New() CLASS TSound

RETURN self

METHOD Initialise() CLASS TSound

ECAS_Init()

RETURN nil

METHOD Cleanup() CLASS TSound

ECAS_Cleanup()

RETURN nil

METHOD ExecuteCommand( str_command ) CLASS TSound

ECAS_Command( str_command )

RETURN nil

METHOD GetLastInteger() CLASS TSound

RETURN ECAS_Last_Integer()

METHOD GetLastString() CLASS TSound

RETURN ECAS_Last_String()

METHOD GetLastFloat() CLASS TSound

RETURN ECAS_Last_Float()

METHOD GetError() CLASS TSound

::ExecuteCommand( "eci-error" )

RETURN ::GetLastInteger()

METHOD AddAudioInput( str_input ) CLASS TSound

::ExecuteCommand( "ai-add " + str_input )

RETURN nil

METHOD LaunchEngine() CLASS TSound

::ExecuteCommand( "engine-launch" )

RETURN nil

METHOD AddAudioOutput( str_output ) CLASS TSound

::ExecuteCommand("ao-add " + str_output )

RETURN nil

METHOD Start() CLASS TSound

::ExecuteCommand( "start" )

RETURN nil

METHOD Stop() CLASS TSound

::ExecuteCommand( "stop" )

RETURN nil

METHOD Quit() CLASS TSound

::ExecuteCommand( "quit" )

RETURN nil

METHOD AddChainSet( str_chainsetname ) CLASS TSound

::ExecuteCommand( "cs-add " + str_chainsetname )  

RETURN nil

METHOD ConnectChainSet() CLASS TSound

::ExecuteCommand( "cs-connect" )

RETURN nil

METHOD AddChain( str_chainname ) CLASS TSound

::ExecuteCommand( "c-add " + str_chainname )

RETURN nil

METHOD GetEngineStatus() CLASS TSound

::ExecuteCommand( "engine-status" )

RETURN ::GetLastString()

METHOD GetConnectedChainSet() CLASS TSound

::ExecuteCommand( "cs-connected" )

RETURN ECAS_Last_String()

METHOD SetLogHistoryLength( int_length ) CLASS TSound

::ExecuteCommand( "int-set-log-history-length " + AllTrim( Str( int_length ) ) )

METHOD GetLog() CLASS TSound

::ExecuteCommand( "int-log-history" )

RETURN ECAS_Last_String()

METHOD AudioInputList() CLASS TSound

::ExecuteCommand( "ai-list" )

RETURN ECAS_Last_string()

METHOD AudioOutputList() CLASS TSound

::ExecuteCommand( "ao-list" )

RETURN ECAS_Last_string()

METHOD AudioInputLength() CLASS TSound

::ExecuteCommand( "ai-get-length" )

RETURN ::GetLastFloat()

METHOD AudioInputPosition() CLASS TSound

::ExecuteCommand( "ai-getpos" )

RETURN ::GetLastFloat()

METHOD AudioOutputPosition() CLASS TSound

::ExecuteCommand( "ao-getpos" )

RETURN ::GetLastFloat()
 
This code works but is not a complete or finished product. The TSound Class currently only taps in to may be 10% of the functionality provided by ecasound. However extension of the class should be easy and straight forward.

Re: Five Linux and Sound

Posted: Sat Jul 04, 2009 1:47 pm
by Antonio Linares
Doug,

Many thanks for sharing it! :-)