Author: Lou Adler
Does anyone have a snippet of code in Delphi to combine multiple WAV files into
one? I am writing a very simple 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 is the ability to create one
wave file based on a list of multiple wave files which are in a specific order.
Answer:
This one should work with any PCM format as long as all files are the same format:
1 procedure JoinWaves(FileList: TStrings; OutputFile: string);
2 {All files must be of the same format}3 var4 I: Integer;
5 FileSize: LongInt;
6 InStream, OutStream: TFileStream;
7 begin8 OutStream := TFileStream.Create(OutputFile, fmCreate);
9 try10 for I := 0 to FileList.Count - 1 do11 if FileExists(FileList[I]) then12 begin13 InStream := TFileStream.Create(FileList[I], fmOpenRead);
14 try15 if I = 0 then16 OutStream.CopyFrom(InStream, InStream.Size)
17 elseif InStream.Size > 44 then18 begin19 InStream.Position := 44;
20 OutStream.CopyFrom(InStream, InStream.Size - 44);
21 end;
22 finally23 InStream.Free;
24 end;
25 end;
26 OutStream.Position := 4;
27 FileSize := OutStream.Size - 8;
28 OutStream.WriteBuffer(FileSize, SizeOf(FileSize));
29 OutStream.Position := 40;
30 FileSize := OutStream.Size - 44;
31 OutStream.WriteBuffer(FileSize, SizeOf(FileSize));
32 finally33 OutStream.Free;
34 end;
35 end;