Comments (6)
Looks like you encode stereo as mono
Sent from my iPhone
On Jun 21, 2016, at 00:56, Julius Athenstaedt [email protected] wrote:
First of all thank you for that great lib!
I want to convert a 1411 kbps pcm_s16le 44100 Hz stereo, s16(recorded with recordRTC) to mp3.
The problem is that the wav file sounds perfect but the converted mp3 file sounds bad, sounds lower than the original and is twice as long.Full js: http://julius.athenstaedt.net/rep/rcx2/background.js
recorded wav: http://julius.athenstaedt.net/rep/wav%20(16).wav
converted mp3 http://julius.athenstaedt.net/rep/mpeg%20(14).mp3function convertToMP3(audioBlob) {
//audioBlob is the recorded Blob from recordRTC api
//with FileReader get the dataform like with XMLHttpRequest (maybe the problem?)
console.log(audioBlob);
var audioData;
fileReader = fileReader || new FileReader();
fileReader.onload = function() {
audioData = this.result;var wav = lamejs.WavHeader.readHeader(new DataView(audioData)); console.log("wav:",wav); mp3encoder = new lamejs.Mp3Encoder(wav.channels, wav.sampleRate, 128); var mp3Data = []; left = new Int16Array(audioData, wav.dataOffset, wav.dataLen /2); right = new Int16Array(audioData, wav.dataOffset, wav.dataLen /2); sampleBlockSize = 1152; var mp3buf=[]; for (var i = 0; i < left.length; i += sampleBlockSize) { leftChunk = left.subarray(i, i + sampleBlockSize); rightChunk = right.subarray(i, i + sampleBlockSize); mp3buf = mp3encoder.encodeBuffer(leftChunk, rightChunk); if (mp3buf.length > 0) { mp3Data.push(new Int8Array(mp3buf)); } } 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); saveFile(url, "mpeg.mp3"); }; fileReader.readAsArrayBuffer(audioBlob);
}
Thank You for help!!
(sorry for bad english)—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or mute the thread.
from lamejs.
And what I have to change? I have used the code for stereo from the example.
from lamejs.
Did you split your stereo input into left and right channels?
Sent from my iPhone
On Jun 24, 2016, at 18:34, Julius Athenstaedt [email protected] wrote:
And what I have to change? I have used the code for stereo from the example.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or mute the thread.
from lamejs.
Yes like in the example, but their was only one second silence. So maybe I splitted wrong:
left = new Int16Array(audioData, wav.dataOffset, wav.dataLen /2);
right = new Int16Array(audioData, wav.dataOffset, wav.dataLen /2);
from lamejs.
Yes this is wrong.
Split by taking every other sample into separate channel.
For i=0 i<data.length i+=2
Left= data [i]
Right = data[i+1]
And then put left and right samples into their own int16 arrays
Sent from my iPhone
On Jun 24, 2016, at 19:18, Julius Athenstaedt [email protected] wrote:
Yes like in the example, but their was only one second silence. So maybe I splitted wrong:
left = new Int16Array(audioData, wav.dataOffset, wav.dataLen /2);
right = new Int16Array(audioData, wav.dataOffset, wav.dataLen /2);
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or mute the thread.
from lamejs.
Thank you that was the error.
correctly splitted:
//audioData is the wav-blob converted to an ArrayBuffer
var data = new Int16Array(audioData, wav.dataOffset, wav.dataLen/2);
for (i = 0; i < data.length; i += 2) {
left.push(data[i]);
right.push(data[i + 1]);
}
left = new Int16Array(left);
right = new Int16Array(right);
from lamejs.
Related Issues (20)
- lamejs not working with angular 8 -- Uncaught ReferenceError: Lame is not defined HOT 3
- Silent MP3 file when converting output from Azure Speech-to-Text javascript SDK HOT 2
- Is it possible to use VBR (variable bit rate) HOT 1
- Blob to MP3 HOT 1
- lamejs.WavHeader.readHeader - Uncaught (in promise) TypeError: Cannot read property 'dataOffset' of undefined HOT 3
- There is a problem with the sound quality in the node environment
- Deleted
- recorder wavdata to mp3 causes ui rendering block HOT 2
- window not defined
- "MPEGMode is not defined" HOT 21
- [Firefox] Data from right channel is not passed to encoder despite there are expected two channels
- MPEGMode is not defined HOT 5
- No sound in trimmed & encoded audio blob, Vue 2. Why?
- wav转mp3的时候lampjs报"ReferenceError: MPEGMode is not defined" HOT 11
- Cannot read properties of undefined (reading 'println') HOT 1
- can i convert amr to mp3?
- License clarification
- zhuker/lamejs 打包报错 HOT 1
- Why does this code work on Firefox not on Chromium?
- Maintainer needed? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from lamejs.