• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 226
  • Last Modified:

Recording a wave file


How can I record a new WAV file from the mic and save it into a new file?

  • 2
  • 2
  • 2
  • +1
1 Solution
There are a lot of sound components in the Delphi Super page
and they are capable of getting the sound from the Sound Card,
and capable of giving them in the buffers.

 When the buffer is filled, the component fires the onbufferarrive or something like that. In the event handler of this event simply write the arrived buffer to the HD.(I think that some of these components must have the ability of directly writing to a wav file.
If they lack this ability(recording to wav file), you must add a header to very first beginning of the file.

As you know WAV file has header, which holds the size of the file , the sampling frequency used and the things like that, So you must arrange the header.

To have the header done;
1- first write the header section to the HD. (Before writing anything to HD.)
2- Start recording, add the coming data to the end of the header that you wrote.
2- After completing the record , return the header section and write the correct values for the file size, frequecy ..


saar2Author Commented:
Where is the Delphi Super page ?

Could you please give me the source code for the header writing?

Thank you,

 this article is already a good start :


 It is for D1 so you'll need to change some code.

 DSP : http://sunsite.icm.edu.pl/delphi/

 and another good one :

 Torry : http://www.torry.ru/index.htm

Regards, Zif.
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

The easiest way is using the low level API using the "mciSendString" function.

For example: place some buttons on your form and write this code.

-------Record button-------
        i =: mciSendString('open new type waveaudio alias anyname', 0, 0, 0);
        i =: mciSendString('record anyname to 20000', 0, 0, 0);

------Stop button----------
        i =: mciSendString('stop anyname', 0, 0, 0);

--------Play button-------
        i =: mciSendString('play anyname from 1 wait', 0, 0, 0);

------Save button---------
        i =: mciSendString('save anyname c:\wave.wav', 0, 0, 0);
        i =: mciSendString('close anyname', 0, 0, 0);

Note: This example uses 20000 miliseconds as the maximum recording time, you can increase this value on the record command (see the code on the record button). The recording stops on two cases. Whe the maximum time is reached or when the user selects the stop button (the one that happens first)

Other note: The "open" and "close" commands are relative to the device, you have to use the "open" command prior to any wave operation (record, play, save, etc..) and use the "close" command when you have finished. Remember all your wave operations must happen between the "open" and "close" MCI commands.

As ZifNab stated
 the edlphi uper page URL is

saar2Author Commented:
msac_m, I looked at the Delphi Super Page and I didn't find any free component which let me create and save a file. I tried to download some files but the links were broken.

trillo, I don't know much about Delphi. Do I need to create Tmediaplayer object?
How do I use the Open/Close commands? What is the "i" variable?

Thank you all,
Ok.... let's see:
The code I posted here makes use of API functions, this means that you don't have to create a TMedaPlayer component, reducing the memory and executable space needed.

The open, close, save (and others) are called MCI commands ("multimedia command interface"), and the are used with the mciSendString APi function. This is a powerful function that allows you to manipulate almost any kind of multimedia type (audio, midi, avi video, CD, etc..)
What is the "i" variable.... It's optional but it's always useful. The mciSendString functions always return a value depending on the string used, but in all cases when the functions is succesfull it returns 0. This will allow you to trap errors, if "i" is different from 0 an error occurred.

There are a lot of these MCI command strings and the keywords and syntax depend on each command and device. You can find the documentation of MCI commands on help files, or if you don't have them you have two choices: Searching on the Web or just write "Trillo, tell e more about MCI", OK?
I hope this helped you a little bit.

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now