请教-根据配置播放语音文件 ( 积分: 100 )

  • 主题发起人 主题发起人 mawei0913_green
  • 开始时间 开始时间
M

mawei0913_green

Unregistered / Unconfirmed
GUEST, unregistred user!
现有memo1,memo2,button1,Timer1,Mediaplayer1
现有配置文件: vocfile.txt,包括:cc
clcy
sfz
kw
jhkcsj
jhkctime
sjkcsj
sjkctime
wd
wdtime
文件:schadule.txt,包括:
T535|T535|北京|天津|10:20|10:20|0|无|00:10|10:30|10:20|中央|2007-01-05|0|0|2|0|
L809|L809|北京|昌平|10:25|10:25|0|无|00:15|10:40|10:25|中央|2007-01-05|0|0|2|0|
1301|1301|北京|满洲里|10:30|10:30|0|无|00:00|10:30|10:30|2候|2007-01-05|0|0|2|0|

procedure TForm1.BitBtn2Click(Sender: TObject);
var
SStringlist : TStringList;
i ,j,m: Integer;
STemp : String;
tmplist:Tstringlist;
str:string;
tmpstr: string;
begin
memo1.Clear;
gsystempath:=ExtractFilePath(Application.ExeName);
SStringlist := TStringList.Create;
SStringlist.LoadFromFile(gSystemPath + 'schadule.txt');
tmplist:=Tstringlist.Create;
tmplist.LoadFromFile(gsystempath+' vocfile.txt');
for j:=0 To SStringlist.Count -1 do
begin

str:=sstringlist[j];

memo1.Lines.Add('--->'+inttostr(j+1));
for i:=0 to tmplist.Count -1 do
begin
if trim(tmplist.Strings )='cc' then
begin
STemp :=f_spliterstring(SStringlist.Strings [j],1);
memo1.Lines.Add( stemp);
//tmpstr:=copy(str,1,2);
//getvoclist(getplaylist(str));
// playready;
// playvoc;
end;
if trim(tmplist.Strings )='clcy' then
begin
STemp :='次列车';
memo1.Lines.Add( stemp);


end;
if trim(tmplist.Strings )='sfz' then
begin
stemp:=f_spliterstring(SStringlist.Strings [j],3);
memo1.Lines.Add( stemp);
end;
if tmplist.Strings ='kw' then
begin
STemp :='开往';
memo1.Lines.Add(stemp);
end;
if tmplist.Strings ='zdz' then
begin
STemp :=f_spliterstring(SStringlist.Strings [j],4);
memo1.Lines.Add(stemp);
end;
if tmplist.Strings ='jhkcsj' then
begin
STemp :='计划到站时间';
memo1.Lines.Add(stemp);
end;
if tmplist.Strings ='jhkctime' then
begin
STemp :=f_spliterstring(SStringlist.Strings [j],6);
memo1.Lines.Add(stemp);

end;
if tmplist.Strings ='sjkcsj' then
begin
STemp :='实际到站时间';
memo1.Lines.Add(stemp);

end;
if tmplist.Strings ='sjkctime' then
begin
STemp :=f_spliterstring(SStringlist.Strings [j],11);
memo1.Lines.Add(stemp);

end;

if tmplist.Strings ='wd' then
begin
STemp :='晚点';
memo1.Lines.Add(stemp);

end;
if tmplist.Strings ='wdtime' then
begin
STemp :=f_spliterstring(SStringlist.Strings [j],9);
memo1.Lines.Add(stemp);

end;
{if tmplist.Strings ='gd' then
begin
STemp :='股道';
memo1.Lines.Add(stemp);

end;
if tmplist.Strings ='gdnum' then
begin
STemp :=f_spliterstring(SStringlist.Strings [j],7);
memo1.Lines.Add(stemp);
end;
if tmplist.Strings ='zt' then
begin
STemp :='站台';
memo1.Lines.Add(stemp);

end;
if tmplist.Strings ='ztnum' then
begin
STemp :=f_spliterstring(SStringlist.Strings [j],8);
memo1.Lines.Add(stemp);
end;}

end;
end;
end;
//分割字符串

function TForm1.f_spliterstring(InputData: string; CharNum: integer): string;
var OutputData:string;
Li_CharNum,Li_CharNum2:integer;
Li_Step,Li_Counter:integer;
begin
Li_counter:=1;
Li_CharNum:=1;
Li_CharNum:=PosEx('|',InputData,Li_CharNum); //在inputdata中查找'|'的起始位置
//DebugBreak; //是Win32函数,与在该位置设置一个断点具有相同的效果
if Li_CharNum=Null then
begin
OutputData:='NULL';
end;
//取出字符串
if CharNum=1 then
begin
OutputData:=MidBStr(InputData,1,Li_CharNum-1); //从inputdata的第一个字符开始取li_charnum-1个字符
end;
for Li_Step:=1 to CharNum do
begin
Li_Counter:=Li_Counter+1;
Li_CharNum:=Li_CharNum+1;
Li_CharNum2:=PosEx('|',InputData,Li_CharNum);
if (Li_CharNum2=Null) or (Li_CharNum2=0) then
begin
Li_CharNum2:=Length(InputData);
end;
if Li_Counter=CharNum then
begin
OutputData:=MidBStr(InputData,Li_CharNum,Li_CharNum2-Li_CharNum);
end;
Li_CharNum:=Li_CharNum2;
end;
Result:=OutputData;
end;
procedure TForm1.getnumlist(numstring: String);
var
ilong : Integer;
itemp : Integer;
begin
itemp := StrToInt(numstring);
ilong := Length(Trim(numstring));
case ilong of
1 :
begin
vocList[vocnum] := Trim(numstring);
vocnum := vocnum + 1;
end;
2 :
begin
if itemp = 10 then
begin
vocList[vocnum] := '十';
vocnum := vocnum + 1;
end
else if (itemp > 10) and (itemp < 20) then
begin
vocList[vocnum] := '十';
vocnum := vocnum + 1;
vocList[vocnum] := Copy(Trim(numstring),2,1);
vocnum := vocnum + 1;
end
else if (itemp = 20)
or (itemp = 30)
or (itemp = 40)
or (itemp = 50)
or (itemp = 60)
or (itemp = 70)
or (itemp = 80)
or (itemp = 90) then
begin
vocList[vocnum] := Copy(Trim(numstring),1,1);
vocnum := vocnum + 1;
vocList[vocnum] := '十';
vocnum := vocnum + 1;
end
else
begin
vocList[vocnum] := Copy(Trim(numstring),1,1);
vocnum := vocnum + 1;
vocList[vocnum] := '十';
vocnum := vocnum + 1;
vocList[vocnum] := Copy(Trim(numstring),2,1);
vocnum := vocnum + 1;
end;
end;
3 :
begin
if itemp = 100 then
begin
vocList[vocnum] := '1';
vocnum := vocnum + 1;
vocList[vocnum] := '百';
vocnum := vocnum + 1;
end
else if Copy(Trim(numstring),2,1) = '0' then
begin
vocList[vocnum] := Copy(Trim(numstring),1,1);
vocnum := vocnum + 1;
vocList[vocnum] := '百';
vocnum := vocnum + 1;
vocList[vocnum] := '0';
vocnum := vocnum + 1;
vocList[vocnum] := Copy(Trim(numstring),2,1);
vocnum := vocnum + 1;
end
else
begin
vocList[vocnum] := Copy(Trim(numstring),1,1);
vocnum := vocnum + 1;
vocList[vocnum] := '百';
vocnum := vocnum + 1;
vocList[vocnum] := Copy(Trim(numstring),2,1);
vocnum := vocnum + 1;
vocList[vocnum] := '十';
vocnum := vocnum + 1;
vocList[vocnum] := Copy(Trim(numstring),3,1);
vocnum := vocnum + 1;
end;
end;
4 :
begin

end;
5 :
begin

end;
6 :
begin

end;
7 :
begin

end;
8 :
begin

end;
9 :
begin

end;
end;
end;

procedure TForm1.getnumtimelist(numtimestring: String);
var
iLength : Integer;
numtime : Integer;
numhour : Integer;
numday : Integer;
begin
numhour := 0;
numday := 0;
numtime := StrToInt(numtimestring);
if numtime >= 60 then
begin
numhour := Round(numtime/60) -1;
numtime := numtime - numhour*60;
end;
if numhour >= 24 then
begin
numday := Round(numhour/24)-1;
numhour := numhour - numday*24;
end;
if numday <> 0 then
begin
getnumlist(IntToStr(numday));
vocList[vocnum] := '天';
vocnum := vocnum + 1;
end;
if numhour <> 0 then
begin
getnumlist(IntToStr(numhour));
vocList[vocnum] := '小时';
vocnum := vocnum + 1;
end;
if numtime <> 0 then
begin
getnumlist(IntToStr(numtime));
vocList[vocnum] := '分钟';
vocnum := vocnum + 1;
end;
end;

procedure TForm1.gettimelist(timestring: String);
begin
if Copy(Trim(timestring),1,1) = '0' then
begin
if Copy(Trim(timestring),2,1) = '0' then
begin
vocList[vocnum] := '0';
vocnum := vocnum + 1;
vocList[vocnum] := '点';
vocnum := vocnum + 1;
end
else
begin
vocList[vocnum] := Copy(Trim(timestring),2,1);
vocnum := vocnum + 1;
vocList[vocnum] := '点';
vocnum := vocnum + 1;
end;
end
else
begin
getnumlist(Copy(Trim(timestring),1,2));
vocList[vocnum] := '点';
vocnum := vocnum + 1;
end;
if Copy(Trim(timestring),4,2) = '00' then
Exit;
if Copy(Trim(timestring),4,1) = '0' then
begin
vocList[vocnum] := Copy(Trim(timestring),4,1);
vocnum := vocnum + 1;
vocList[vocnum] := '分';
vocnum := vocnum + 1;
end
else
begin
getnumlist(Copy(Trim(timestring),4,2));
vocList[vocnum] := '分';
vocnum := vocnum + 1;
end;
end;

procedure TForm1.getvoclist(vocstring: String);
var
i : Integer;
strtemp : String;
begin
strtemp := '';
for i := 1 to Length(Trim(vocstring)) do
begin
if Copy(Trim(vocstring),i,1) = '|' then
begin
if strtemp <> '' then
begin
if Copy(Trim(strtemp),1,1) = '!' then //num
getnumlist(Copy(Trim(strtemp),2,Length(strtemp)-1))
else if Copy(Trim(strtemp),1,1) = '%' then //time
gettimelist(Copy(Trim(strtemp),2,Length(strtemp)-1))
else if Copy(Trim(strtemp),1,1) = '^' then //fenzhong
getnumtimelist(Copy(Trim(strtemp),2,Length(strtemp)-1))
else
begin
vocnum := vocnum + 1;
voclist[vocnum-1] := strtemp;
end;
strtemp := '';
end;
end
else
begin
strtemp := strtemp + Copy(Trim(vocstring),i,1);
end;
end;
end;

procedure TForm1.playready;
var
i : Integer;
begin
for i := 0 to vocnum do
begin
if vocList = '' then
vocList := voclist[i+1];
end;
end;

procedure TForm1.playvoc;
begin
try
MediaPlayer1.FileName := gSystemPath + 'voc/'+ vocList[playnum] + '.wav';
Memo2.Lines.Add(MediaPlayer1.FileName);
MediaPlayer1.Open;
MediaPlayer1.Play;
Timer1.Enabled := True;
Except
Writeln(novoctext,FormatDateTime('yyyy-mm-dd hh:mm:ss ',Now)+vocList[playnum]);
playnum := playnum +1;
playvoc;
end;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
if playnum >= vocnum - 1 then
begin
Timer1.Enabled := False;
Memo2.Lines.Add(FormatDateTime('yyyy-mm-dd hh:mm:ss',Now)+'over');
Exit;
end;
if MediaPlayer1.Position >= MediaPlayer1.Length then
begin
playnum := playnum + 1;
Timer1.Enabled := False;
playvoc;
end;
end;
function TForm1.getplaylist(str1: String):String;
var
vocList1 : array [0..200] of String;
vocnum1 : Integer;
str : String;
i,ii : Integer;
strtemp : String;
itemp : Integer;
sr : String;
begin
sr := '';
vocnum1 := 0;
ii := 0;
str := str1;
for i := 1 to Length(str) do
begin
if Copy(str,i,1) = '|' then
begin
strtemp := Copy(str,i+1,Length(str)-i);
itemp := getnumofstring(strtemp)-1;
ii := ii + 1; //记录的 " | "
case ii of
0:
begin

end;
1:
begin
vocList1[vocnum1] := Copy(strtemp,1,itemp);
vocnum1 := vocnum1+1;
vocList1[vocnum1] := '次列车';
vocnum1 := vocnum1+1;
end;
2:
begin
vocList1[vocnum1] := Copy(strtemp,1,itemp);
vocnum1 := vocnum1+1;
vocList1[vocnum1] := '开往';
vocnum1 := vocnum1+1;
end;
3:
begin
vocList1[vocnum1] := Copy(strtemp,1,itemp);
vocnum1 := vocnum1+1;
vocList1[vocnum1] := '计划到站时间';
vocnum1 := vocnum1+1;
end;
4:
begin
vocList1[vocnum1] := '%'+Copy(strtemp,1,itemp);
vocnum1 := vocnum1+1;
vocList1[vocnum1] := '实际到站时间';
vocnum1 := vocnum1+1;
end;
5:
begin

end;
6:
begin

end;
7:
begin

end;
8:
begin
vocList1[vocnum1+1] := '晚点';
vocnum1 := vocnum1+1;
vocList1[vocnum1+1] := '^'+ gettime((Copy(strtemp,1,itemp)));
vocnum1 := vocnum1+1;
end;
9:
begin
vocList1[vocnum1-2] := '%'+Copy(strtemp,1,itemp);
vocnum1 := vocnum1+1;
end
else
begin
Break;
end;
end;
end;
end;
for i := 0 to vocnum1 do
begin
sr := sr + '|' +voclist1;
end;
result := sr+'|';
end;

function TForm1.getcheci(str1: String): String;
var
str : String;
begin
str := str1;
Result := Copy(str,1,Length(str)-Pos(str,'|'));
end;

function TForm1.getnumofstring(str1: String): Integer;
var
i : Integer;
begin
Result := 0;
for i := 1 to Length(str1) do
begin
if Copy(str1,i,1) = '|' then
begin
Result := i;
Exit;
end;
end;
end;

function TForm1.gettime(str1: String): String;
begin
Result := IntToStr(StrToInt(Copy(str1,1,2))*60 + StrToInt(Copy(str1,4,2)));
end;
请教,怎样根据vocfile.txt的内容,播放语音
如果vocfile.txt中有cc,则:再memo2中显示“F:/playvoc/playvoc/voc/T535.wav”
如果vocfile.txt中有clcy,则,在memo2中显示“F:/playvoc/playvoc/voc/次列车.wav”
。。。。
结果:如:
F:/playvoc/playvoc/voc/T535.wav
F:/playvoc/playvoc/voc/次列车.wav
F:/playvoc/playvoc/voc/北京.wav
F:/playvoc/playvoc/voc/开往.wav
F:/playvoc/playvoc/voc/天津.wav
F:/playvoc/playvoc/voc/计划到站时间.wav
F:/playvoc/playvoc/voc/十.wav
F:/playvoc/playvoc/voc/点.wav
F:/playvoc/playvoc/voc/2.wav
F:/playvoc/playvoc/voc/十.wav
F:/playvoc/playvoc/voc/分.wav
F:/playvoc/playvoc/voc/实际到站时间.wav
F:/playvoc/playvoc/voc/十.wav
F:/playvoc/playvoc/voc/点.wav
F:/playvoc/playvoc/voc/3.wav
F:/playvoc/playvoc/voc/十.wav
F:/playvoc/playvoc/voc/分.wav
F:/playvoc/playvoc/voc/晚点.wav
F:/playvoc/playvoc/voc/十.wav
F:/playvoc/playvoc/voc/分钟.wav

还请各位高人完善程序或者提供完整代码,谢谢!
 
要这么烦吗?要录多少音啊!

有没有听说过TTS,动态语音播报,想读什么就是什么。。。
 
此程序有点麻烦,本人希望能找到一个简单明了的程序,还请各位指教!
 
TTS是什么呀,我是DELPHI的初学者,对TTS并不了解,还请 黄耀彰 进行详细说明。

那位高人若有什么高见,也请给予指点说明,现在我紧需这个程序!谢谢了!
 
多人接受答案了。
 
后退
顶部