tags:

views:

944

answers:

3

I have a library of different words/phrases, and in order to build sentences at present I add a combination of these phrases into a playlist to make a sentence. Unfortunately if the user is running cpu intensive applications (which most of my users are) there can be a lag of a few seconds mid-sentence (in between phrases).

In order to combat this I was thinking of an approach which will merge the right combination of mp3 files on the fly into an appropriate phrase, save this in the %temp% directory, and then play this 1 mp3 which should overcome the problem I'm experiencing with gaps.

What is the easiest way to do this in c#? Is there an easy way to do this? The files are fairly small, 3-4 seconds long each, and a sentence can consist of 3-20ish phrases.

+1  A: 

As MP3s are a compressed audio source, I imagine that you can't just concatenate them into a single file without decoding each one first to the wave form that it would play. This may be quite intensive. Perhaps you could cheat by using a critical section when playing back your phrase so that the CPU is not stolen from you until the phrase was complete. This isn't necessarily playing nice with other threads but might work if your phrases are short.

Jeff Yates
+1  A: 

MP3 files consist out of "frames", that each represent a short snippet (I think around 25ms) of audio.

So yes, you can just concatenate them without problem.

bart
I will mostly have control over which mp3 files are used, would there ever be a problem if different bit rates were used?
James
No problem if your audio player can handle VBR files, because that's exactly how VBR works.
bart
A: 

On simple option is to shell to the command line:

copy /b *.mp3 c:\new.mp3

Better would be to concatenate the streams. That's been answered here: http://stackoverflow.com/questions/444309/what-would-be-the-fastest-way-to-concatenate-three-files-in-c

Jon Galloway