Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

453
Views
¿Cómo cortar el archivo de audio de la entrada en el navegador con js, lamejs?

Tengo una entrada en mi componente Vue donde cargo el archivo de audio a través de @change, luego necesito cortarlo, por ejemplo, tengo 30 segundos de audio y necesito recibir audio de 5 a 15 segundos. He instalado el paquete lamejs para hacer eso.

Pero después de todas mis operaciones con audio, recibo audio cortado pero sin ningún sonido, así que no sé cuál es la razón de eso. ¡Necesitas ayuda!

método que carga el archivo

 async onUploadFile(event) { const fileData = event.target.files[0]; this.file = fileData; await this.decodeFile(fileData); },

método que decodifica el archivo a audioBuffer

 async onUploadFile(event) { const fileData = event.target.files[0]; this.file = fileData; await this.decodeFile(fileData); },

método que corta el audio y lo codifica en mp3 y luego recibe la URL del blob

 async audioBufferSlice(buffer, begin, end) { const audioContext = new AudioContext(); const channels = buffer.numberOfChannels; const rate = buffer.sampleRate; const duration = buffer.duration; const startOffset = rate * begin; const endOffset = rate * end; const frameCount = endOffset - startOffset; const audioLength = endOffset - startOffset; let trimmedAudio = audioContext.createBuffer( buffer.numberOfChannels, audioLength, rate ); for(var i = 0; i < buffer.numberOfChannels; i++){ trimmedAudio.copyToChannel(buffer.getChannelData(i).slice(begin, end), i); } var audioData = this.serializeAudioBuffer(trimmedAudio); let mp3Data = []; const sampleBlockSize = 1152; let mp3encoder = new lamejs.Mp3Encoder(2, audioData.sampleRate, 128); var left = new Int8Array(audioData.channels[0].length); var right = new Int8Array(audioData.channels[1].length); for (var i = 0; i < audioData.channels[0].length; i += sampleBlockSize) { var leftChunk = left.subarray(i, i + sampleBlockSize); var rightChunk = right.subarray(i, i + sampleBlockSize); var mp3buf = await mp3encoder.encodeBuffer(leftChunk, rightChunk); if (mp3buf.length > 0) { mp3Data.push(mp3buf); } } let buf = await mp3encoder.flush(); if (buf.length > 0) { mp3Data.push(buf); } var blob = new Blob(mp3Data, {type: 'audio/mp3'}); var url = window.URL.createObjectURL(blob); console.log('MP3 URl: ', url); },

¿Qué hice mal que recibo el audio cortado pero sin ningún sonido? Miro ese repositorio como ejemplo https://github.com/Vinit-Dantkale/AudioFy

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!