Creating and Saving Audio Files (Questions)

I’m in the process of working on my very first programming project, a simple voice notes app that should be able to:

  1. Create notes
  2. Edit existing notes
  3. Delete notes
  4. Show a list of notes currently saved on the device (list table view?)
  5. Persist notes on the device between sessions (Documents folder persists across sessions)

I’m having a bit of trouble understanding how to create and save a new audio file.

I’ve gone over the “simple audio recorder” example and understand that r = media.newRecording(filePath) creates a new audio file in the Documents directory using the value stored in dataFileName. The r:startRecording() then uses that file to record into.

However, this example only creates one file that gets recorded into over and over. I’m interested in creating a new audio file each time a recording is started.

I’ve been messing around with various code for a few days now and my newbie brain just can’t seem to get anything working properly.

I think my three main concerns are:

  • how do I create a unique newRecording object for every recording?
  • how do I save it to the Documents folder without overwriting the previous file?
  • how does the startRecording method know which file to record into if multiple files exist?

Can someone help me with a jumping off point? I would be immensely grateful.

Thanks,

  • Mike
    [import]uid: 14700 topic_id: 28681 reply_id: 328681[/import]

You need to set up a variable that will hold an ID number for the recording to be made.

[lua]local nextRecording = 1
local dataFileName[/lua]

You would then use this to alter the dataFileName variable before you start a new recording, remembering to increment the ‘recording’ variable once the recording has finished.
[lua]dataFileName = “recording”…nextRecording
– recording code here
nextRecording = nextRecording + 1[/lua]

So your recordings will be called ‘recording1.aif’, ‘recording2.aif’ etc etc

When you want to replace an existing recording, just use a different variable to change the dataFileName variable. Say you are working on note 7, and hold this number in a variable called thisNote:

[lua]dataFileName = “recording”…thisNote[/lua]

You’ll need to look into storing your nextRecording variable permanently on the device so when the app is loaded it knows how many recordings have been made and what number to give the next one. I use the ‘Ice’ library for this, it’s pretty simple to use. [import]uid: 93133 topic_id: 28681 reply_id: 115659[/import]

This saving library is much better than ICE in my opinion, and much simpler to use.
Satheesh’s Saving and Loading Library

binc [import]uid: 147322 topic_id: 28681 reply_id: 115665[/import]

@ Nick & Binc,

Thank you so much for your help! I can’t believe I didn’t think to do that. Oh well, I’m learning, so I can’t beat myself up.

I added the suggested variable and managed to get it recording properly. I haven’t tackled trying to save the variable across sessions yet, but after looking at the library Binc suggested, it looks pretty straightforward.

I really do appreciate you taking time to help me out. Thanks.

  • Mike [import]uid: 14700 topic_id: 28681 reply_id: 115741[/import]