用Delphi随机产生60000个不重复的数字,然后用提供的0-9这十个个位数的声音,文件名分别是:0.wav,1.wav,..........,然后用产生的数字去组合声音。比如:58478,产生一个文件名为58478.wav的声音文件,而声音内容则只是单纯的58478这五个数就可以,就是用5.wav,8.wav,4.wav,7.wav,8.wav这些声音连接起来的,不用向日常生活中是:5万8千4百7十8这么读,请问可不可以???
调试欢乐多
下载 “微软TTS 语音朗读引擎” 试试看。
procedure TForm1.Button1Click(Sender: TObject);
(*
Path=输入1.wav 2.wav 的目录路径
FileStr=数字 521871
OutPath=输出合成后的目录
*)
function MakeWavFile(Path,FileStr,OutPath: string): Boolean;
type
TWavFormat = packed record
ChunkID: array[0..3] of Char; {'RIFF'}
ChunkSize: Longword; {size-8}
Format: array[0..3] of Char; {'WAVE'}
SubChunk1ID: array[0..3] of Char; {'fmt '}
SubChunk1Size: Longword; {hex10}
AudioFormat: Word; {hex 01}
NumOfChannels: Word; {1 mono, 2 stereo}
SampleRate: Longword; {number of samples/sec}
ByteRate: Longword; {samplerate* num of channels*bytes per (mono) sample}
BytesperSample: Word; {size of (mono) sample}
BitsPerSample: Word; {BytesperSample *8}
SubChunk2ID: array[0..3] of Char; {'data'}
SubChunk2Size: Longword; {number of data bytes}
end;
var
WavFormat: array of TWavFormat;
FileHandle:array of THandle;
FileName:array of string;
FileStream:array of TFileStream;
ChunkSize:array of Integer;
NewFormat:TWavFormat;
i:integer;
iCount:integer;
Run:Boolean;
begin
Result := False;
iCount:=Length(FileStr); SetLength(FileName,iCount);
for i := 1 to iCount do
begin
FileName[i-1]:=Path+FileStr[i]+'.wav';
if not FileExists(FileName[i-1]) then Exit;
end;
SetLength(WavFormat,iCount);
SetLength(FileHandle,iCount);
SetLength(FileStream,iCount);
SetLength(ChunkSize,iCount);
for i := 0 to iCount-1 do FileHandle[i] := _lopen(PAnsiChar(FileName[i]), OF_READ or OF_SHARE_DENY_NONE);
Run:=False;
for i := 0 to iCount - 1 do Run:=Run or (Integer(FileHandle[i]) <= 0);
if Run then
begin
for i := 0 to iCount - 1 do _lclose(FileHandle[i]);
Exit;
end;
for i := 0 to iCount - 1 do FileStream[i] := TFileStream.Create(FileHandle[i]);
try
for i := 0 to iCount - 1 do
if FileStream[i].Read(WavFormat[i], SizeOf(TWavFormat)) <> SizeOf(TWavFormat) then Exit;
if WavFormat[0].ChunkID <> 'RIFF' then Exit;
if WavFormat[0].SubChunk2ID <> 'data' then Exit;
for i := 0 to iCount - 1 do
begin
ChunkSize[i] := WavFormat[i].SubChunk2Size;
WavFormat[i].ChunkSize := 0;
WavFormat[i].SubChunk2Size := 0;
end;
Run:=True;
for i := 1 to iCount - 1 do Run:=Run or (CompareMem(@WavFormat[0], @WavFormat[i], SizeOf(TWavFormat)));{格式不同}
if Not Run then Exit;
with TMemoryStream.Create do
try
NewFormat:=WavFormat[0];
NewFormat.ChunkSize:=0;
NewFormat.SubChunk2Size := 0;
for i := 0 to iCount - 1 do
begin
NewFormat.ChunkSize := NewFormat.ChunkSize+ChunkSize[i];
NewFormat.SubChunk2Size := NewFormat.SubChunk2Size+ChunkSize[i];
end;
NewFormat.ChunkSize := NewFormat.ChunkSize + SizeOf(NewFormat) - 8;
Write(NewFormat, SizeOf(TWavFormat));
for i := 0 to iCount - 1 do
CopyFrom(FileStream[i], ChunkSize[i]);
try
SaveToFile(OutPath+FileStr+'.wav');
except
Exit;
end;
finally
Free;
end;
finally
for i := 0 to iCount - 1 do FileStream[i].Free;
end;
Result := True;
end;
begin
with TStringList.Create do
try
Randomize;
Clear; Sorted := True; Duplicates := dupIgnore;;
while Count<60000 do Add(Format('%.5d',[Random(99999)]));
for i := 0 to Count - 1 do
MakeWavFile('c:\',Strings[i],'c:\CSDNDemo\');
finally
Free;
end;
end;