0

My Delphi 10-4-2 FMX project captures microphone audio to a file using this code:

  private
    fFileIncrement: Integer;
    fMic: TAudioCaptureDevice;

procedure TForm1.RecordButtonClick(Sender: TObject);
begin
  fMic := TCaptureDeviceManager.Current.DefaultAudioCaptureDevice;
  if fMic <> nil then
    begin
      RecordButton.Enabled := False;
      StopButton.Enabled := True;
      Inc(fFileIncrement);
      fMic.FileName := 'TESTWAVE-' + fFileIncrement.ToString + '.wav';
      fMic.StartCapture;
    end;
end;


procedure TForm1.StopButtonClick(Sender: TObject);
begin
  if (fMic <> nil) and (fMic.State = TCaptureDeviceState.Capturing) then
  begin
    fMic.StopCapture;
    StopButton.Enabled := False;
    RecordButton.Enabled := True;
  end;
end;

Intermittently, approximately one out of three audio files are missing the last half second of the recording.

What would cause the end of the audio to be cut?

Edit: This has been reported here https://quality.embarcadero.com/browse/RSP-33752 along with a sample project.

Mike at Bookup
  • 1,211
  • 14
  • 32
  • One should be able to run this code, record a few short spoken words (be sure to press the Stop button promptly) and then play the resulting files to see that a few files are missing the last half second of audio. – Mike at Bookup Apr 17 '21 at 20:38
  • Pardon me being obtuse, but why would starting a single record operation result in several "resulting files"? – MartynA Apr 18 '21 at 19:39
  • Perhaps he meant it happens only occasionally? @MikeatBookup: Is this on a particular platform, or all of them? – Dave Nottage Apr 18 '21 at 22:09
  • If you ran the code you would see that it's set up to make a new file (with an incremented file name) so that it's easy to record a few files. On Windows it seems to truncate about one out of three files or so. – Mike at Bookup Apr 19 '21 at 00:41
  • @DaveNottage The files created by this code on macOS work fine. (no missing the last half second of the recording) – Mike at Bookup Apr 19 '21 at 03:00
  • 1
    @MikeatBookup By what means have you determined that you are missing half a second of audio? 500ms is a pretty short interval for a human-initiated button click to reproduce with any accuracy. Is there something in the audio that allows you to resolve when the mouse click happened with that sort of precision? – J... Apr 20 '21 at 17:05
  • Absolutely. My project records very short audio annotations of chess positions. The user presses the Record button, quickly says "The pawn attacks the bishop." and then promptly presses the Stop button. The resulting file plays back as, "The pawn attacks th..." (missing the very critical last 500ms). – Mike at Bookup Apr 21 '21 at 14:30
  • 1
    Before the update where this bug will be fixed, I suggest you start a 500mS timer from the button release and only stop recording when the timer is triggering his event. Of course this would makes all recording 500mS longer but at least you won't loose the critical part. – fpiette Apr 22 '21 at 05:11

0 Answers0