录音

来源:互联网 发布:拓普网络股份有限公司 编辑:程序博客网 时间:2024/04/27 19:57
导读:

  [转]老妖的代码:

  C/C++ code

  用MediaPlay录音

  //---------------------------------------------------------------------------

  void __fastcall CreateWav(WORD wChannels, WORD wResolution, long lRate, String strFileName)

  {

  typedef struct _TWavHeader

  {

  long rId;

  long rLen;

  long wId;

  long fId;

  long fLen;

  WORD wFormatTag;

  WORD nChannels;

  long nSamplesPerSec;

  long nAvgBytesPerSec;

  WORD nBlockAlign;

  WORD wBitsPerSample;

  long dId;

  long wSampleLength;

  }TWavHeader;

  

  TWavHeader wh;

  wh.rId = 0x46464952;

  wh.rLen = 36;

  wh.wId = 0x45564157;

  wh.fId = 0x20746d66;

  wh.fLen = 16;

  wh.wFormatTag = 1;

  wh.nChannels = wChannels;

  wh.nSamplesPerSec = lRate;

  wh.nAvgBytesPerSec = wChannels * lRate * (wResolution / 8);

  wh.nBlockAlign = wChannels * (wResolution / 8);

  wh.wBitsPerSample = wResolution;

  wh.dId = 0x61746164;

  wh.wSampleLength = 0;

  int nHandle = FileCreate(strFileName);

  FileSeek(nHandle, 0, 0);

  FileWrite(nHandle, &wh, sizeof(wh));

  FileClose(nHandle);

  }

  //---------------------------------------------------------------------------

  void __fastcall TForm1::btnStartClick(TObject *Sender)

  {

  // 开始录音

  MediaPlayer1->DeviceType = dtAutoSelect;

  CreateWav(2, 16, 44100, "C://Test.wav");

  MediaPlayer1->FileName = "C://Test.wav";

  MediaPlayer1->Open();

  MediaPlayer1->StartRecording();

  }

  //---------------------------------------------------------------------------

  void __fastcall TForm1::btnEndClick(TObject *Sender)

  {

  // 结束录音

  MediaPlayer1->Stop();

  MediaPlayer1->Save();

  MediaPlayer1->Close();

  }

  //---------------------------------------------------------------------------



本文转自

http://soa.5d6d.com/redirect.php?fid=11&tid=38&goto=nextnewset
原创粉丝点击