Arduino audio recorder and player

I was hoping to get some help with an audio recorder and play, I would want it to have 2 SD cards 1 for songs and one for recoding, I would want both to be played from the same aux cord/plug, I would like it to be able to pause/play skip and go back on songs and adjust audio, I really don’t minutes the inputs I.E. buttons or what boards. Sorry if this sounds a bit bossy I just need something really specific and I’m unable to do it my self I work more with sensors and servos rather then audio, if you have any questions or anything please ask

So, what help do you need?

well, I've got code for just an audio player (it uses a YX5300) but I want to also record audio to a separate SD card and play it from said SD card possibly using the same buttons. my original take was to record it to a new SD on an SD card reader/Writer but I got stuck with the whole playing it back part due to the fact I want to play it from the same aux plug so I don't have to switch just to listen from recordings to songs, I ended up just starting from scratch but attached is the code

#include <SoftwareSerial.h>
#include <DFPlayerMini_Fast.h>
#include <Encoder.h>

#define NEXT_BUTTON_PIN 2   // Button for next song
#define LAST_BUTTON_PIN 3   // Button for last song
#define SW_PIN 4            // Encoder switch button
#define CLK_PIN 5           // Encoder pin CLK
#define DT_PIN 6            // Encoder pin DT
#define BAUDRATE 9600

SoftwareSerial mySerial(10, 11); // RX, TX for DFPlayer Mini
DFPlayerMini_Fast mp3Player;

Encoder encoder(CLK_PIN, DT_PIN);
int16_t lastEncoderValue = 0;

void setup() {
  Serial.begin(BAUDRATE);
  mySerial.begin(BAUDRATE);
  mp3Player.begin(mySerial);

  pinMode(NEXT_BUTTON_PIN, INPUT_PULLUP);
  pinMode(LAST_BUTTON_PIN, INPUT_PULLUP);
  pinMode(SW_PIN, INPUT_PULLUP);
  
  attachInterrupt(digitalPinToInterrupt(NEXT_BUTTON_PIN), playNext, FALLING);
  attachInterrupt(digitalPinToInterrupt(LAST_BUTTON_PIN), playLast, FALLING);
}

void loop() {
  mp3Player.loop();

  int16_t encoderValue = encoder.read();
  if (encoderValue != lastEncoderValue) {
    int8_t volumeChange = (encoderValue - lastEncoderValue) / 4; // Adjust volume change speed
    lastEncoderValue = encoderValue;
    int8_t currentVolume = mp3Player.getVolume();
    int8_t newVolume = constrain(currentVolume + volumeChange, 0, 30); // Volume range: 0-30
    mp3Player.volume(newVolume);
  }

  if (digitalRead(SW_PIN) == LOW) {
    delay(50);  // Debounce delay
    if (digitalRead(SW_PIN) == LOW) {
      togglePause();
    }
  }
}

void playNext() {
  mp3Player.next();
}

void playLast() {
  mp3Player.previous();
}

void togglePause() {
  if (mp3Player.isPlaying()) {
    mp3Player.pause();
  } else {
    mp3Player.play();
  }
}

also, I just redid the code from this video https://www.youtube.com/watch?v=HSLKefx1VK4&t=486s

basically, I need help getting it to record and play audio from a separate SD card

Ok, you have a working player. What are you using as a recorder? What Arduino are you using? Is that recorder also a player?

With the XY5300 you don't have access to the digital audio so you'll have to mix in analog. (Analog mixers are bult around summing amplifiers.)

With line-level signals you can use a passive mixer, which is just 2-resistors (4 for stereo). Here are some schematics..

Digital mixing is done with sample-by-sample summation, or since you are usually adjusting the levels (which might be required to prevent clipping) it usually ends-up to be a weighted average.

I'm using an Arduino Uno board, I haven't picked out a microphone module for the Arduino but if you would like I could find one right now, the code I showed is just a player for the YX5300 which is a built-in aux and SD card reader. the code has nothing to do with recording or a separate SD card but I would want a separate SD card reader so I can have 2 separate file "holders" but I would also be fine with using the same SD card as long as I can pick between songs and recordings and it doesn't accidentally play a recording while I'm listening to music, I want to use the same aux port and want to avoid a speaker due to the fact I'm sticking the whole thing in a helmet which is going to have a built-in UI but I already got the UI part done.

sorry if this is a lot

I'm sorry I have no idea about anything related to audio and I hate to ask but I have very little idea about what that means or what happens as a result so may you please elaborate? I do know the difference between digital and analog with digital being numbers and analog being waves in the air but that's all.

You need more than just a microphone module and and a UNO has very limited audio capability and there will be ZERO recording while anything is being written to an SD card.

would you recommend something else? I'm fine using a different board or parts as long as it does the same job, I just chose an Arduino because I have a few laying around and I'm familiar with them. also, I thought it would be a fun project to do, and having it make it myself would allow me to choose where every button is placed on the helmet/backpack (I'm going to have a backpack for batteries, sensors and an Arduino nano v3 but just decided today to add a recording feature and music feature and its spiraled in to a goose chase)

Some of the Teensy series of Arduino compatible boards have enough memory and are fast enough to handle audio, and audio processing libraries are available. Check them out at PJRC.

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