Merge two AudioInputStreams with varying AudioFormats
843802Mar 17 2010 — edited Mar 18 2010Ok, let me start by saying what I am trying to accomplish...
I work for a university and am attempting to build an audio "merging" application. Essentially, a foreign language professor will record half of a conversation ahead of time. Then, this professor's students will load the audio file created by the professor into the application. As this audio file is playing, the student can record the second half of the conversation "over" the initial audio clip, as a separate audio stream. Finally, the student can save these two audio streams as a single audio file with the two streams merged together.
That's the background... here's my problem...
Using the audio concatenation example found on JSResources.org, I was able to merge the professor's file with the students recorded audio stream into a single file. However, this only works if the audio formats are exactly the same. If the formats are different when I merge them together, the professor's audio stream (which doesn't match the student's recorded format) is distorted, meaning it is either played faster or slower in comparison to the student's audio stream. I want to be able to take into account the fact that some professors may use varying formats when creating their files.
I'm assuming this issue has something to do with how I am reading from the AudioInputStreams, because when I play these streams back (without saving them in any way) they sound fine. When i attempt to write them out to a file and play that file back is when I have the issue. Is there a way to write these two streams out to file so they both sound 'normal'?
Thanks!