Reputation: 2795
I need to give chunks of audio data to a voice recognition engine. For now my program reads and buffers chunks of data from a 8k-rate ulaw-encoded raw file, using this code :
unsigned char buf[MAX_AUDIO_BUF_LEN];
FILE *fp;
int len;
AudioSamples epSamplesStruct;
/* Read in Audio File */
fopen_s(&fp, FILE_NAME, "rb");
if (fp == NULL) {
printf("AUDIO THREAD=> ERROR. Cannot open prompt file %s\n", FILE_NAME);
return 1;
}
/* loop while there are still buffers to be picked up from file */
while((len = fread(buf, 1, MAX_AUDIO_BUF_LEN, fp)) > 0) {
epSamplesStruct.samples = (void *) buf;
epSamplesStruct.len = len;
epSamplesStruct.type = L"audio/basic";
num_samples_read += len;
// Processing the audio...
}
epSampleStruct
is the structure passed to the recognition engine.
I would like to transform this code so as read from a microphone instead of a file. I can not adapt so much the type of audio data : it should remain ulaw-encoded and with a 8k rate.
How would you do this? Thanks for any constructive help.
Upvotes: 0
Views: 1732
Reputation: 606
You might want to have a look at the Waveform Audio Interface : here and here.
The second link is for .NET developpers, but starts with a lot of information about useful c functions such as waveInOpen()
, so you can start here.
Edit : another MSDN link : Recording Waveform Audio
Upvotes: 3