首页 > 代码库 > c#语音报时(含完整的声音资源文件).rar

c#语音报时(含完整的声音资源文件).rar

 

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
private void btnBaoshi_Click(object sender, EventArgs e)
{
    try
    {
        System.Threading.Thread thread = new System.Threading.Thread(new System.Threading.ThreadStart(PlayTime));
        thread.Start();
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.Message);
    }
}
 
private static void PlayTime()
{
    System.Media.SoundPlayer sndPlayer;
 
    string sound = @"VoiceTime\TIMENOW.wav";
    sndPlayer = new System.Media.SoundPlayer(sound);
    sndPlayer.PlaySync();
 
    if (DateTime.Now.Hour >= 0 && DateTime.Now.Hour < 6)
        sound = @"VoiceTime\AM0.wav";
    else if (DateTime.Now.Hour >= 6 && DateTime.Now.Hour < 12)
        sound = @"VoiceTime\AM1.wav";
    else if (DateTime.Now.Hour >= 12 && DateTime.Now.Hour < 18)
        sound = @"VoiceTime\PM.wav";
    else
        sound = @"VoiceTime\EM.wav";
    sndPlayer = new System.Media.SoundPlayer(sound);
    sndPlayer.PlaySync();
 
    int hours = DateTime.Now.Hour;
 
    if (hours > 12)
        hours = hours - 12;
 
    if (hours < 10)
        sound = @"VoiceTime\T0" + hours + ".wav";
    else
        sound = @"VoiceTime\T" + hours + ".wav";
 
    sndPlayer = new System.Media.SoundPlayer(sound);
    sndPlayer.PlaySync();
 
    sound = @"VoiceTime\POINT.wav";
    sndPlayer = new System.Media.SoundPlayer(sound);
    sndPlayer.PlaySync();
 
    int min = DateTime.Now.Minute;
    if (min >= 0 && min < 10)
        sound = @"VoiceTime\T00.wav";
    else if (min >= 10 && min < 20)
        sound = @"VoiceTime\T10.wav";
    else if (min >= 20 && min < 30)
        sound = @"VoiceTime\T20.wav";
    else if (min >= 30 && min < 40)
        sound = @"VoiceTime\T30.wav";
    else if (min >= 40 && min < 50)
        sound = @"VoiceTime\T40.wav";
    else if (min >= 50 && min < 60)
        sound = @"VoiceTime\T50.wav";
    sndPlayer = new System.Media.SoundPlayer(sound);
    sndPlayer.PlaySync();
 
    min = min % 10;
    if (min != 0)
    {
        sound = @"VoiceTime\T0" + min + ".wav";
        sndPlayer = new System.Media.SoundPlayer(sound);
        sndPlayer.PlaySync();
    }
 
    sound = @"VoiceTime\MIN.wav";
    sndPlayer = new System.Media.SoundPlayer(sound);
    sndPlayer.PlaySync();
 
    if (sndPlayer != null)
    {
        sndPlayer.Dispose();
        sndPlayer = null;
    }
}

  

c#语音报时(含完整的声音资源文件).rar