[nas] How to play sounds through NAS using libaudio.so?

Hynek Hanke hanke at volny.cz
Sat Oct 23 12:39:19 MDT 2004


Hi,

I'm working on accessibility and I'd like to use NAS as the
audio output server for Speech Dispatcher (http://www.freebsoft.org),
an application providing uniform high-level interface to speech
synthesis.

I played with it today, but was unable to make any sound through
the AuSoundPlayFromData method. It compiles, but keeps silent.
I was trying to find the answer in the documentation and in
the example programs, but failed. Please, can you help me?

I made myself a simple test program. It doesn't print out any
error message, but AuSoundPlayFromData doesn't produce any sound
output. On the other side, AuSoundPlaySynchronousFromFile does.
What am I doing wrong?

---

#include <stdio.h>
#include <audio/audiolib.h>
#include <audio/soundlib.h>
#include <flite/flite.h>

cst_voice *register_cmu_us_kal();

int
main()
{
    cst_wave *wav;
    cst_voice *flite_voice;

    Sound s;
    AuServer *aud = 0;

    int ret;

    /* I just fabricate some sound (this code is tested and works) */
    flite_init();
    flite_voice = register_cmu_us_kal();
    if (flite_voice == NULL)
	{
	    printf("Couldn't register the basic kal voice.\n");
	    exit(1);
	}
    wav = flite_text_to_wave("Hello world.", flite_voice);
    if (wav == NULL){
	printf ("Bad wavefile!\n");
	exit(1);
    }

    /* Then I open the server, seems no problem here */
    aud = AuOpenServer(NULL, 0, NULL, 0, NULL, NULL);
    if (!aud)
        {
	    fprintf(stderr, "Can't connect to audio server\n");
	    exit(-1);
        }

    /* I create the helper sound structure ... */
    s = SoundCreate(SoundFileFormatNone,
		    AuFormatLinearSigned16LSB,
		    1, wav->sample_rate, wav->num_samples, NULL);
    
    /* ... and play the sound */
    ret = AuSoundPlayFromData(aud, s,
			    wav->samples,
			    AuNone,
			    100,
			    NULL , NULL, NULL,
			    NULL, NULL, NULL);

    /* Here I recieve a non-null reply in ret ...*/
    if (ret == NULL){
	printf ("Ops, something went wrong.\n");
	exit(1);
    }

    /* ...but no sound is produced. However, if I uncomment this line,
       It plays test.wav without any problems and I hear it in my
       speakers. */
    //    AuSoundPlaySynchronousFromFile(aud, "test.wav", 100);

    /* Just to be sure that closing the connection is not the cause
    of the error. */
    sleep(2);

    if (aud)
	AuCloseServer(aud);

    return 0;
}

---

Thanks a lot & thanks for NAS!

Hynek Hanke
Czech Republic



More information about the Nas mailing list