Solved

Recording a wave file

Posted on 1998-11-23
7
202 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 2

Accepted Solution

by:
trillo earned 150 total points
Comment Utility
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
Comment Utility
As ZifNab stated
 the edlphi uper page URL is
 http://sunsite.icm.edu.pl/delphi/

Regards
0
 
LVL 4

Author Comment

by:saar2
Comment Utility
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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

744 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now