Sign in to follow this  
Followers 0
tom13

Splitting an audio file or recording multiple parts and then rebuild again to 1 file

13 posts in this topic

#1 ·  Posted (edited)

I'm working on an audio project which basically creates small files of sounds and should then (in an other client, but that doesn't matter for this question) rebuild or at least continue playing the second part after the first part has finished.

So, I got one song and split it into record1.mp3 and record2.mp3 - record1 ends where record2 starts, I tried this:

#include <Sound.au3>

$s1 = _SoundOpen("c:\record\record1.mp3")
$length1 = _SoundLength ($s1, 2)
$s2 = _SoundOpen("c:\record\record2.mp3")

_SoundPlay($s1)
Do
    Sleep(0)
Until _SoundPos($s1, 2) >= 20000 + 408.459734407587
_SoundPlay($s2)
_SoundStop($s1)

While 1
    Sleep(1)
WEnd

408.459734407587 is the delay it took to start the second record, so we still continue on the (hopefully?) exact same time

It works. However, on the moment where it jumps from record1 to record 2 you'll hear a small difference in sound.

Anyone has any idea on how to fix it? Other ideas on how to rebuild and play it continuesly are welcome aswell.

I also tried to send little pieces of binary code each time, and rebuild the file with the new code in it. Problem with this is that since the parts keep coming the file will become too big - and the MP3 structure gets corrupted if you remove the first part of the binary code. Even if you would, how would I solve the sound interruption when restarting the play method (since it'd only nottice that the file has been updated after replaying it)?

All ideas are welcome.

edit: 20000 is the moment where record2 started recording

EDIT:

my problem changed quite a bit, check my latest post for description: #532983

Edited by tom13

Share this post


Link to post
Share on other sites



You should be using Sox

Welcome to the home of SoX, the swiss army knife of sound processing programs. SoX is a command line utility that can convert various formats of computer audio files in to other formats. It can also apply various effects to these sound files during the conversion. As an added bonus, SoX can play and record audio files on several unix-style platforms.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

You should be using Sox

That program is exactly what I need.. but it does not seem to be for windows ? Do you know about that? :)

I could not find a windows aplicable exe either.

And the win32 folder on the repository seems to be empty?

edit: nevermind, they hided it on source forge :)

Now I need to figure out how to use this baby.

Edited by tom13

Share this post


Link to post
Share on other sites

That program is exactly what I need.. but it does not seem to be for windows ? Do you know about that? :)

I could not find a windows aplicable exe either.

Yes it is. It says Win32 Binary.

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

All of the documentation you need is in that zip file. You will probably use the "trim" function to split a file.

trim start [length]

Trim can trim off unwanted audio from the beginning and end of

the audio. Audio is not sent to the output stream until the

start location is reached.

The optional length parameter tells the number of samples to

output after the start sample and is used to trim off the back

side of the audio. Using a value of 0 for the start parameter

will allow trimming off the back side only.

Both options can be specified using either an amount of time or

an exact count of samples. The format for specifying lengths in

time is hh:mm:ss.frac. A start value of 1:30.5 will not start

until 1 minute, thirty and ½ seconds into the audio. The format

for specifying sample counts is the number of samples with the

letter 's' appended to it. A value of 8000s will wait until

8000 samples are read before starting to process audio.

For example, suppose that you have a recording 1 hour long and wish to cut it into two halves. The following two commands will leave the first half in Half1.wav and the second half in Half2.wav.

sox Input.wav Half1.wav trim 0 30:00

sox Input.wav Half2.wav trim 30:00 60:00

Edited by weaponx

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

All of the documentation you need is in that zip file. You will probably use the "trim" function to split a file.

Well. I did manage to trim audio files, that is not the problem. Note that I had record1.mp3 and record2.mp3

I however need to play those 2 files continuesly after each other without any sound interruption - and, note that record2.mp3 will not be on the harddisk when record1.mp3 just starts playing, it will be when it is on 50% of the duration or something - and when record1.mp3 is on it's end it should continue with record2.mp3 (without interruption/sound disruption/delay).

Also, I tried recording with SoX (my recorder ain't that good so SoX would be great for that aswell), inserted this command (it's in the help file):

sox rec -c 2 test.aiff trim 0 10

I then get the following error:

sox socio: can't open input file 'rec': No such file or directory

Any ideas on both problems maybe?

Edit: nevermind about the recording thing, they hided the rec part in a different download...

The continuesly playing problem still remains though - because it does not seem to be possible to add another sound file to the query while SoX is already playing?

Edited by tom13

Share this post


Link to post
Share on other sites

If you need to play audio in sequence you just call _SoundPlay($sound,1). The "1" flag will pause your script until the first song finishes.

Share this post


Link to post
Share on other sites

Hi.

if sample rate and stereo mode are the same for your MP3 files, look at

mp3directcut (google)

Regards, Rudi.


Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Share this post


Link to post
Share on other sites

If you need to play audio in sequence you just call _SoundPlay($sound,1). The "1" flag will pause your script until the first song finishes.

Yeah.... BUT like I said before: that adds a sound delay/interruption.. you'll hear a little difference in sound (check my uploaded example above), and since the two files are not 2 different songs but 1 continueing song: that difference in sound may not be there, it must play them fluently

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

Hi.

if sample rate and stereo mode are the same for your MP3 files, look at

mp3directcut (google)

Regards, Rudi.

Hi, like I said: the problem is NOT to cut/rip/whatever the audio files, the problem is to continuesly play the cutted versions after each other without interruption (rebuilding them into 1 file is not possible because the second file is not on the harddisk when the first one is just about to play - plus this would make the file too big). So, it needs to instantly play the second file after the first without any delay or interruption.

That is the problem...

Edited by tom13

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

Tried some more stuff... no luck, if you listen well you still hear the sound disruption/change.. tried things like this:

#include <Sound.au3>

$s1 = _SoundOpen("c:\record\record1.wav")
$s2 = _SoundOpen("c:\record\record2.wav")

_SoundPlay($s1, 0)
$y = _SoundLength($s1, 2)
Do
    $x = _SoundPos($s1, 2) + 0.155606368965888
Until $x >= $y
    
_SoundPlay($s2, 1)

Where the .wavs are both 20 seconds and $s2 starts right after $s1

So no luck. I probably need a command tool like thing that will continuesly play 2 (or more) sounds after each other without interruptions, once the first file is about to end the second file will be on the harddisk and then started instantly - after that the first while (which is actually replaced by a new file with the same name) should be instantly played.

Anyone have any idea on how to solve this?

Edited by tom13

Share this post


Link to post
Share on other sites

Guess I'm pretty much doomed on this one :)

1 millisecond screwing it all up..

I did hear someone saying that I should use some kind of a buffer though, but I am not sure what he really means and how to do that - anyone that does maybe?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0