Garbled recording audio using TMRpcm

I’m creating an audio recorder using the TMRpcm library which records to an SD card.

In the initial prototyping stages of my project, I was getting reasonably clear recordings. I could understand my voice in the recordings. However, now that I have a soldered-together unit, its producing semi-garbled recordings. What I mean by that is that the words sound like they are all run together, like the each word is cut off. It’s barely intelligible, even with low noise in the background.

This is my first post, so I’m not allowed to upload attachments, but I have a sample file if anyone can tell me how to post it (or how soon I stop being “new”).

Here is my code. Note that in “loop()” I commented out some of the stuff I added after prototyping to do things like use a grounded DIO input to end the recording of one file and start the next. The currently active code is just like my working prototypes had - just start a recording, use a delay, then stop recording. But even with this super simple setup it produced garbled recordings.

Can anyone help? Thank you.

#include <SD.h>
#include <SPI.h>
#include <TMRpcm.h>
#define SD_ChipSelectPin 10

int mic = A5;
TMRpcm audio;
char fname[12];  //Audio filename
char dir_name[3];  //New directory used at each boot
char buf[40];  //print character buffer
bool recording_now = false;
unsigned long start_time = 0;

void serial_cmd();
void start_rec();
void stop_rec();

void SD_Setup() {

  int dir_num = 1;
  while (not SD.begin(SD_ChipSelectPin)) {
    Serial.println("SD Initializing...");
  Serial.println("SD Initialized");

  sprintf(dir_name, "%i", dir_num);
  while (SD.exists(dir_name)) {
    sprintf(buf, "Dir %i exists", dir_num);
    sprintf(dir_name, "%i", dir_num);
  sprintf(buf, "Using dir %s", dir_name);

void mic_Setup() {
  /* PWR on pin D2, GND on GND, OUT to 'mic' */
  Serial.println("Mic init");
  pinMode(2, OUTPUT);
  digitalWrite(2, HIGH);
  pinMode(mic, INPUT);
  audio.CSPin = SD_ChipSelectPin;
  Serial.println("Mic init done");

void setup() {
  pinMode(9, INPUT_PULLUP);

void start_rec() {
  Serial.println("Start rec");
  if (not recording_now) {
    start_time = (int) round(0.5 + millis()/1000);
    //TMRpcm won't finalize wav files not in root directory, so use dir num
    //as prefix instead of directory.
    sprintf(fname, "%s_%05lu.wav", dir_name, start_time);
    sprintf(buf, "Start recording to file %s", fname);
    audio.startRecording(fname, 16000, mic);
    recording_now = true;
  } else {
    Serial.println("Already recording");

void stop_rec() {
  Serial.println("Stop rec");
  if (recording_now) {
    recording_now = false;
    sprintf(buf, "Stop recording to file %s", fname);
  } else {
    Serial.println("Not recording");

void loop() {
  unsigned long interval = 1000*30;  // 30 second recording interval
  // if (digitalRead(9)) {
  //   start_rec();
  //   while (recording_now) {
  //     if ((millis() - start_time > interval) || (not digitalRead(9))) {
  //       stop_rec();
  //     }
  //   }
  //   Serial.println("not recording now");
  // }

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.