write pcm data to file
This commit is contained in:
@@ -130,18 +130,29 @@ int main() {
|
|||||||
* Each period is 2048 BYTES because each frame is 2 bytes.
|
* Each period is 2048 BYTES because each frame is 2 bytes.
|
||||||
* Each frame is 2 bytes because of 1 channel, and 16 bit format
|
* 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) {
|
while (snd_pcm_readi(pcm_handle, (void *)buf, period_size) > 0 && periods_read < periods_to_read) {
|
||||||
printf("======READING FRAMES========\n");
|
printf("======READING FRAMES========\n");
|
||||||
|
|
||||||
// Because each frame is 2 bytes (format/bit rate), cast to int16
|
// Because each frame is 2 bytes (format/bit rate), cast to int16
|
||||||
int16_t *samples = (int16_t *)buf;
|
// int16_t *samples = (int16_t *)buf;
|
||||||
for (int i = 0; i < period_size; i++) {
|
// for (int i = 0; i < period_size; i++) {
|
||||||
printf("%d ", samples[i]);
|
// printf("%d ", samples[i]);
|
||||||
}
|
// }
|
||||||
|
|
||||||
|
fwrite(buf, sizeof(int16_t), period_size, file);
|
||||||
|
|
||||||
printf("\n");
|
printf("\n");
|
||||||
periods_read++;
|
periods_read++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: keep appending above frames into one buffer, and send to deepgram
|
||||||
|
|
||||||
|
fclose(file);
|
||||||
free((void *)buf);
|
free((void *)buf);
|
||||||
snd_pcm_close(pcm_handle);
|
snd_pcm_close(pcm_handle);
|
||||||
snd_pcm_hw_params_free(params);
|
snd_pcm_hw_params_free(params);
|
||||||
|
|||||||
Reference in New Issue
Block a user