如何为Base64 WAV转换为JavaScript中的base64 MP3 [英] How to convert base64 wav to base64 mp3 in JavaScript

查看:3018
本文介绍了如何为Base64 WAV转换为JavaScript中的base64 MP3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有麻烦我的应用程序。

我要录制声音并将其存储在使用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



  1. 添加到 startRecordingAudio 方法上的 CDVSound.m 这样的:

    *的NSDictionary = recordSettings [NSDictionary的dictionaryWithObjectsAndKeys:
                                        [NSNumber的numberWithInt:kAudioFormatMPEG4AAC],AVFormatIDKey,
                                        [NSNumber的numberWithFloat:16000.0],AVSampleRateKey,
                                        [的NSNumber numberWithInt:1],AVNumberOfChannelsKey,
                                        零];


  2. 替换为:

    audioFile.recorder = [[CDVAudioRecorder页头] initWithURL:audioFile.resourceURL设置:零误差:放大器;错误] //默认PCM录音

    使用:

    audioFile.recorder = [[CDVAudioRecorder页头] initWithURL:audioFile.resourceURL设置:recordSettings错误:&放大器;错误]

    <醇开始=3>
  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 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

  1. 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];

  2. 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];

    1. 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆