Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
lamejsfix
Advanced tools
Readme
Fast mp3 encoder written in JavaScript. On my machine it works 20x faster than realtime (it will encode 132 second long sample in 6.5 seconds) both on node and chrome. lamejs is a rewrite of jump3r-code which is a rewrite of libmp3lame.
this lib is temporary to fix bug "MPEGMode is not defined". it's forked by 'https://github.com/isolin/lamejs'
To install via Bower or npm, simply do the following:
$ bower install lamejs --save
$ npm install lamejs
<script src='lame.all.js'></script>
<script>
var mp3Data = [];
var mp3encoder = new lamejs.Mp3Encoder(1, 44100, 128); //mono 44.1khz encode to 128kbps
var samples = new Int16Array(44100); //one second of silence replace that with your own samples
var mp3Tmp = mp3encoder.encodeBuffer(samples); //encode mp3
//Push encode buffer to mp3Data variable
mp3Data.push(mp3Tmp);
// Get end part of mp3
mp3Tmp = mp3encoder.flush();
// Write last data to the output data, too
// mp3Data contains now the complete mp3Data
mp3Data.push(mp3Tmp);
console.debug(mp3Data);
</script>
To use lamejs in Node.js build, you can install it from npm
:
npm install lamejs
Then use it:
var lamejs = require("lamejs");
Either see example.html for full example of wav file encoding in browser or use this:
<script src='lame.all.js'></script>
<script>
channels = 1; //1 for mono or 2 for stereo
sampleRate = 44100; //44.1khz (normal mp3 samplerate)
kbps = 128; //encode 128kbps mp3
mp3encoder = new lamejs.Mp3Encoder(channels, sampleRate, kbps);
var mp3Data = [];
samples = new Int16Array(44100); //one second of silence (get your data from the source you have)
sampleBlockSize = 1152; //can be anything but make it a multiple of 576 to make encoders life easier
var mp3Data = [];
for (var i = 0; i < samples.length; i += sampleBlockSize) {
sampleChunk = samples.subarray(i, i + sampleBlockSize);
var mp3buf = mp3encoder.encodeBuffer(sampleChunk);
if (mp3buf.length > 0) {
mp3Data.push(mp3buf);
}
}
var mp3buf = mp3encoder.flush(); //finish writing mp3
if (mp3buf.length > 0) {
mp3Data.push(new Int8Array(mp3buf));
}
var blob = new Blob(mp3Data, {type: 'audio/mp3'});
var url = window.URL.createObjectURL(blob);
console.log('MP3 URl: ', url);
</script>
If you want to encode stereo mp3 use separate sample buffers for left and right channel
<script src='lame.all.js'></script>
<script>
mp3encoder = new lamejs.Mp3Encoder(2, 44100, 128);
var mp3Data = [];
left = new Int16Array(44100); //one second of silence (get your data from the source you have)
right = new Int16Array(44100); //one second of silence (get your data from the source you have)
sampleBlockSize = 1152; //can be anything but make it a multiple of 576 to make encoders life easier
for (var i = 0; i < samples.length; i += sampleBlockSize) {
leftChunk = left.subarray(i, i + sampleBlockSize);
rightChunk = right.subarray(i, i + sampleBlockSize);
var mp3buf = mp3encoder.encodeBuffer(leftChunk, rightChunk);
if (mp3buf.length > 0) {
mp3Data.push(mp3buf);
}
}
var mp3buf = mp3encoder.flush(); //finish writing mp3
if (mp3buf.length > 0) {
mp3Data.push(mp3buf);
}
console.log(mp3Data);
</script>
FAQs
Pure JavaScript MP3 Encoder(this a tmp lib to fix bug 'MPEGMode is not defined')
The npm package lamejsfix receives a total of 46 weekly downloads. As such, lamejsfix popularity was classified as not popular.
We found that lamejsfix demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.