Reputation: 1685
I know that i can record sounds by Media Player component, but after record i have to save it and then play it. But is there any way to play it instantly or with a custom delay?
Upvotes: 2
Views: 2851
Reputation: 364
Here is how to do it with bass.dll from http://www.un4seen.com/
You can use the RecordTest example from un4seen and modify the following functions like this:
function RecordingCallback(Handle: HRECORD; buffer: Pointer; length: DWORD; user: Pointer): boolean; stdcall;
begin
BASS_StreamPutData(chan, buffer, length); // added: pass the captured data to the push stream
// Copy new buffer contents to the memory buffer
Form1.WaveStream.Write(buffer^, length);
// Allow recording to continue
Result := True;
Form1.WaveStream.Write(WaveHdr, SizeOf(WAVHDR));
chan := BASS_StreamCreate(44100, 2, 0, STREAMPROC_PUSH, nil); // added: create a push stream
BASS_ChannelPlay(chan, False); // added: start it
// start recording @ 44100hz 16-bit stereo
end;
procedure TForm1.StopRecording;
var
i: integer;
begin
BASS_ChannelStop(rchan);
BASS_StreamFree(chan); // added: free the push stream
bRecord.Caption := 'Record';
// complete the WAV header
WaveStream.Position := 4;
i := WaveStream.Size - 8;
WaveStream.Write(i, 4);
i := i - $24;
WaveStream.Position := 40;
WaveStream.Write(i, 4);
WaveStream.Position := 0;
// create a stream from the recorded data
chan := BASS_StreamCreateFile(True, WaveStream.Memory, 0, WaveStream.Size, 0);
if chan <> 0 then
begin
// enable "Play" & "Save" buttons
bPlay.Enabled := True;
bSave.Enabled := True;
end
else
MessageDlg('Error creating stream from recorded data!', mtError, [mbOk], 0);
end;
When you press record after the modification, It plays the sound at the same time while recording it.
I got this code from Ian in the forum.
Upvotes: 1
Reputation: 256
You might try the audio library at: http://www.un4seen.com/
The "BASS" DLLs work fine with Windows Xp and Win 7. They are free for non-commercial use. The download includes a simple Delphi example of an audio recorder that allows one to "record," then "save" as an audio file or "playback" the file immediately without saving the audio file while the audio file is still in memory. "BASS" works very well with Delphi 2007. It might work great for your purposes.
Upvotes: 2
Reputation: 9294
You can easily do it with LakeofSoft VC components. Their voice recording demo works like you want.
Upvotes: 3