Transferred from: http://blog.csdn.net/yunqian09/article/details/5554527
My way to add a timer to set the interval 100ms, through the timer to enable, control alarm sound switch
Procedure Tform1.timer1timer (Sender:tobject);
Begin
Windows.beep (1200+i_f,10+i_f);
If i_f<2000 Then
Begin
Inc (I_F);
End
End
===============================================
Delphi defines the Beep method in the Sysutils unit, which can emit a sound that is typically used for reminders and debugging.
Beep is actually called the API function: MessageBeep (MB_OK);
MessageBeep can invoke several different sound files in the following ways:
MessageBeep (MB_OK); MessageBeep (Mb_iconhand); MessageBeep (mb_iconquestion); {This doesn't ring, don't know why} MessageBeep (mb_iconexclamation); MessageBeep (Mb_iconasterisk); MessageBeep ($FFFFFFFF); {with messagebeep (MB_OK);}
Beep is also an API function that can specify the height and length of the sound; Because it has the same name as Sysutils.beep, this should be called:
Windows.beep (pitch, length);
For example: Windows.beep (440, 2000); will play an international standard tone (440HZ) for 2 seconds.
In addition, the value range of the first parameter is: $-$7ffff.
Audio meter in http://www.cnblogs.com/del/archive/2008/10/22/1316380.html
The following program will play the first sentence of the < Olympic theme song >:
Unit unit1;interfaceuses Windows, Messages, sysutils, variants, Classes, Graphics, Controls, Forms, Dialogs, stdctr Ls;type TForm1 = Class (Tform) Button1:tbutton; Procedure Button1Click (Sender:tobject); End;var form1:tform1;implementation{$R *.dfm}procedure tform1.button1click (sender:tobject); const T = 800;begin Window S.beep (n, t); Windows.beep (392, T); Windows.beep (262, t*2); Windows.beep (294, T); Windows.beep (n, t); Windows.beep (196, t*2); Windows.beep (262, T); Windows.beep (294, T); Windows.beep (n, t); Windows.beep (392, T); Windows.beep (294, t*4); end;end.
var
I:integer;
Begin
For I: = 0 To
Windows.beep (+ I, + i);
End
The form is not able to do anything when the machine makes a sound
=====================================
If you want to play a basic system sound, call MessageBeep with the appropriate parameters. If you want to speak with the speaker, call MessageBeep (-1);.
To play a WAV sound, you can use the object Tmediaplayer, but if you want to play it quickly, the simplest way is to call the API function sndPlaySound (declared in the MMSystem unit).
For example:
Procedure Tform1.button1click (Sender:tobject);
Begin
sndPlaySound (' C:/windows/media/tada.wav ',
Snd_nodefault or Snd_async or snd_loop);
End
Procedure Tform1.button2click (Sender:tobject);
Begin
sndPlaySound (nil, 0); Stop pronunciation
End
If you want to play a sound often, you should consider loading the file into memory and playing it from memory:
Var
tada:string;
Procedure Tform1.button1click (Sender:tobject);
Begin
sndPlaySound (Pointer (TADA), snd_memory
or Snd_nodefault or snd_async);
End
Initialization
Tada: = LoadFile (' c:/windows/media/tada.wav ');
Finalization
Tada: = '; Frees the memory that the string occupies.
End.
Delphi Alarm Sound Beep, MessageBeep and Windows.beep