这是我从VC代码转过来的,没有经过测试,不知道行不行。function recordWAVEFile(dwMilliSeconds: DWORD): DWORD;
var
wDeviceID: UINT;
dwReturn: DWORD;
mciOpenParms: MCI_OPEN_PARMS;
mciRecordParms: MCI_RECORD_PARMS;
mciSaveParms: MCI_SAVE_PARMS;
mciPlayParms: MCI_PLAY_PARMS;
begin
// Open a waveform-audio device with a new file for recording.
mciOpenParms.lpstrDeviceType := 'waveaudio';
mciOpenParms.lpstrElementName := '';
dwReturn := mciSendCommand(0, MCI_OPEN,
MCI_OPEN_ELEMENT or MCI_OPEN_TYPE,
DWORD(@mciOpenParms));
if Boolean(dwReturn) then
begin
// Failed to open device; don't close it, just return error.
Result := dwReturn;
Exit;
end; // The device opened successfully; get the device ID.
wDeviceID := mciOpenParms.wDeviceID; // Begin recording and record for the specified number of
// milliseconds. Wait for recording to complete before continuing.
// Assume the default time format for the waveform-audio device
// (milliseconds).
mciRecordParms.dwTo := dwMilliSeconds;
dwReturn := mciSendCommand(wDeviceID, MCI_RECORD,
MCI_TO or MCI_WAIT, DWORD(@mciRecordParms));
if Boolean(dwReturn) then
begin
mciSendCommand(wDeviceID, MCI_CLOSE, 0, Null);
Result :=dwReturn;
Exit;
end; // Play the recording and query user to save the file.
mciPlayParms.dwFrom := 0;
dwReturn := mciSendCommand(wDeviceID, MCI_PLAY,
MCI_FROM or MCI_WAIT, DWORD(@mciPlayParms));
if Boolean(dwReturn) then
begin
mciSendCommand(wDeviceID, MCI_CLOSE, 0, Null);
Result := dwReturn;
Exit;
end;
if MessageBox(Application.Handle, 'Do you want to save this recording?',
'', MB_YESNO) = IDNO then
begin
mciSendCommand(wDeviceID, MCI_CLOSE, 0, Null);
Result := 0;
Exit;
end; // Save the recording to a file named TEMPFILE.WAV. Wait for
// the operation to complete before continuing.
mciSaveParms.lpfilename := 'tempfile.wav';
dwReturn := mciSendCommand(wDeviceID, MCI_SAVE,
MCI_SAVE_FILE or MCI_WAIT, DWORD(@mciSaveParms));
if Boolean(dwReturn) then
begin
mciSendCommand(wDeviceID, MCI_CLOSE, 0, Null);
Result := dwReturn;
Exit;
end; Result := 0;
end;
var
wDeviceID: UINT;
dwReturn: DWORD;
mciOpenParms: MCI_OPEN_PARMS;
mciRecordParms: MCI_RECORD_PARMS;
mciSaveParms: MCI_SAVE_PARMS;
mciPlayParms: MCI_PLAY_PARMS;
begin
// Open a waveform-audio device with a new file for recording.
mciOpenParms.lpstrDeviceType := 'waveaudio';
mciOpenParms.lpstrElementName := '';
dwReturn := mciSendCommand(0, MCI_OPEN,
MCI_OPEN_ELEMENT or MCI_OPEN_TYPE,
DWORD(@mciOpenParms));
if Boolean(dwReturn) then
begin
// Failed to open device; don't close it, just return error.
Result := dwReturn;
Exit;
end; // The device opened successfully; get the device ID.
wDeviceID := mciOpenParms.wDeviceID; // Begin recording and record for the specified number of
// milliseconds. Wait for recording to complete before continuing.
// Assume the default time format for the waveform-audio device
// (milliseconds).
mciRecordParms.dwTo := dwMilliSeconds;
dwReturn := mciSendCommand(wDeviceID, MCI_RECORD,
MCI_TO or MCI_WAIT, DWORD(@mciRecordParms));
if Boolean(dwReturn) then
begin
mciSendCommand(wDeviceID, MCI_CLOSE, 0, Null);
Result :=dwReturn;
Exit;
end; // Play the recording and query user to save the file.
mciPlayParms.dwFrom := 0;
dwReturn := mciSendCommand(wDeviceID, MCI_PLAY,
MCI_FROM or MCI_WAIT, DWORD(@mciPlayParms));
if Boolean(dwReturn) then
begin
mciSendCommand(wDeviceID, MCI_CLOSE, 0, Null);
Result := dwReturn;
Exit;
end;
if MessageBox(Application.Handle, 'Do you want to save this recording?',
'', MB_YESNO) = IDNO then
begin
mciSendCommand(wDeviceID, MCI_CLOSE, 0, Null);
Result := 0;
Exit;
end; // Save the recording to a file named TEMPFILE.WAV. Wait for
// the operation to complete before continuing.
mciSaveParms.lpfilename := 'tempfile.wav';
dwReturn := mciSendCommand(wDeviceID, MCI_SAVE,
MCI_SAVE_FILE or MCI_WAIT, DWORD(@mciSaveParms));
if Boolean(dwReturn) then
begin
mciSendCommand(wDeviceID, MCI_CLOSE, 0, Null);
Result := dwReturn;
Exit;
end; Result := 0;
end;
如果要做到你所讲的那种,请用waveInXXX系列函数吧。