## How to play a part of an audio file ?

Please post bug reports, feature requests, or any question regarding the DELPHI AREA projects here.

### How to play a part of an audio file ?

hello,

I just started with waveaudio package,
and succeeded in making a recording.

For simple task like recording and playback,
I find the manual quit complex.
So I couldn't find a simple solution (without understanding the complete manual) for my second problem: playing (and displaying) a small part of the recorded signal. I know the start and end times in milliseconds, but then ...

// get the audio length in msec
Nsamp := WaveStorage.Wave.Length ;

// make a copy so we can use a different part later
WaveStorage_part.WaveStream[0].CopyFrom(WaveStorage.WaveStream[0],0);

// delete the end of the audio, that we don't need
// Nsamp is too large but it looks it's accepted
WaveStorage_part.Wave.Delete(5000,Nsamp);
// delete the beginning
WaveStorage_part.Wave.Delete(0,3000);

// so now we have the part to be played and displayed
StockAudioPlayer1.PlayStream ( WaveStorage_part.WaveStream[0] ) ;

I sthis the correct way of doing it, or are there better / simpler ways ?

What's the difference between
Wavestream[0]
and
Wave
they seem to do the same ??

thanks,
Stef Mientki
stef
Active Member

Posts: 18
Joined: July 15th, 2007, 1:35 pm

That's correct. Alternatively you can set the position of player to desired start position of the audio. Then during playback, when position reached to the stop position, stop the player.

Wave and Wavestream[0] properties of TWaveStorage point to same object. Wavestream[0] property of TWave class is for compatibility with TWaveCollection.
Kambiz

Kambiz

Posts: 2430
Joined: March 7th, 2003, 7:10 pm

thanks Kambiz,

cheers,
Stef
stef
Active Member

Posts: 18
Joined: July 15th, 2007, 1:35 pm

I update Wave Audio package to add some new methods to TWaveStreamAdapter class.

One of these methods is Copy. Using this method you can create a portion of original wave easily.

For example:

Code: Select all
WaveStorage.Wave.LoadFromFile('D:\Data_TO_exe\aap.wav'); WaveStorage_part.Wave.Copy(WaveStorage.Wave, 3000, 2000);

Or using Sub method:

Code: Select all
WaveStorage_part.Wave.LoadFromFile('D:\Data_TO_exe\aap.wav'); WaveStorage_part.Wave.Sub(3000, 2000);
Kambiz

Kambiz

Posts: 2430
Joined: March 7th, 2003, 7:10 pm

thanks Kambiz,

I've been struggling the last days with your mixer component,
I couldn't get it to work reliable on more than 1 machine (all XP),
and it crashed terrible on Vista (but I guess that's due to some major changes in Vista). So I had to go back to my old mixer component (Amixer, also called tAudioMixer, so I had to remove it from your library and rewrite my code. As the mixer component is a rather complex / system dependant component (at least from my point of view), it might be a good idea to add a demo (like in amixer), so the user can quickly see if the mixer works for his soundcard.

cheers,
Stef
stef
Active Member

Posts: 18
Joined: July 15th, 2007, 1:35 pm

I did run Mixer Control demo on my Vista box with no problem.
Kambiz

Kambiz

Posts: 2430
Joined: March 7th, 2003, 7:10 pm

thanks,

sorry I forgot all about that demo,
as soon as I've a vista machine available,
I'll certainly test that,
and I'll report back.

cheers,
Stef
stef
Active Member

Posts: 18
Joined: July 15th, 2007, 1:35 pm

sorry sorry sorry, Kambiz,

it was all my fault,
your demo of the mixer (and now mine too runs perfectly well,
both under XP and Vista,
tested several cards range from over 5 years old to very modern ones.

One of the problems is that Vista has a new philosophy about mixers,
so I've to get used to that.

thanks for the very good component
(much simpeler (after you understand it than the one I used before),
cheers,
Stef Mientki
stef
Active Member

Posts: 18
Joined: July 15th, 2007, 1:35 pm

hi Kambiz,

Thanks for the fast bugfix ...

... but the recording problem (a buffer is stored twice) is still there,
probably has been there all the time,
but I didn't notice it until now.

My program works like this:
- an image is shown
- the child should pronounce the issue on the image
- these steps are repeated about 50 times
I use StockAudioRecorder, because it was used in your example,
and because it has a recordtofile.

When I load a new image, the recording isn't stopped.
When using large images, the number of errors increases.
When I increase the buffersize of the recorder, the number of errors decreases (maybe even vanishes at 10000 ),
but as I need to know the pointers were a certain image was shown,
10000 is too long,
because when asking the recorder for it's position,
(at least I guess) the recorder waits until the buffer is finished.

I also tried to increase the number of buffers,
but that didn't reduce the error rate.

I also tried to pause the recording before loading a new image,
(see the last recording in the attachment),
and that resulted in an "echo" of almost every word.

If it's necessary,
I think I can simplify my program,
so I can send it to you for debugging.

cheers,
Stef
Attachments
waveaudio_problem.pdf
some recordings
stef
Active Member

Posts: 18
Joined: July 15th, 2007, 1:35 pm

Having a sample to trace the problem would be very helpful.
Kambiz

Kambiz

Posts: 2430
Joined: March 7th, 2003, 7:10 pm

hi Kambiz,

I created a simple example,
reproducing the problem.
I don't have it around with me now,
so I'll send it tomorrow.

cheers,
Stef
stef
Active Member

Posts: 18
Joined: July 15th, 2007, 1:35 pm

hi Kambiz,

this is a very simple example (D7) that shows the problem.
The program shows a picture,
then you have to pronounce the object,
with the spacebar you go to the next picture,
and so on.
With escape you leave the program.

You need 2 large (600k or larger) jpeg pictures (not included),
named
auto_2.jpg
bal_2.jpg
or change the name in the program.

Hope this helps you to solve the problem,
(I'm not in a hurry, because I now use another approach).

cheers,
Stef
Attachments
test_sound_opname.zip
stef
Active Member

Posts: 18
Joined: July 15th, 2007, 1:35 pm

Thanks for the sample. It's very good that you are not in harry.

I was too busy for a few says, so that I couldn't even get online. I try to find and resolve the problem until weekend.
Kambiz

Kambiz

Posts: 2430
Joined: March 7th, 2003, 7:10 pm

Hi Stef,

I checked your sample out. On my machine it works properly.

Even I used PicShow and better audio format to use more cpu, but no change in quality of recorded voice.

Kambiz

Kambiz

Posts: 2430
Joined: March 7th, 2003, 7:10 pm

### Who is online

Users browsing this forum: No registered users and 5 guests