Jump to content


This topic is now archived and is closed to further replies.


joining two audio file binaries

Recommended Posts


i am trying to join two wma audio files together after taking them from the db, i need them to play in 1 sequence, has anyone done this before. i can only get one playing even thogh there is the data of two maybe theres a better teqnique (one that works).

heres how im trying to join them but obviously the file end indicates its end and its still read as one and rest diguarded does anyone hav any ideas how i can do this in another way.

[code] header("Content-type: audio/basic");


$sql = "SELECT audio FROM audio WHERE id='18';";
$result = mysql_query($sql, $conn);
$row = mysql_fetch_array($result);
$audio = $row["audio"];

$sql = "SELECT audio FROM audio WHERE id='19';";
$result = mysql_query($sql, $conn);
$row = mysql_fetch_array($result);
$audio = $audio." ".$row["audio"];

echo $audio;[/code]

thhanx all

Share this post

Link to post
Share on other sites
I've never tried this, but there is a little program SoX at http://sox.sourceforge.net/ that you can use to concat sound fils

.... you fetch first audio then write to a file
$file1 = "/tmp/audio1.wma";  // maybe is better generate a random name for the file
$descriptor = fopen ($file1, "w"); 

.... you fetch second audio then write to another file
$file2 = "/tmp/audio2.wma";
$descriptor2 = fopen ($file2, "w");

.... then you concat audio files with sox
$finalfile = "/tmp/final.wma";
$cmd = "sox $file1 $file2 $finalfile";

... erase temporary files

... the last task is to open final.wma, read and return to client
$descriptor3 = fopen($finalfile,"r");
$audio = fread ($descriptor3, filesize ($finalfile));

echo $audio

A better solution would be put $finalfile in a directory under your document root in webserver and redirect header to it.

Share this post

Link to post
Share on other sites
everything looks like its working but i need to concat but i dont know were to put the SOX files for access by shell_exec() i never used a custom shell program so i dont know were to put it i tried a few.

thanx this is very helpfull

Share this post

Link to post
Share on other sites
Well, at a first sight you could put sox.exe in any directory, I suggest C:\WINDOWS (XP) or C:\WINNT (NT or 2000), but check before in PHP.INI wheater you're using safe_mode=true or 1, this directory should be inside safe_mode_exec_dir. Don't forget to call shell_exec with full pathname like shell_exec("c:/windows/sox $file1 $file2 $finalfile");

Share this post

Link to post
Share on other sites
ok its all working BUT

soxmix only exepts wav files, i tryed with wav its doing the job but in my own upload script my wav files are not going in to my db properly they are loosing binaary data wen they go in to the db, the wma files go in perfectly but wav files are being reduced maybe they got special chars in them. here is how im uploading my audio files,

[code] $audiodata = $_FILES['fileaudio']['tmp_name'];
$fopen=fopen($audiodata, "r");
$fread=fread($fopen, $size);
$audiodata = addslashes($fread);
            $sql = "INSERT INTO audio (audio) VALUES ('".$audiodata."');";
            mysql_query($sql, $conn);[/code]

wma files are going in perfect but wav files get reduced to 64 kb

thanx alot uv been very helfull my proj is up and running almost.

Share this post

Link to post
Share on other sites
this kinda stuff is not uploaded


i know about addcslashes($i,$i) but do you recon il hav to compensate for all of this, theres many more and i dont know the ascci.

man i been awake for ages

if (response)

Share this post

Link to post
Share on other sites
heres some more thats getting knocked out at db insert even though i am using addslashes()

[quote]  $$**0066==EENNWW``kkvvƒƒ››§§±±¹¹ÁÁÈÈÎÎÓÓ××ÙÙÙÙØØÕÕÑÑÌÌÄļ¼²²¦¦ššŒŒ~~qqcc

these are ok


Share this post

Link to post
Share on other sites
Well, there are a lot of things that could get wrong:

1) First, when we use fopen with binary files we should do this way
$handle = fopen("file", "rb"); 
$handle = fopen("file", "wb"); 
to make sure file will be treated like a binary file, else it will be treated like a text file where it could do text transformations on line terminators;

2) What is the type of audio field in MySQL?

Pedro A. S

Share this post

Link to post
Share on other sites
well i changed it to long blob, prob solved and used 'B' opperator in fopen.

thanck you verry much for your help.

il work to the next stage and il post my progress, the script is gona join the database audio to create speach.

i will update you on my success, thanx verry much, im gona research what type of sounds i need, i have nero wav editor so i can clean up the sounds.

once more thanx very much i dont think i would have got very far without ur help, and the help u given will stay with me through my up and comming projects.

thancks nadeem shafi

ps. stay tuned

Share this post

Link to post
Share on other sites


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.