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秒
}

相关内容

热门资讯

上海旅游节大巡游花车阵容抢先看... 2026上海旅游节大巡游9月12日外滩启幕,21辆全新主题花车携手21支境内外表演方队联袂登场,邀你...
原创 8... 上周门诊来了位 62 岁的张阿姨,得糖尿病快五年了,平时管嘴特别严,糖果、点心、甜饮料一概不碰,连水...
原创 餐... 2026年9月8日晚,南京浦口区泰冯路29号,墨语江南·阿婆菜餐厅户外帐篷里,灯火温润,其间还天降喜...
原创 它... 人到中年肝肾精血慢慢耗损,容易腰膝酸软、头晕眼花、精神疲惫。黄精性平,擅长补肝肾、益精血,搭配不同食...
同样卖奶茶,为何古茗赚了15亿... 出品/联商专栏 撰文/老刀 编辑/蔡建桢 今年上半年,蜜雪、古茗、霸王茶姬、茶百道、沪上阿姨全部盈利...