uses ComObj, SpeechLib_TLB,Activex;procedure TextToWav(Atext: string; AFieldName: string);
varSpFileStream1: TSpFileStream;SpVoice1: TSpVoice;ShengYinXuHao: integer;
begin// 声音序号 0为中文,1为英文ShengYinXuHao := 1;if ShengYinXuHao <> 1 thenShengYinXuHao := 0;//SpVoice1 := TSpVoice.Create(nil);SpFileStream1 := TSpFileStream.Create(nil);trySpVoice1.Voice := SpVoice1.GetVoices('', '').item(ShengYinXuHao);// SpVoice1.Volume := 30; //音量 0到100// SpVoice1.Rate := 0; // 读速 -5到5之间SpFileStream1.Format.type_ := SAFT8kHz8BitStereo; // SAFT8kHz8BitMono;SpFileStream1.Open(AFieldName, SSFMCreateForWrite, false); // + '.wav';SpVoice1.AudioOutputStream := SpFileStream1.DefaultInterface;SpVoice1.Speak(Atext, SVSFlagsAsync);SpVoice1.WaitUntilDone(-1);SpFileStream1.Close;finallyif SpVoice1 <> nil thenSpVoice1.Free;if SpFileStream1 <> nil thenSpFileStream1.Free;end;
end;//使用方法:sPath := ExtractFilePath(ParamStr(0));trycoinitialize(nil);TextToWav('begin', sPath + 'mp3\av.wav');finallycouninitialize;end;