Audio "blending"

Rusty

Well-Known Member
Licensed User
Longtime User
I need to be able to take two audio files (.mp3, but can be anything to accomplish this), I need to be able to "blend" the two audio files so that they play "end to end".

For example: If I have an audio file that says "Hello my name is " and another that says "Fred", I'd like to "blend" them so that the audio says "Hello my name is Fred".
Does anyone know if this is possible? If so, any thoughts on technique? I am not trying to record the two files as one, I am wanting to play one immediately followed by the other, then play another... Hopefully the sound would be "seamless"

Thanks,
Rusty
 
Last edited:

stevel05

Expert
Licensed User
Longtime User
For short sounds, you can play them one after the other with any of the audio libraries. There are a number of ways to alter the timing between the two files.

There is probably no need to merge the files.

Soundpool would give you most control over playback.

-------------------
Sent via Tapatalk
 
Upvote 0

Rusty

Well-Known Member
Licensed User
Longtime User
Perfect!
Can Soundpool be made to play multiple loaded files sequentially, immediately one after the other?
I used the soundpool example Erel provided and they "talk" over themselves.
Thanks!
Rusty
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
Soundpool doesn't have a play complete call back, but if you know the length of each sample, you can play them via a timer.
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
There is not really enough information to give you a definitive answer, it depends on how you are creating the files as to the best solution overall.

You Could handle the whole thing using MediaPlayer, which has a play completed event so you could play the next file after one has completed.

If the files have extra space at the end then it will cause a delay.

You could cycle through all of the file you are going to use and get the duration using MediaPlayer then play them using SoundPool and a timer.

If you are creating the files in advance, you can see how long they are and enter that along with the file.

Of you are recording the file within the app you can calculate it from the recorded data, you may want to trim silence.

So there are many possible ways to do it, depending on what you are trying to achieve.
 
Upvote 0

Rusty

Well-Known Member
Licensed User
Longtime User
Steve,
Thanks for the valuable input.
I do record my own sound files (MP3).
I've tried playing the multiple files one after the other after having trimmed all the silence of both ends. There seems to be a loading delay on the (slightly) longer files so even though the silence is trimmed it seems to have latency between file load/play.
I've tried pre-loading three MediaPlayers so the load function is done prior to the play and still it seems to delay.
If SoundPool had a completed event, I believe it would be perfect!...alas, it doen't.
Brief summary, I'm trying to create sentences (audio) where the user can substitute values within the text; create audio segments for the beginning of the sentence, the substituted value and the ending of the sentence. (there may be more segments than three)
Then I want to be able to play each segment without any delays between audio segments.
Thanks for all your valuable suggestions. Any ideas are welcome :)
Rusty
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
In which case I suggest you try using SoundPool, manage the durations within the app, set a list of sounds and durations (maybe a type structure), change the timer interval to match the playing sound and play the next sound in the timer_tick sub.
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
Just found out something else interesting, it appears if you set Maxstreams to 1 and then set the priority in descending order, it creates a queue, and plays the sounds one after the other.

I learn something new every day too!

If that again introduces too much latency then the timer is the way to go as you can adjust that as you need with multiple streams.

BTW, the While,Loops just ensure that the sounds have time to load as they are pre-loaded and may not play if they haven't finished loading.
 

Attachments

  • sptest.zip
    88.5 KB · Views: 187
Last edited:
Upvote 0

Rusty

Well-Known Member
Licensed User
Longtime User
Thanks!
I think this might work.
I tried it yesterday, but it "cancelled" all lower priority sounds.
I didn't try putting it into a While loop...didn't realize that the play would return a value :)
Good thinking and thanks very much.
Rusty
 
Upvote 0

Rusty

Well-Known Member
Licensed User
Longtime User
Yes, but what I'd failed to do is to put it into a while loop. When the first file is playing, without the loop, all other lower priority files get cancelled.
Works great!
Thanks so much.
Rusty
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
The loop only needs to be done the first time you play the sound, in case it hasn't finished loading.

Subsequent plays don't need it. I've considered playing all loaded sounds that way with a volume of 0 so they don't actually play. But force the app to wait until they are definitely loaded.

If it causes an app has stopped error, a doevents between each one should sort it out.

-------------------
Sent via Tapatalk
 
Upvote 0
Top