-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Save a selection as a new file #526
Comments
Duplicate of #419. |
I feel like the pieces are there, but am not versed in blobs. Specifically, the code in #419 says that it allows a user to select an area, then it returns a blob containing the audio in that area; how would someone save that audio clip to the user's disk? |
So, when you create a region, you have its start and end positions in seconds. In Web Audio, the audio track (when decoded) is represented as an array of floats. To copy your region, you need to know where in the array it starts and ends–in frames, not in seconds. To convert seconds to frames, you just multiply seconds by the sample rate with which the audio was decoded. In the original example we copy the whole audio into a new buffer (because
Hopefully this helps. |
I've been looking this over for a little while, and while I understand the process of copying frame by frame from the original buffer in to an empty buffer, As for the saving, would it be correct to say that once the buffer is full, another tool will be needed to parse the buffer in to a file (WAV, but ideally mp3)? |
It's |
Cheers. var segmentDuration = wavesurfer.backend.buffer.duration;
var originalBuffer = wavesurfer.backend.buffer;
var emptySegment = wavesurfer.backend.ac.createBuffer(
originalBuffer.numberOfChannels,
segmentDuration * originalBuffer.sampleRate,
originalBuffer.sampleRate
);
for (var i = 0; i < originalBuffer.channels; i++) {
var chanData = originalBuffer.getChannelData(i);
var segmentChanData = emptySegment.getChannelData(i);
for (var j = 0, len = chanData.length; j < len; j++) {
segmentChanData[j] = chanData[j];
}
}
emptySegment; // Here you go! Not empty anymore, contains a copy of the segment! |
How can we convert the emptySegment in above code to blob?? |
Have tried below code but, the result mp3 is not playing, any suggestion? var blob = new window.Blob([new Uint8Array(emptySegment)], { type: 'audio/mpeg'}); console.log('done encoding'); |
This thread ends inconclusively, and I would like to produce what Joshfindit originally intended: a simple sound trimmer or editor based on wavesurger's ability to define clips visually. Or has this been done elsewhere? |
Facing exactly the same issue, did you figure it out? I've tried to use region's start and end and use ffmpeg.wasm to cut the region. Also tried to use getChannelData(0) and build either a Blob or File object and export it, but unsuccessfully. |
Nope, I didn’t. But I didn’t venture too far to find one. I wanted something quick and easy and discovered that it did not work that way. Please copy me if you find something.
I am still actively using wavesurfer.js, but only for the features that were available in version 1.0 and accompanying libraries.
Thanks,
Slava
From: I, Erik ***@***.***>
Sent: Tuesday, July 5, 2022 12:06 AM
To: katspaugh/wavesurfer.js ***@***.***>
Cc: LBPSlava ***@***.***>; Comment ***@***.***>
Subject: Re: [katspaugh/wavesurfer.js] Save a selection as a new file (#526)
Facing exactly the same issue, did you figure it out?
I've tried to use region's start and end and use ffmpeg.wasm to cut the region. Also tried to use getChannelData(0) and build either a Blob or File object and export it, but unsuccessfully.
—
Reply to this email directly, view it on GitHub <#526 (comment)> , or unsubscribe <https://github.com/notifications/unsubscribe-auth/AA7XXU7KFYA2JJCK5APD4ITVSOYBNANCNFSM4BPPFA6Q> .
You are receiving this because you commented. <https://github.com/notifications/beacon/AA7XXU6N5VYRA7BVAH3ZO33VSOYBNA5CNFSM4BPPFA62YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOIYBLOVY.gif> Message ID: ***@***.*** ***@***.***> >
|
I know I'm a bit late to the party but if it helps someone else in the future he goes: I used lamejs as the encoder library that can be included as a js in your page:
wavesurfer stores the actual audio data in its buffer variable: We need to create our own samples buffer by selecting the samples from the wavesurfer main buffer.
The trick seems to have been that the audio samples to export need to be in 16bit array whereas wavesurfer uses a float32 array. The above example is also hardcoded for mono so please note some adjustments are needed to support stereo. |
I've looked through the documentation as well as the issues, and can't see anywhere that talks about saving a file from wavesurfer.
Is there currently a built-in way to do this?
What I'm looking for in the end is to:
The text was updated successfully, but these errors were encountered: