Board index » delphi » Combining multiple WAV files into one

Combining multiple WAV files into one


2003-12-30 08:32:13 AM
delphi262
Hello all,
Does anyone have a snippet of code in Delphi to combine multiple WAV files
into one? I am writing a very simple TTS (text-to-speech) application for
Chinese pronounciation. I have all the wave files needed to synthesize
Chinese pronounciation (506 files in all). Now, all I need to do is the
ability to create one wave file based on a list of multiple wave files.
For example, in this sentence
wo3 zui4 xi3 huan1 wo3 de ming2 zi
Here, I'd generate a list containing the items:
wo3.wav
zui4.wav
xi3.wav
huan1.wav
wo3.wav
de.wav
ming2.wav
zi.wav
Then, combine these wave files in the order specified to create one wave
file.
Thanks in advance,
Aaron
 
 

Re:Combining multiple WAV files into one

take a look at:
www.delphiarea.com/products/waveaudio/
i guess you can do that with such classes, the main issue would be to concat
the waves to each other (which is easy) and update the internal fields inside
the master wave file to reflect the size changes.
let me know if you managed or not.
--
Liran
www.com-n-sense.com
 

Re:Combining multiple WAV files into one

Well, I thought it would be a simple matter, and was hoping that I'd not
need any third-party components. I envisioned a quick snippet of code that
could do this (the WAV files are going to be of the same frequency, bitrate,
etc...).
Any other suggestions?
Aaron
 

Re:Combining multiple WAV files into one

Quote
I envisioned a quick snippet of code that could do this (the
WAV files are going to be of the same frequency, bitrate,
etc...).
Are you only dealing with 1 or 2 formats or does it have to
support all wave formats?
-Mike
 

Re:Combining multiple WAV files into one

I am only dealing with one format. Namely, PCM 11.025kHz, 8bit, Mono WAVE
files.
Thanks for your help,
Aaron
 

Re:Combining multiple WAV files into one

"Aaron Chan" <XXXX@XXXXX.COM>writes
Quote
I am only dealing with one format. Namely, PCM 11.025kHz, 8bit, Mono
WAVE
files.

Thanks for your help,
Aaron
Search back through these newsgroups. I posted code to show how to
concatenate two wave files of the same characterisitics but different
duration.
David
 

Re:Combining multiple WAV files into one

Quote
I am only dealing with one format. Namely, PCM 11.025kHz, 8bit, Mono WAVE
files.
Here's a quick way of doing what I think you want.
-Mike
procedure JoinWaves(FileList: TStrings; OutputFile: string);
// This procedure will only work with
// 11.025Khz, 8 bit mono linear PCM wave files
var
Header: string;
I: Integer;
FileSize: LongInt;
InStream, OutStream: TFileStream;
begin
OutStream := TFileStream.Create(OutputFile, fmCreate);
try
Header := 'RIFF'#0#0#0#0'WAVEfmt '
+ #$10#0#0#0#1#0#1#0#$11#$2B#0#0#$11#$2B#0#0
+ #1#0#8#0'data'#0#0#0#0;
OutStream.WriteBuffer(Header[1], Length(Header));
for I := 0 to FileList.Count -1 do
if FileExists(FileList[I]) then
begin
InStream := TFileStream.Create(FileList[I], fmOpenRead);
try
if InStream.Size>44 then
begin
InStream.Position := 44;
OutStream.CopyFrom(InStream, InStream.Size - 44);
end;
finally
InStream.Free;
end;
end;
OutStream.Position := 4;
FileSize := OutStream.Size - 8;
OutStream.WriteBuffer(FileSize, SizeOf(FileSize));
OutStream.Position := 40;
FileSize := OutStream.Size - 44;
OutStream.WriteBuffer(FileSize, SizeOf(FileSize));
finally
OutStream.Free;
end;
end;
 

Re:Combining multiple WAV files into one

Thank you so much! I will try this code out ASAP.
Aaron
 

Re:Combining multiple WAV files into one

Yes, I usually do search through the newsgroups before posting new
questions. However, I was not able to find a satisfactory thread (I use
Google Groups to do searches).
Anyway, perhaps you can post a link to the thread you are referring to?
Thank you,
Aaron
 

Re:Combining multiple WAV files into one

OK, I have tested it and it is exactly what I am looking for!
Thanks!
Aaron
 

Re:Combining multiple WAV files into one

Quote
OK, I have tested it and it is exactly what I am looking for!
I just thought of an improvement. This one should work with
any PCM format as long as all files are the same format.
-Mike
procedure JoinWaves(FileList: TStrings; OutputFile: string);
// All files must be of the same format
var
I: Integer;
FileSize: LongInt;
InStream, OutStream: TFileStream;
begin
OutStream := TFileStream.Create(OutputFile, fmCreate);
try
for I := 0 to FileList.Count -1 do
if FileExists(FileList[I]) then
begin
InStream := TFileStream.Create(FileList[I], fmOpenRead);
try
if I = 0 then
OutStream.CopyFrom(InStream, InStream.Size)
else if InStream.Size>44 then
begin
InStream.Position := 44;
OutStream.CopyFrom(InStream, InStream.Size - 44);
end;
finally
InStream.Free;
end;
end;
OutStream.Position := 4;
FileSize := OutStream.Size - 8;
OutStream.WriteBuffer(FileSize, SizeOf(FileSize));
OutStream.Position := 40;
FileSize := OutStream.Size - 44;
OutStream.WriteBuffer(FileSize, SizeOf(FileSize));
finally
OutStream.Free;
end;
end;
 

Re:Combining multiple WAV files into one

Super!!! that is even better. Thanks for everything.
 

Re:Combining multiple WAV files into one

Quote
Yes, I usually do search through the newsgroups before posting new
questions. However, I was not able to find a satisfactory thread (I use
Google Groups to do searches).

Anyway, perhaps you can post a link to the thread you are referring to?

Thank you,
Aaron
My solution was essentially the same as Mike's, but doing everything in
memory.
Cheers,
David