Javascript to squeeze sounds?

Does anyone know to compress a sound with Javascipt?

Does anyone know make a sound a specified percentage of its current length (in seconds) with Javascipt?

I'm not quite sure what you're asking. The title says "squeeze" which I take to mean "take up less space." But "compress," in the text, is a technical term with respect to sounds, meaning to reduce the variation of loudness.

For the less-space problem, a good first try would be to leave out every other sample. This will distort the high frequencies, but not the low frequencies. How much that matters depends on what kind of sound it is. Long ago, the phone company (back when there was just one) determined experimentally that the 300 to 3000 Hz range of frequencies is enough for intelligible speech, and even to give you a good sense of whose voice you're hearing. But for music, you really need 20kHz for it to sound good.

But if your sound file is an mp3, it's already about as small as it can get without sounding terrible (for music). The mp3 format is all about compression. It's done in a more complicated way than just leaving out samples, so it loses low frequencies rather than high frequencies.

If what you want is to reduce the variation in loudness, pick the value you'd like as the middle of the range, let's say 0.7 out of 1, and then for each sample you compute 0.7+0.66*(x-0.7) for a compression ration of 2/3.

Sorry, I don't mean like compressing the code of the sound to take up less information but still be the same sound, I mean, quite literally, squeezing it, like the Scratch sound editor option 'make faster', but by a specified amount, like
(make sound(recording1 v) faster by(10) secs::sound)

(make sound(recording1 v) faster by(50)%::sound)

I made a prototype of the block using KEEP. Update: Done easier with altering of sample rate.
There are a lot of bugs, but it sort of works. No more bugs.

Your block makes the sound longer with a smaller percentage, and shorter with a higher one!
It makes nightcore daycore and vice versa!
Well, as long as I bear that in mind and use the percentage opposite of what I want, it'll work.

My block doesn't speed it up, per se, but instead alters it to that percentage. So 50% speed would be 50% the amount of speed it originally was, etc. That's the way it's supposed to be, isn't it?

It's supposed to be like that, except 50% is half as long and 200% is twice as long. That's how percentages work.

I personally find it easier to use it the other way, but okay, I'll update the project for that.
Try clicking the link again.

It isn't, but whatever.

We all have our opinions. I think so, you may not think so. There isn't a definitive answer.

What? No, the project isn't updated. I'll deal with it.

Does the block at least look different?


EDIT: I see you've removed the -1, but it doesn't help.

Dang it, I pressed save like 7 times and clicked it to make sure!
Whatever, you can "fix" it by removing the image block in the definition.
Edit: That was the closest I could get to meeting your very specific standards. I got nothing.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.