I have a trouble in my app.
I want to record a sound and store it in iOS using Cordova. I have already a base64/wav file, but it's very heavy so I want to convert it into a base64/mp3.
Which is the algorithm that allows me to do that?
Example:
b64Wavtob64mp3("base64/...");
// Return a mp3 base64
Thanks in advance!
I forgot completely base64
because I was looking for a audio compressed
Solved!
I did it with a wav2m4a
plugin.
https://github.com/xu-li/phonegap-wav2m4a
But I wanted to go further so I modified CDVSound.m
at iOS.
I just followed these instructions:
https://gist.github.com/jlsuarezs/d48094d431307a466496
Add to the startRecordingAudio
method on CDVSound.m
this:
NSDictionary *recordSettings = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithInt: kAudioFormatMPEG4AAC], AVFormatIDKey,
[NSNumber numberWithFloat:16000.0], AVSampleRateKey,
[NSNumber numberWithInt: 1], AVNumberOfChannelsKey,
nil];
Replace:
audioFile.recorder = [[CDVAudioRecorder alloc] initWithURL:audioFile.resourceURL settings:nil error:&error]; // Default PCM recording
With:
audioFile.recorder = [[CDVAudioRecorder alloc] initWithURL:audioFile.resourceURL settings:recordSettings error:&error];
- Changing another lines:
CDVSound.m checks to make sure you're using a wav file. Simply changing this at the top of the file should prevent that.
define RECORDING_WAV @"wav"
I changed it to:
#define RECORDING_WAV @"m4a"
or
#define RECORDING_M4A @"m4a"
and change in the file instances that contains the RECORDING_WAV
variable.