-
Notifications
You must be signed in to change notification settings - Fork 8
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
While mixAllInOneSound how to repeat second file until first File duration. #67
Comments
Hi Amit, Probably what you want is the LoopSoundTransform. I don't know if it works, I hope it will ! Sound sound1 = start().withFile(new File("file1.wav")).convertIntoSound().apply(new LoopSoundTransform(300000)).stopWithSound();
Sound sound2 = start().withFile(new File("file2.wav")).convertIntoSound().stopWithSound();
start().inParallel(
prepare().mixAllInOneSound().build(),
5,
sound1, sound2
); Please note that 300000 is a random value, you should compute how much samples you need (yes the unit is in samples, not in milliseconds) |
@libetl Hey I think its working but the problem is I didn't get regarding samples, first time working on Sound programming So Can you help, how can I get the idea or calculate sample for any Audio file? It would be great help you can give me an example :-) |
Sound soundOrgination = start().withFile(file1).convertIntoSound().stopWithSound();
int SampleLength = soundOrgination.getSamplesLength();
// System.out.println("Sample Legth " + SampleLength);
Sound backgroundSound = start().withFile(file2).convertIntoSound().apply(new LoopSoundTransform(SampleLength)).stopWithSound();
start().withSound(backgroundSound ).exportToStream().playIt();
start().withSound(soundOrgination).exportToStream().playIt();```
> _I have done something like this But Both Sound not playing completely but stuck in between, any idea where I am doing this wrong?_
** Is there any limit on file duration? like 20 or 30 seconds only? |
Sorry commuting from work. |
Hello again ! I just tried to implement your task and maybe you forgot to compare the sound formats before looping. Here is a snippet that worked for me : import org.toilelibre.libe.soundtransform.model.converted.FormatInfo;
import org.toilelibre.libe.soundtransform.model.converted.sound.Sound;
import org.toilelibre.libe.soundtransform.model.exception.SoundTransformException;
import java.io.File;
import static org.toilelibre.libe.soundtransform.actions.fluent.FluentClient.start;
public class TestLoop {
public static void main(String[] args) throws SoundTransformException {
File longFile = new File("/mnt/data/lionel/aLongSound.wav");
File shortFile = new File("/mnt/data/lionel/aShortSound.wav");
Sound longSound = start().withFile(longFile).convertIntoSound().stopWithSound();
Sound shortSound = start().withFile(shortFile).convertIntoSound().stopWithSound();
FormatInfo longSoundFormat = longSound.getFormatInfo();
FormatInfo shortSoundFormat = shortSound.getFormatInfo();
float ratio = (shortSoundFormat.getSampleSize() * shortSoundFormat.getSampleRate()) /
(longSoundFormat.getSampleSize() * longSoundFormat.getSampleRate());
Sound repeatedSound = start().withSound(shortSound)
.loop((int)(longSound.getSamplesLength() * ratio)).stopWithSound();
start().withSound(longSound).mixWith(repeatedSound).exportToFile(new File("/mnt/data/lionel/output.wav"));
}
} Good luck ! |
@libetl Hey Thank you So much it's working like charm. Well thanks for the above example 👍 |
@libetl Hey Whie compiling the lib in my final Project I am getting following build error I am using |
Try the ReduceNoiseSoundTransform to lower the noise. Good luck ! |
Hey |
I build it Successfully if I use Thanks You 👍 |
Oops I did not know that the lib is not compatible with gradle android tools >= 3.
Need to have a look. Unfortunately not during this weekend (not alone).
Hopefully sunday evening or monday evening.
Le 1 déc. 2017 11:48, "Amit" <[email protected]> a écrit :
… I build it Successfully is I use classpath 'com.android.tools.build:
gradle:2.3.3'
but not with classpath 'com.android.tools.build:gradle:3.0.0'
Please help if possible
Thanks You 👍
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#67 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABLTfisPnfL4zfhrYZV1ifQk7rP6nQttks5s79mDgaJpZM4Qwpnb>
.
|
Ok, Thank you So much for this and I want to ask that Can we make the final Converted Sound as valid m4a file. Trying to do that but having some problem while merging same m4a audio with video. |
There is not any downstream conversion to MP3 ogg or m4a. I only have
upstream conversion (MP3 or ogg to sound). I think it is possible to add
all of them but too hard alone.
Le 1 déc. 2017 11:58 AM, "Amit" <[email protected]> a écrit :
… Ok, Thank you So much for this and I want to ask that Can we make the
final Converted Sound as valid m4a file. Trying to do that but having some
problem while merging same m4a audio with video.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#67 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABLTfueRzPHxbdsodh25cE71940kRuVwks5s79vtgaJpZM4Qwpnb>
.
|
How Can I use ReduceNoiseSoundTransform on Sound
How to calculate the "percentOfMaxVolumeThreshold" |
That is a good question, there is no obvious way to compute dynamically a percentage to reduce the noise. It should be a static value. Try different values. If your need is to get a sound with a normalized volume in decibels, Sound normalizedSound = start().withSound(mixedSound).apply(new NormalizeSoundTransform(0.9f)).stopWithSound(); |
@libetl |
🤔 Try to apply the noise filter (ReduceNoiseSoundTransform) on the voice sound alone. |
here is a working configuration with gradle (2.3.3) : compile('org.toile-libre.libe:soundtransform:1.0.23'){
exclude group:'junit', module:'junit'
} |
I don't know why junit 3.8.2 is exported from my lib. Weird. |
@libetl Applying ReduceNoiseSoundTransform(0.1f) but it becomes noisy after that. What else I need to do? |
no luck :( You should send me your sample so I can understand more the trouble with it. |
@libetl Hey, I have sent you the sample Sound Zip file on your mail Id - Also attaching the same over here
It would be great if you can look into the issue and help me, I am stuck on this part for very long. 👍 |
mixWith operation seems to have a bug. I am sorry. |
@libetl Any Chance to fix this issue?? I really need this Please |
spent the whole evening yesterday, will try again to understand this evening, no promise yet. |
looking for some documentation about how to reduce noise efficiently |
@libetl Thank you So much 💯 |
Hi Amit, |
@libetl That would be a great help :-) |
Hi, That is not good, but it still contributes to reducing the noise level : Create this SoundTransform class : package org.toilelibre.libe.soundtransform.infrastructure.service.converted.sound.transforms;
import org.apache.commons.math3.complex.Complex;
import org.toilelibre.libe.soundtransform.model.converted.FormatInfo;
import org.toilelibre.libe.soundtransform.model.converted.sound.transform.SimpleFrequencySoundTransform;
import org.toilelibre.libe.soundtransform.model.converted.spectrum.Spectrum;
public class BlurSoundTransform extends SimpleFrequencySoundTransform<Complex []> {
@Override
public Spectrum<Complex[]> transformFrequencies (final Spectrum<Complex[]> fs, final int offset, final int powOf2NearestLength, final int length) {
double averageReal = 0f;
double averageImaginary = 0f;
Complex[] newArray = new Complex[powOf2NearestLength];
for (int j = 0 ; j < length ; j++) {
averageReal = averageReal + Math.abs(fs.getState()[j].getReal());
averageImaginary = averageImaginary + Math.abs(fs.getState()[j].getImaginary());
}
averageReal = averageReal / length;
averageImaginary = averageImaginary / length;
final double averageAbs = Math.pow(averageReal, 2) + Math.pow(averageImaginary, 2);
for (int j = 0 ; j < length ; j++) {
double difference = Math.abs(averageAbs -
(Math.pow(fs.getState()[j].getReal(), 2) + Math.pow(fs.getState()[j].getImaginary(), 2)));
newArray[j] = difference > averageAbs / 1f ? fs.getState()[j] : new Complex(0);
}
for (int j = length ; j < powOf2NearestLength ; j++) {
newArray[j] = new Complex(0);
}
return new Spectrum<Complex []> (newArray, new FormatInfo(fs.getSampleSize (), fs.getSampleRate ()));
}
} Call it from your example, this is what I tried: public class TestLoop {
public static void main(String[] args) throws SoundTransformException {
Sound sampleSound = start().withFile(new File("/mnt/data/lionel/LoopSound.wav")).convertIntoSound()
.apply(new BlurSoundTransform()).apply(new NormalizeSoundTransform(0.5f)).stopWithSound();
Sound voiceSound = start().withFile(new File("/mnt/data/lionel/VoiceRecordSound.wav")).convertIntoSound()
.apply(new BlurSoundTransform()).apply(new NormalizeSoundTransform(1f)).stopWithSound();
Sound repeatedSound = start().withSound(sampleSound).changeFormat(voiceSound.getFormatInfo())
.apply(new LoopSoundTransform(voiceSound.getSamplesLength())).stopWithSound();
final Object stopMonitor = new Object();
synchronized (stopMonitor) {
start().withSound(voiceSound).mixWith(repeatedSound).playIt(stopMonitor);
try {stopMonitor.wait();} catch (InterruptedException e) {}
}
}
} No miracle to hear, the noise level is reduced slightly, maybe there should be a better filter than this one. |
Thank you so this Awesome Lib for SoundTransform -
I am trying something like this.
try { start().inParallel(prepare().convertIntoSound().build() , 5, file1, file2) .mixAllInOneSound().exportToFile(outPutFile); } catch (SoundTransformException e) { e.printStackTrace(); }
the Output file is of duration 25 sec, I want to convert as complete 55sec by repeat second file for at least two times. How can achieve this, I am doing this for adding background Guitar sound in any recorded file in Android.
Please help, Thank you.
The text was updated successfully, but these errors were encountered: