44 #include <pulse/pulseaudio.h>
45 #include <pulse/simple.h>
58 ss.format = PA_SAMPLE_S16LE;
62 pa = pa_simple_new(NULL,
"ASR", PA_STREAM_RECORD, dev,
"Speech", &ss, NULL, NULL, &error);
64 fprintf(stderr,
"Error opening audio device %s for capture: %s\n", dev, pa_strerror(error));
69 fprintf(stderr,
"Failed to allocate memory for ad device\n");
74 handle->recording = 0;
75 handle->
sps = samples_per_sec;
76 handle->
bps =
sizeof(int16);
85 return ad_open_dev(DEFAULT_DEVICE, samples_per_sec);
120 ad_read(
ad_rec_t * r, int16 * buf, int32 max)
127 if (pa_simple_read(r->pa, (
void*)buf, max * 2, &error) < 0) {
128 fprintf(stderr,
"Failed to read speech: %s\n", pa_strerror(error));
139 return AD_ERR_NOT_OPEN;
142 if (ad_stop_rec(r) < 0)
145 pa_simple_free(r->pa);
Basic type definitions used in Sphinx.
SPHINXBASE_EXPORT ad_rec_t * ad_open(void)
Open the default audio device.
generic live audio interface for recording and playback
SPHINXBASE_EXPORT ad_rec_t * ad_open_dev(const char *dev, int32 samples_per_sec)
Open a specific audio device for recording.
SPHINXBASE_EXPORT ad_rec_t * ad_open_sps(int32 samples_per_sec)
Open the default audio device with a given sampling rate.