From cd8ea7c5edc4618dead660acca9c13809c16284f Mon Sep 17 00:00:00 2001 From: talksik Date: Sat, 26 Jul 2025 18:32:48 -0700 Subject: [PATCH] write pcm data to file --- ai-conversation/audio_capture.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/ai-conversation/audio_capture.c b/ai-conversation/audio_capture.c index 661fe0b..17cb8ac 100644 --- a/ai-conversation/audio_capture.c +++ b/ai-conversation/audio_capture.c @@ -130,18 +130,29 @@ int main() { * Each period is 2048 BYTES because each frame is 2 bytes. * Each frame is 2 bytes because of 1 channel, and 16 bit format */ + FILE *file = fopen("output.pcm", "wb"); + if (file == NULL) { + perror("Error opening file"); + return 1; + } while (snd_pcm_readi(pcm_handle, (void *)buf, period_size) > 0 && periods_read < periods_to_read) { printf("======READING FRAMES========\n"); // Because each frame is 2 bytes (format/bit rate), cast to int16 - int16_t *samples = (int16_t *)buf; - for (int i = 0; i < period_size; i++) { - printf("%d ", samples[i]); - } + // int16_t *samples = (int16_t *)buf; + // for (int i = 0; i < period_size; i++) { + // printf("%d ", samples[i]); + // } + + fwrite(buf, sizeof(int16_t), period_size, file); + printf("\n"); periods_read++; } + // TODO: keep appending above frames into one buffer, and send to deepgram + + fclose(file); free((void *)buf); snd_pcm_close(pcm_handle); snd_pcm_hw_params_free(params);