I want to modify the pitch of the audio clip dynamically based on the user input at different time instants, say if user enters change the pitch of the audio after 10 seconds then how can I achieve the same?
I found this link that describes how to modify the pitch but i want to repeat this process at different time instants of the audio clip and for some short duration only. Can anybody guide me on this ?
Some Edits
Edit 1
I found this code as I mentioned this previously as well
//source file
final File file1 = new File(“Sample.mp3”);
//destination file
final File file2 = new File(“Sample_cat.wav”);
//audio stream of file1
final AudioInputStream in1 = getAudioInputStream(file1);
//get audio format for targetted sound
final AudioFormat inFormat = getOutFormat(in1.getFormat());
//change the frequency of Audio format
private AudioFormat getOutFormat(AudioFormat inFormat) {
int ch = inFormat.getChannels();
float rate = inFormat.getSampleRate();
return new AudioFormat(PCM_SIGNED, 72000, 16, ch, ch * 2, rate,
inFormat.isBigEndian());
}
//get the target file audio stream using file format
final AudioInputStream in2 = getAudioInputStream(inFormat, in1);
//write the audio file in targeted pitch file
AudioSystem.write(in2, AudioFileFormat.Type.WAVE, file2);
EDIT 2 I found another code which sets the position of audio file from where you want to start and stop the audio.
File audioFile = new File(audioFilePath);
AudioInputStream audioStream = AudioSystem.getAudioInputStream(audioFile);
AudioFormat format = audioStream.getFormat();
DataLine.Info info = new DataLine.Info(Clip.class, format);
Clip audioClip = (Clip) AudioSystem.getLine(info);
audioClip.open(audioStream);
audioClip.setLoopPoints(10_000, 500_000);
audioClip.loop(1);
Now, How can I change the pitch for the duration set in Edit 2 i.e. 10 ms to 50 ms using the code in Edit 1
can anybody suggest me if I can do the same thing in any other ways except Java ? then suggestions are welcome... Please Help. I am new to this.
**Edit 3 **
One can refer the exact problem on this link : link
These are the values(in milliseconds) that I am referring :
public static void convertMsgToAudio(String msg){
int len = msg.length();
duration = new double[len];
msg = msg.toUpperCase();
System.out.println("Msg 2 : " + msg);
int i;
//char ch;
for(i=0;i<msg.length();i++){
if(msg.charAt(i) == 'A'){
duration[i] = 50000;
}
else if (msg.charAt(i) == 'B'){
duration[i] = 100000;
}
else if (msg.charAt(i) == 'C'){
duration[i] = 150000;
}
else if (msg.charAt(i) == 'D'){
duration[i] = 200000;
}
else if (msg.charAt(i) == 'E'){
duration[i] = 250000;
}
else if (msg.charAt(i) == 'F'){
duration[i] = 300000;
}
else if (msg.charAt(i) == 'G'){
duration[i] = 350000;
}
else if (msg.charAt(i) == 'H'){
duration[i] = 400000;
}
else if (msg.charAt(i) == 'I'){
duration[i] = 450000;
}
else if (msg.charAt(i) == 'J'){
duration[i] = 500000;
}
else if (msg.charAt(i) == 'K'){
duration[i] = 550000;
}
else if (msg.charAt(i) == 'L'){
duration[i] = 600000;
}
else if (msg.charAt(i) == 'M'){
duration[i] = 650000;
}
else if (msg.charAt(i) == 'N'){
duration[i] = 700000;
}
else if (msg.charAt(i) == 'O'){
duration[i] = 750000;
}
else if (msg.charAt(i) == 'P'){
duration[i] = 800000;
}
else if (msg.charAt(i) == 'Q'){
duration[i] = 850000;
}
else if (msg.charAt(i) == 'R'){
duration[i] = 900000;
}
else if (msg.charAt(i) == 'S'){
duration[i] = 950000;
}
else if (msg.charAt(i) == 'T'){
duration[i] = 1000000;
}
else if (msg.charAt(i) == 'U'){
duration[i] = 1100000;
}
else if (msg.charAt(i) == 'V'){
duration[i] = 1200000;
}
else if (msg.charAt(i) == 'W'){
duration[i] = 1300000;
}
else if (msg.charAt(i) == 'X'){
duration[i] = 1400000;
}
else if (msg.charAt(i) == 'Y'){
duration[i] = 1500000;
}
else if (msg.charAt(i) == 'Z'){
duration[i] = 1600000;
}
}
}