#include #include #include #include "proto.h" #include "getargs.h" #include "hplay.h" char *prog = "hplay"; long samp_rate = 32000; char *host_name = NULL; char *name = "RSynth_Speech"; int sock; int audio_init(int argc, char **argv) { int bits = ESD_BITS8 ; int channels = ESD_MONO ; int mode = ESD_STREAM ; int func = ESD_PLAY ; esd_format_t format = 0; char *host = "localhost"; int rate_set = 0; int use_audio = 1; argc = getargs("Esound Audio",argc, argv, "r", "%d", &rate_set, "Sample rate (Hz)", "a", NULL, &use_audio, "Audio enable", "s", "", &host_name, "ESD Host", "n", "", &name, "ESD stream name", NULL); if (rate_set) samp_rate = rate_set; if ( host_name ) host = host_name; format = bits | channels | mode | func; /* sock = esd_play_stream( format, rate ); */ sock = esd_play_stream_fallback( format, samp_rate, host_name, name ); printf( "Speaking to esound://%s:%d/%s?format=0x%08x&rate=%d\n", host, sock, name, format, samp_rate ); return argc; } void audio_play(int n, short *data) { char buf[ESD_BUF_SIZE]; int length = 0, arg = 0, i; unsigned char *converted = (unsigned char *) malloc( n ); if ( n > 0 ) { if ( converted == NULL ) { fprintf( stderr, "Could not allocate memory for conversion\n" ); exit( 3 ); } for ( i = 0; i < n; i++ ) converted[i] = ( data[i] - 32768 ) / 256; if ( sock <= 0 ) exit; if (sock >= 0) if ( write( sock, converted, n ) != n ) { perror( "write" ); free( converted ); } } } void audio_term(void) { close( sock ); }