⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 unit1.pas

📁 sour code delpi, sound rec
💻 PAS
字号:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, mmSystem, ExtCtrls, StdCtrls;

  {Dont forget about putting mmSystem in
   the uses when you make your own prog}

type
  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    Label1: TLabel;
    Label2: TLabel;
    Timer1: TTimer;
    Label3: TLabel;
    Label4: TLabel;
    Button4: TButton;
    SaveDialog1: TSaveDialog;
    Label5: TLabel;
    Memo1: TMemo;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
    procedure Button4Click(Sender: TObject);

  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

    // Record
    procedure TForm1.Button1Click(Sender: TObject);
    begin

    Label2.Caption:='0';                     //Sets label2 to 0 duh


    Timer1.Enabled:=true;                    //Turns timer1 on so you know
                                             //how long you'v been recording


    Label1.Caption:='Rocording started';    //Changes label1 so you know
                                            //its recording ;)
                                            

    mciSendString('OPEN NEW TYPE WAVEAUDIO ALIAS MicSound', nil, 0, Handle);

    // MicSound is what the WaveAudio is asigned to.
    // It is used in all the mciSendString so if you
    // rename it to a diffrent name then you need to
    // make sure you change it on all of them.
    // If you dont know what I just said..
    // hell I dont think I know what i just said
    // then leave it the way it is, it will work ether way.
    
    // The Following is pritty much self explanatory but I put
    // the Notes out for those who dont follow.

    mciSendString('SET MicSound TIME FORMAT MS ' +      // set the time format

        'BITSPERSAMPLE 8 ' +                            // 8 Bit
        'CHANNELS 1 ' +                                 // MONO
        'SAMPLESPERSEC 8000 ' +                         // 8 KHz
        'BYTESPERSEC 8000',                             // 8000 Bytes/s
        nil, 0, Handle);

    mciSendString('RECORD MicSound', nil, 0, Handle);
    end;


    // Stop Record
    procedure TForm1.Button2Click(Sender: TObject);
    begin
    Timer1.Enabled:=false;   //Stops the timer
    
    mciSendString('STOP MicSound', nil, 0, Handle);

    end;


    // Save Wave File
    procedure TForm1.Button3Click(Sender: TObject);
    begin

    mciSendString(PChar('SAVE MicSound ' + 'C:\FileName.wav'), nil, 0, Handle);

    mciSendString('CLOSE MicSound', nil, 0, Handle);

    Label1.Caption:='Wave file saved to C:\FileName.wav'; //Lets you know its saved :P

    end;


procedure TForm1.Timer1Timer(Sender: TObject);
Var
p1 : integer;

begin
p1:=strtoint(label2.caption);          //Sets P1 to what ever label2 is

label2.Caption:= inttostr(p1 + 1);     //Adds one to P1... to easy.
end;

procedure TForm1.Button4Click(Sender: TObject);
begin
 if SaveDialog1.Execute then

    mciSendString(PChar('SAVE MicSound ' + SaveDialog1.filename), nil, 0, Handle);

    mciSendString('CLOSE MicSound', nil, 0, Handle);

    Label1.Caption:='Wave file saved to ' + SaveDialog1.filename; //Lets you know its saved :P


end;



end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -