如何为Base64 WAV转换为JavaScript中的base64 MP3 [英] How to convert base64 wav to base64 mp3 in JavaScript
问题描述
我有麻烦我的应用程序。
我要录制声音并将其存储在使用iOS的科尔多瓦。我已经有一个base64 / wav文件,但它是非常沉重的,所以我想将其转换成一个base64 / MP3。
这是一个可以让我做到这一点的算法?
例如:
b64Wavtob64mp3(BASE64 / ...);
//返回一个MP3的base64
在此先感谢!
我忘了完全的base64
,因为我一直在寻找一个音频COM pressed 的
解决了!
我用 wav2m4a
插件做到了。
https://github.com/xu-li/phonegap-wav2m4a
块引用>不过,我想走得更远,所以我修改
CDVSound.m
在iOS版。
我只是按照这些说明:
https://gist.github.com/jlsuarezs/d48094d431307a466496
块引用>
添加到
startRecordingAudio
方法上的CDVSound.m
这样的:*的NSDictionary = recordSettings [NSDictionary的dictionaryWithObjectsAndKeys:
[NSNumber的numberWithInt:kAudioFormatMPEG4AAC],AVFormatIDKey,
[NSNumber的numberWithFloat:16000.0],AVSampleRateKey,
[的NSNumber numberWithInt:1],AVNumberOfChannelsKey,
零];替换为:
audioFile.recorder = [[CDVAudioRecorder页头] initWithURL:audioFile.resourceURL设置:零误差:放大器;错误] //默认PCM录音
使用:
audioFile.recorder = [[CDVAudioRecorder页头] initWithURL:audioFile.resourceURL设置:recordSettings错误:&放大器;错误]
<醇开始=3>- 更改其他线路:
CDVSound.m进行检查以确保您使用的是wav文件。只需在文件的顶部改变这个应该prevent这一点。定义RECORDING_WAV @WAV
我改成了:
的#define RECORDING_WAV @M4A
或
的#define RECORDING_M4A @M4A
和中包含
RECORDING_WAV
变量文件实例变化。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 compressedSolved!
I did it with a
wav2m4a
plugin.But I wanted to go further so I modified
CDVSound.m
at iOS. I just followed these instructions:
Add to the
startRecordingAudio
method onCDVSound.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.这篇关于如何为Base64 WAV转换为JavaScript中的base64 MP3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!