在Delphi中进行录音/保存 [英] Voice Recording/Saving in Delphi

查看:239
本文介绍了在Delphi中进行录音/保存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否存在允许以下操作的组件或代码: 记录一个或多个口语单词并将其保存到可以播放的文件中. 该文件必须能够在XP,Vista和Windows 7上播放. 该文件可以是独立文件,也可以保存到数据源.

Is there a component or code that allows the following: Record a spoken word (or words) and save it/them to a file that can be played back. The file must be able to be played back on XP, Vista and Windows 7. The file can be either stand alone or saved to a datasource.

[使用Delphi 7在XP上创建应用程序并使用Absolute Database.]

[Using Delphi 7 for creating apps on XP and using Absolute Database.]

推荐答案

通过MMSystem.pas中的函数,您可以使用Windows API进行此操作.您可以使用诸如 MCI函数 PlaySound 或低级别诸如 waveInOpen

The functions in MMSystem.pas let you do this using Windows API. You can either use high-level functions such as the MCI functions and PlaySound, or low-level functions such as waveInOpen, waveInPrepareHeader, waveInProc etc.

如果您想要高级控制,则实际上应该使用低级功能.除了PlaySound之外,我从未使用过高级MCI界面.

If you want high control, you really should use the low-level functions. Except for PlaySound, I have never used the high-level MCI interface.

这是工作代码:

procedure TForm1.FormCreate(Sender: TObject);
var
  op: TMCI_Open_Parms;
  rp: TMCI_Record_Parms;
  sp: TMCI_SaveParms;
begin

  // Open
  op.lpstrDeviceType := 'waveaudio';
  op.lpstrElementName := '';
  if mciSendCommand(0, MCI_OPEN, MCI_OPEN_ELEMENT or MCI_OPEN_TYPE, cardinal(@op)) <> 0 then
    raise Exception.Create('MCI error');

  try

    // Record
    rp.dwFrom := 0;
    rp.dwTo := 5000; // 5000 ms = 5 sec
    rp.dwCallback := 0;
    if mciSendCommand(op.wDeviceID, MCI_RECORD, MCI_TO or MCI_WAIT, cardinal(@rp)) <> 0 then
      raise Exception.Create('MCI error. No microphone connected to the computer?');

    // Save
    sp.lpfilename := PChar(ExtractFilePath(Application.ExeName) + 'test.wav');
    if mciSendCommand(op.wDeviceID, MCI_SAVE, MCI_SAVE_FILE or MCI_WAIT, cardinal(@sp)) <> 0 then
      raise Exception.Create('MCI error');

  finally
    mciSendCommand(op.wDeviceID, MCI_CLOSE, 0, 0);
  end;

end;

这篇关于在Delphi中进行录音/保存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆