Merge Mp3 files to be one file (Thai TTS)

Theera

Expert
Licensed User
Longtime User
Hi all,
Is there the library which automatically merge mp3 files to be one file as same as the mergemp3.exe. I have already test about mergemp3.exe with Thaiwords. I think that is the correctest Thai 's pronounciation. I have already test Thai 's pronounciation with tone marks that isn't work.

Best Regards
Theera
 
Last edited:

warwound

Expert
Licensed User
Longtime User
I'm pretty sure there's no existing library that can join MP3s - but do check that yourself please.

You might find it easier/possible to decode your MP3s to WAV format (uncompressed), then join the WAVs and finally re-encode back to MP3.

Are all of the MP3s to join encoded the same - are they all encoded with the same bitrate, number of channels and sampling frequency?
If not then the task gets more complicated - it's easier to join MP3 and WAV files that have the same number of channels and sampling frequency (and bitrate if we're joining MP3s).

Is this a TTS app where you have numerous MP3 (word) files and you need to join them to create complete sentences?
Decoding a small number of such word MP3s to WAV and then joining the WAVs then playing the combined WAV with AudioTrack is i think possible with the currently available libraries.
That has the advantage of not having to encode the combined WAV file to MP3 to play it back.

Have a look at liblame, test it on a handful of your MP3s - does it successfully decode them to WAV?

Martin.
 
Upvote 0

Theera

Expert
Licensed User
Longtime User
Please give the example about join wav files

Hi Martin,
Thank you for response. I'm not sure that I understand all of your words.
I understand that you need me change mp3 files to wav files the first time.
and then convert be mp3 again. I need to know that How to join wav files.
The your library could join them ? and The wav files is bigger than android device's memory?

Best Regards
Theera
 
Upvote 0

warwound

Expert
Licensed User
Longtime User
Hi there Theera.

Take a look at this page: https://ccrma.stanford.edu/courses/422/projects/WaveFormat/.

A WAV file consists of 44 bytes of 'header' data that describe the audio data, then bytes 45 onwards are the actual audio data.

So in theory you could use InputStreams and OutputStreams to combine all audio data from more than 1 WAV file into a single new file.
BUT the new file would just be a large collection of bytes, without a WAV header (the 44 bytes mentioned above) the new file would not actually be a WAV file.

If your plan is to play the combined audio data using AudioTrack then that is not a problem - you'd pass all the combined audio data bytes to AudioTrack and it would play, there'd be no need to create a true WAV file with the WAV header information.

If however you plan to save the combined audio data as a WAV (for example you'd need a WAV file to encode it to MP3) then you need some way to create a WAV file with the correct header data...
libwave could probably do that for you.
It's a java/android library which i have already partly converted to a B4A library when i created the B4A liblame library.
It wouldn't take me much time to finish off the B4A libwave library but i won't do so unless it is required - i have other things to spend my time on that have higher priority.

In fact rather than using the existing B4A liblame library and then requiring the libwave library, it might be better for your project to take the liblame libary and create new methods to do exactly as you require.
Imagine a single new liblame method that accepts an array of input filenames (the MP3s to decode and join) and an output filename.
The new method would decode each MP3 adding the decoded audio bytes of each decoded MP3 to a ByteArrayOutputStream.
Once all MP3s have been decoded the new method would have all the combined audio data available in the ByteArrayOutputStream.
So the method could return a Byte array, create a WAV file (with correct header) from the decoded bytes or even encode the combined decoded bytes back to an MP3.

The big advantage of creating a new method to do exactly as your app requires is that it will much better handle large amounts of audio data and make 'out of memory' problems less likely to occur.

Have a read of what i have written and if you can give me a better idea of what you require i'll see what i can do.
One thing though is to make sure that the MP3s that you are using can actually be decoded by the liblame decoder, if you read the liblame thread you'll see that it doesn't always successfully decode all MP3s.
It all depends on how the MP3 has been encoded - bitrate, sample rate and number of channels.
So if you have time to grab the liblame demo project and try to decode some of your Mp3s then post with your results then we'll know whether liblame is of any use here.

Martin.
 
Upvote 0
Top