开发者

Get raw chunks of data from a microphone in C

I need to give chunks of audio data to a voice recog开发者_开发百科nition 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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜