About sound recording

I’m now developing a program using recording feature. It’s record well but they’re problem.

When I start record a new recordfile, it’s run well. Such as “record1.aif”

Then I do _ audio.loadSound _ “record1.aif” to playback the sound, it’s ok.

But when I try to start record to “record1.aif” again. The simulator don’t tell anything, able to finish the recording. But I found that the “record1.aif” won’t change and the sound properties remain like the first time I recorded.

The 1st question:

Is the sound record can’t be update into the newer one using same file name declaration?

I’ve try the “Simple Audio Recorder” in sample project, it can’t record a new sound until I open the Sandbox and delete the file remains there.

I can’t figure out so I’m try to create a new record file “record2.aif” and load it instead. It’s ok but the older file must remain as junk because I don’t need it anymore.

So I try using os.remove to remove the old recording file (record1.aif) instead and rename the new recording file into old file name I was delete (_ os.rename _ from record2.aif into record1.aif).

Monitoring in the Sandbox, it’s normally occurance.

But the result is that when I play the “record1.aif”, the program play “The old sound I was delete”, since the file doesn’t exist anymore, as well as the “record1.aif” in the Sandbox is now a new sound.

By the way, when I relaunch the program and load “record1.aif” it’s now the new sound.

If the 1st question answer is “unable”, I would like to ask if they’re anyway to do soft restart program using a code?
 

I try using _ director:changescene _ to switch of the scene and make the code execute again but it’s no use except I relauch the project, the new record file then loaded.

Thanks in advance. :wacko:

“But I found that the “record1.aif” won’t change and the sound properties remain like the first time I recorded.”

The reason why this is, is because you didn’t dispose the audio handle. What’s happening is record.aif IS getting recorded over, but you still have the original in memory. You need to dispose of the old audio before opening the new audio. Do something like the following:

 local filePath = system.pathForFile( 'record1.aif', system.DocumentsDirectory ) local r = media.newRecording( filePath ) local audioHandle = nil local audioChannel = nil local function recordAudio( ) if (audioHandle ~= nil) then --stop audio before disposing it if (audio.isChannelActive(audioChannel)) then audio.stop(audioChannel) end audio.dispose(audioHandle) end                 r:startRecording() end local function stopAndPlaybackRecording( ) r:stopRecording() audioHandle = audio.loadSound( "record1.aif", system.DocumentsDirectory ) audioChannel = audio.play(audioHandle) end

Alright, it’s work now. Thanks. :slight_smile:

“But I found that the “record1.aif” won’t change and the sound properties remain like the first time I recorded.”

The reason why this is, is because you didn’t dispose the audio handle. What’s happening is record.aif IS getting recorded over, but you still have the original in memory. You need to dispose of the old audio before opening the new audio. Do something like the following:

 local filePath = system.pathForFile( 'record1.aif', system.DocumentsDirectory ) local r = media.newRecording( filePath ) local audioHandle = nil local audioChannel = nil local function recordAudio( ) if (audioHandle ~= nil) then --stop audio before disposing it if (audio.isChannelActive(audioChannel)) then audio.stop(audioChannel) end audio.dispose(audioHandle) end                 r:startRecording() end local function stopAndPlaybackRecording( ) r:stopRecording() audioHandle = audio.loadSound( "record1.aif", system.DocumentsDirectory ) audioChannel = audio.play(audioHandle) end

Alright, it’s work now. Thanks. :slight_smile: