Link to home
Start Free TrialLog in
Avatar of Stormmin66
Stormmin66

asked on

Record voice to mp3 stream

This one is very important so I'm going to make it worth while. What I need to do is record from microphone to mp3 stream and write the stream to file.  I would like some example code for this one. I need record, stop, and playback capabilities.  Please don't just point me to a website ( these answers will be rejected ), i must have some example code, and if 3rd party components are used, I will need to know where to obtain them.  Thanx in advance.

Stormmin
Avatar of ginsonic
ginsonic
Flag of Romania image

listening ... for moment
Avatar of tongalite
tongalite

Listening too :)


Hi,
If you want to know more about wav2mp3 then you really ought to take a look at this paper:

http://delphi.about.com/library/bluc/text/uc050501a.htm

It will at least show you what you are up against.

Reject this as you like... you have no quick fix!

Excerpt:
------------------------------------------
The first part (Demo2.dpr) acts as a server. It has a server socket listening on port 6565 for new connections. At the same time it takes audio in from the MIC, converts it into MP3 16BIT 8Khz MONO (2k/second) and pipes it out.
------------------------------------------
Downloadable demo code here:

http://delphi.about.com/gi/dynamic/offsite.htm?site=http://www.stuckindoors.com/delphi/acm/downloads.html

The above is useful reading.Not meant as an answwer to your question, simply a source of info.

(recording from pc mic in delphi is not as straight forward as you might think) You'll need to convert to mp3 anyway. you can download encoders/decoders at the above URL


If I find any relevant code to assist you, I'll post it

Good luck
t.
Avatar of Stormmin66

ASKER

Yes, I realize there is no quick fix for this. I can take the input from the microphone and create a wav file, but i don't want to have to go thru converting it to mp3, I would like to record the stream as mp3.
i think it's better to first recrd to a wav stream and afther that convert it into mp3, since the encoding process takes up a lot of time. Or you state in your hardware requirements that a strong machine is nessesery.
As far as i know it's still impossible to encode wav to mp3 realtime.

still if you want to bypass this problem you should buffer the wave file and feed blocks to the encoder. (as far as i know mp3 is a format designed for streaming.)
Hello ginsonic... we meet yet again.

Now, Stormmin66, I think it IS possible to acheive what you ar planning. I don't have the knowhow - in fact few people on this planet do because it's very sohpisicated - but if you go to the people behind LAME encoder, you can get well along the road there. LAME, like BladeEnc, is a MPEG1 Layer3 encoder/decoder subject to the General Public License. Unlike BladeEnc its performance is musically perfect. Source code is available via CVS. Like the others it only works on files, but I see no reason why, if you mess with the code (which I think is in C++, if I remember correctly) you can't substitute file input with RAM input. MPEG always segments or windows the input into tiny packets called frames, so what you're doing will not be too difficult. The LAME project will probably appreciate any contribution you can make.

Website...  http://www.sulaco.org/mp3/
a real simple way would be to use the ACM Components from http://www.stuckindoors.com/delphi
they're free with source and use the MS ACM
you can also checkout my demo of VoIP to see how to use them
http://lee.nover.has.his.evilside.org/isapi/pas2html.dll/pas2html?File=/delphi/projects/VoIP
to make the mp3 work you need to wrap it in this structure :

  MP3_wfe_tag = packed record
    wID: WORD;
    fdwFlags: DWORD;
    nBlockSize: WORD;
    nFramesPerBlock: WORD;
    nCodecDelay: WORD;
  end;


  // addons for extra codecs
  WAVE_FORMAT_MSG723 = 66;
  WAVE_FORMAT_MPEGLAYER3 = $0055;
  MPEGLAYER3_WFX_EXTRA_BYTES = 12;

  MPEGLAYER3_ID_UNKNOWN = 0;
  MPEGLAYER3_ID_MPEG = 1;
  MPEGLAYER3_ID_CONSTANTFRAMESIZE = 2;

  MPEGLAYER3_FLAG_PADDING_ISO = $00000000;
  MPEGLAYER3_FLAG_PADDING_ON = $00000001;
  MPEGLAYER3_FLAG_PADDING_OFF = $00000002;

  msg723_mn: array[0..9]of Byte = (2, 0, $ce, $9a, $32, $f7, $a2, $ae, $de, $ac);
  mpgl3_mn: MP3_wfe_tag = (
    wID: MPEGLAYER3_ID_MPEG;
    fdwFlags: MPEGLAYER3_FLAG_PADDING_OFF;
    nBlockSize: 0;
    nFramesPerBlock: 1;
    nCodecDelay: $0571);


acm components have the abilitiy to use extended formats
you simple add the constant mpgl3_mn format to the end of the WaveFormatEx strucutre of the acmconverter component

// acmConvIn is TACMConvertor
const offset = SizeOf(TWaveFormatEx);
begin
with acmConvIn.FormatOut do
       if Format.wFormatTag = WAVE_FORMAT_MSG723 then
          Move(msg723_mn, RawData[offset], 10);

you do the same for mp3
ASKER CERTIFIED SOLUTION
Avatar of Lee_Nover
Lee_Nover

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi Lee Nover

You gave him the same URL I gave him a ½ dozen posts ago!
T.
ahhh ... didn't see the whole link .. just the about.com .. :)
Lee, i'll give this a try and see if i follow what you are saying, may be back for more details.
Hi lee...
I tryied out your VoIP Sample and could not get it to work on my Win98 peer-to-peer LAN

I type the IP address of the other machine on mine and press enter, the program goes trought a long time-out and enables again! No sound on the other side!

Am I doing something wrong?

VSF
www.victory.hpg.com.br
VSF - dunno, it works for me on win2k, I've tested it with some other ppl on different oses and it worked
it's merely a demo of how to make a voip app
I made it to test the system before I implemented it into a bigger project - didn't want to recompile the client and the server everytime :)
what if you use localhost ?
and on lan you can use the computers name
you can also leave the box empty - then it will broadcast into the LAN
all of the VoIP apps in the network will receive the broadcast
you can mail me regarding the VoIP app - Lee_Nover@delphi-si.com
Sorry took so long to reply, been on vacation.  Code really helped out, thanx.
about these Components .. you don't have to use anything extra with mp3 if you use the professional version of the Fraunhoffer codec which can also be downloaded at that site
I don't know what I did wrong before but now it works without any modifications
that little 'hack' is still needed for MS G.723.1