-
Notifications
You must be signed in to change notification settings - Fork 102
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
I want to import a part of music data. #1386
Comments
Hi! Meyda operates on the buffers you give it, so if you load the audio from disk in your code and pass the appropriate buffers, that’s what Meyda will calculate the features on. Or are you looking for this feature in the CLI? |
Thank you for your reply. It is very encouraging. The execution environment is not CLI. My goal is to do DeepLearning while DJing. To do this, I am creating an environment for music analysis. Then I came across this library. I would like to build this environment, but I am encountering some problems.
For 1, we think we can solve this problem by specifying some time periods in the music and decode them. I would really appreciate any good advice you can give me. I'm sorry if my English is not good enough to read it. |
Sorry that the error you encountered wasn't clear enough! The issue is that the length of your buffer always needs to be a power of 2. So, if you can cut your audio into a length of that size, you will be able to use this method. An important piece of context is that for the purposes of audio analysis, you can add silence to the start and end of your buffer and you will and up with the same result - so if you have 45 seconds of audio at a CD quality sample rate, you have 45*44100 samples (buffer length 1,984,500). The next power of 2 is 2^21, 2,097,152. This means that you can add 2^21-45*44100 zeros to the end of your signal and then you will be able to extract audio features for this audio. Another approach would be to take your 45 seconds of audio and cut it into chunks, then extract the features from these chunks and take the average result as representative of the whole sound. For example, splitting the signal into chunks that are of length 2^16 would result in chunks that are roughly 1.5 seconds long. An additional benefit of this approach is that you will have information about how the audio features change over the course of the sound, which you can use in machine learning applications as a feature in and of itself. I hope that helps, let me know if I can clarify further! |
I would love to know how to split audio into chunks, decode only the specified chunk portion and pass it to meyda. how do I chunk it after reading in fs? |
If you had an array that was 11 elements long (like an audio buffer with 11 samples), and you wanted to chunk that buffer up into arrays that are 4 elements long, you could do something like: const myArray = [0,0,0,0,0,0,0,0,0,0,0];
// array is the buffer, and n is the size of the chunks
function chunk(array, n) {
// Copy the array to avoid modifying the original
let myArrayCopy = [...array];
// Create a second array to store each of the chunks
let chunks = [];
// While there are still enough elements in the array to create a chunk of the right size...
while (myArrayCopy.length >= n) {
// Take the first n elements, remove them from the array, and push them as an array onto the chunks we'll return
chunks.push(myArrayCopy.splice(0,n));
}
// Here you may be left with some remaining samples. You can decide whether to discard them, to add zeros
// to the end of the array as I described in my previous comment, or to return an incomplete chunk - whatever is
// appropriate for your code. Just make sure to only pass buffers to meyda of the correct length.
return chunks;
}; That code would return an array as follows: const chunkedArray = chunk(myArray, 3);
console.log(chunkedArray);
[
[0,0,0],
[0,0,0],
[0,0,0],
] So now you end up with multiple buffers representing a shorter part of the signal. To go back to my example above, if you have an audio recording that you loaded from disk that is 1,984,500 samples long, you can chunk that array of samples by doing |
Okay that's okay I'll let you know if I want it lol |
Hello, I have a question. I am an excited user of this library.
Is there any way to specify a duration for the audio file to be loaded, like the python library librosa.load?
If not, is there any way to add this functionality?
We would like to use the above method to reduce the amount of data processing when decoding a song.
The text was updated successfully, but these errors were encountered: