C++ Builder XE 用sndPlaySound写的简单的语音播报算法
admin
2024-02-03 19:13:25

void __fastcall TForm2::N6Click(TObject *Sender)
{
//语音报时
// char   *wav_handle   ;
//HRSRC  h =FindResource(HInstance, "Resource_1", "RCData");
//HGLOBAL  h1=LoadResource(HInstance,h);
//wav_handle = (char   *)LockResource(h1);
//sndPlaySound(wav_handle,   SND_MEMORY   |   SND_SYNC);
AnsiString SoftStr= ExtractFilePath(Application->ExeName);
AnsiString Wstr=SoftStr +"res\\VoiceTime\\TIMENOW.wav";
//sndPlaySound(wav_handle,   SND_MEMORY   |   SND_SYNC);
sndPlaySound(Wstr.c_str() ,SND_ASYNC);
Sleep(2000);   //延时1秒
//
TDateTime dt = Now();
unsigned short hour,min, sec, msec;
//dt.DecodeTime(

dt.DecodeTime(&hour, &min,&sec,&msec);
if(hour>=0 && hour <=5)
{ //凌晨
 Wstr= SoftStr +"res\\VoiceTime\\AM0.wav";
 sndPlaySound(Wstr.c_str() ,SND_ASYNC);
 Sleep(800);   //延时1秒
 //点
 Wstr= SoftStr +"res\\VoiceTime\\T"+AnsiString().sprintf("%02d",hour) +".wav";
 sndPlaySound(Wstr.c_str() ,SND_ASYNC);
 Sleep(800);   //延时1秒
}
else if(hour >5 && hour<=12)
{ //上午
 Wstr= SoftStr +"res\\VoiceTime\\AM1.wav";
 sndPlaySound(Wstr.c_str() ,SND_ASYNC);
 Sleep(800);   //延时1秒
 //点
 Wstr= SoftStr +"res\\VoiceTime\\T"+AnsiString().sprintf("%02d",hour) +".wav";
 sndPlaySound(Wstr.c_str() ,SND_ASYNC);
 Sleep(800);   //延时1秒
}
else if(hour>12)
{   //下午
    Wstr= SoftStr +"res\\VoiceTime\\PM.wav";
    sndPlaySound(Wstr.c_str() ,SND_ASYNC);
    Sleep(800);   //延时1秒
    //点
    Wstr= SoftStr +"res\\VoiceTime\\T"+AnsiString().sprintf("%02d",hour-12) +".wav";
    sndPlaySound(Wstr.c_str() ,SND_ASYNC);
    Sleep(800);   //延时1秒
}
else
{ //晚上
    Wstr= SoftStr +"res\\VoiceTime\\EM.wav";
    sndPlaySound(Wstr.c_str() ,SND_ASYNC);
    Sleep(800);   //延时1秒
   //点
    Wstr= SoftStr +"res\\VoiceTime\\T"+AnsiString().sprintf("%02d",hour-12) +".wav";
    sndPlaySound(Wstr.c_str() ,SND_ASYNC);
    Sleep(800);   //延时1秒
}
//点
    Wstr= SoftStr +"res\\VoiceTime\\POINT.wav";
    sndPlaySound(Wstr.c_str() ,SND_ASYNC);
    Sleep(800);   //延时1秒
   //分
   if(min/10>0)
   {
    Wstr= SoftStr +"res\\VoiceTime\\T"+AnsiString().sprintf("%02d",min/10*10) +".wav";
    sndPlaySound(Wstr.c_str() ,SND_ASYNC);
    Sleep(800);   //延时1秒
    Wstr= SoftStr +"res\\VoiceTime\\T"+AnsiString().sprintf("%02d",min%10) +".wav";
    sndPlaySound(Wstr.c_str() ,SND_ASYNC);
    Sleep(800);   //延时1秒
   }
   else
   {
    Wstr= SoftStr +"res\\VoiceTime\\T"+AnsiString().sprintf("%02d",min) +".wav";
    sndPlaySound(Wstr.c_str() ,SND_ASYNC);
    Sleep(800);   //延时1秒
   }
    Wstr= SoftStr +"res\\VoiceTime\\Min.wav";
    sndPlaySound(Wstr.c_str() ,SND_ASYNC);
    Sleep(800);   //延时1秒
   //秒
//    Wstr= SoftStr +"res\\VoiceTime\\T"+AnsiString().sprintf("%02d",sec) +".wav";
//    sndPlaySound(Wstr.c_str() ,SND_ASYNC);
//    Sleep(1000);   //延时1秒
//    Wstr= SoftStr +"res\\VoiceTime\\Min.wav";
//    sndPlaySound(Wstr.c_str() ,SND_ASYNC);
//    Sleep(1000);   //延时1秒
}

相关内容

热门资讯

随笔|我把芫荽炒成菜 文|臧彦钧 馋人多半喜欢自己下厨。除了自己动手不用求人外,更多的是能在烹饪过程中自由发挥,抛开前人的...
4分钱的壳配3毛钱的肉?不少成... 对于热爱美食的当地人来说 在夜市或者美食街 都看到过这种“流量食物” ——蒜蓉粉丝烤扇贝 而且价格还...
全国首个以宋词为核心主题的演艺... 齐鲁晚报·齐鲁壹点 张浩穿越回李清照的时代与其展开时空对话,化身为玩家体验真实宋代生活……近日,在济...
“全球文旅轻创业计划”在京发布... 2025年11月17日上午,“银发文旅项目发布会暨全球文旅轻创业计划启动仪式”在中国传媒大学成功举办...
城事|办理口岸过百,台湾“首来... 据央视新闻消息,19日,国台办举行例行发布会,大陆持续释放旅游福利,首次来大陆的台胞“首来族”可获得...