Comments (6)
@javismiles I had a similar problem in my project and discovered that different systems will use different sample rates. Because you are telling the encoder that the incoming data is processed at 44.1K samples per second, if the actual sample rate is higher, you will get the behavior you described. In fact, I am willing to bet that you are on a windows machine and that the sample rate (if you inspect the audio context, you can find this value) will be 48K. For example, 1Khz tone would be encoded as 44100/48000*1000 = .919Khz.
from lamejs.
Dear Esvirsky
Thank you so much for your kind reply,
following your advice i made it work with the code you see here below, now
it records and encodes in real time from mic and then uploads and writes to
server an mp3 successfully, yay, however i have two issues and a question:
a) the very beginning of recording gets distorted and a bit cut, the last
second of recording also gets cut, so if i record 8 seconds, the first half
second and last half second get cut, and also the first second has
breaks-cuts in it, the intermediate 6 seconds are ok
b) sound seems to sound somehow lower frequency than the voice recorded, is
that an EQ issue or an encoder issue or is there a problem in my code?
c) final thing, at the moment the encoding is not happening in a web
worker, how could i modify this code to make the encoding happen in the
background in a web worker to improve performance etc?
thank you so so so much and here below is my code:
<script> navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia; liblame = new lamejs(); var mymp3Encoder=new liblame.Mp3Encoder(1,44100,320); function upload(blobOrFile) { var form = new FormData(); form.append("blobbie", blobOrFile); var xhr = new XMLHttpRequest(); xhr.open('POST', './upload.php', true);xhr.send(form); xhr.onreadystatechange = function(e) { if (xhr.readyState == 4) { if (xhr.status==200) { cap=xhr.responseText; }}}; xhr.onload = function(e) {}; xhr.upload.onprogress = function(e) { if (e.lengthComputable) {a = (e.loaded / e.total) * 100; console.log (e.loaded+"/"+e.total+"/"+a);}}; } function record() { thetext=$("#statusbit"); navigator.getUserMedia({audio: true}, function (stream) { var stopRecording = beginRecording(stream); var start = +new Date(); thetext.text('Recording... 3.0'); // Run a function every 100 ms to update the UI var timer = setInterval(function () { var duration = new Date() - start; if (duration < 8000) { thetext.text('Recording... ' + ((8000 - duration) / 1000).toFixed(1)); } else { var buffers = stopRecording(); clearInterval(timer); console.log ("Get MP3"); mp3Buffer=mymp3Encoder.flush(); if (mp3Buffer.length>0) buffers.push(mp3Buffer); var blob=new Blob(buffers, {type: 'audio/mpeg'}); upload(blob); } }, 100); }, function (error) {thetext.text('Error! Try again.');}); } function beginRecording(stream) { // Set up Web Audio API to process data from the media stream (microphone). var context = new AudioContext(); var microphone = context.createMediaStreamSource(stream); var processor = context.createScriptProcessor(0, 1, 1); var buffers = []; processor.onaudioprocess = function (event) { var data = event.inputBuffer.getChannelData(0); var lo = data; //the decoded data range: -1 +1 var l = new Float32Array(lo.length); for(var i=0;iJavier ideami
Ideami Studios
San Francisco / Barcelona
+1 408 634 9071
http://torchprinciple.com
http://ideami.com
http://posterini.com
http://incredivid.com
http://torchprinciple.com
On Wed, Oct 21, 2015 at 6:01 PM, esvirsky [email protected] wrote:
Take a look at this #10 #10. You
have to convert the incoming Float32Array to a different Float32Array or
Int16Array and you can just feed that data to encodeBuffer. Like this:var buffer = mp3encoder.encodeBuffer(l);
buffers.push(buffer)hope that helps.
—
Reply to this email directly or view it on GitHub
#14 (comment).
from lamejs.
i just confirmed that my code is recording the sound between 1 and 2 semitones lower in frequency than what it should..... just recorded some piano notes, and what comes out is between 1 and 2 semitones lower... why is that happening? code is above, best
from lamejs.
@javismiles and @DeusExLibris I had the same issue in regards to pitch. My workaround was to increase sample rate from 44.1K to 48K, not sure if it's the right approach but it works.
from lamejs.
@aenciso: Just to clarify for future readers, you are saying you changed the sample rate of the stream after capturing it from the microphone using something like ffmpeg, right? It isn't possible to change the sample rate of the AudioContext as it is a read-only property.
from lamejs.
@DeusExLibris sorry yes. I captured the audio using audioContext and then using lamejs to convert the stream to MP3 on the fly but I had to set the Mp3Encoder rate to 48000 to avoid that problem described above.
from lamejs.
Related Issues (20)
- Working With MediaRecorder API HOT 1
- Dependency on module mic-recorder-to-mp3 HOT 1
- 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
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.