Solved

Recording a wave file

Posted on 1998-11-23
7
211 Views
Last Modified: 2010-04-04
Hi

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

Saar
0
Comment
Question by:saar2
  • 2
  • 2
  • 2
  • +1
7 Comments
 

Expert Comment

by:msac_m
ID: 1347664
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 ..


Regards,


0
 
LVL 4

Author Comment

by:saar2
ID: 1347665
Where is the Delphi Super page ?

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

Thank you,
Saar
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1347666
saar2,

 this article is already a good start :

 http://www.undu.com/DN970901/00000022.htm

 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.
0
Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

 
LVL 2

Accepted Solution

by:
trillo earned 150 total points
ID: 1347667
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.

Trillo
0
 

Expert Comment

by:msac_m
ID: 1347668
As ZifNab stated
 the edlphi uper page URL is
 http://sunsite.icm.edu.pl/delphi/

Regards
0
 
LVL 4

Author Comment

by:saar2
ID: 1347669
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,
Saar
0
 
LVL 2

Expert Comment

by:trillo
ID: 1347670
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.
Trillo
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question