Giter VIP home page Giter VIP logo

Comments (6)

DeusExLibris avatar DeusExLibris commented on July 18, 2024 1

@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.

javismiles avatar javismiles commented on July 18, 2024

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;i

Javier 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.

javismiles avatar javismiles commented on July 18, 2024

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.

aenciso avatar aenciso commented on July 18, 2024

@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.

DeusExLibris avatar DeusExLibris commented on July 18, 2024

@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.

aenciso avatar aenciso commented on July 18, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.