Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Recording a wave file

Posted on 1998-11-23
7
214 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
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

808 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