Jump to content

joining two audio file binaries


nadeemshafi9

Recommended Posts

hi

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");

include("../db_con.php");

$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
Link to comment
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"); 
fwrite($descriptor,$audio);
fclose($descriptor);

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

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

... erase temporary files
unlink($file1);
unlink($file2);

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

echo $audio

A better solution would be put $finalfile in a directory under your document root in webserver and redirect header to it.
Link to comment
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");
Link to comment
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");
$size=filesize($audiodata);
$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.
Link to comment
Share on other sites

this kinda stuff is not uploaded

[quote]}}}}}}kkppuuyy~~ƒƒ‡‡‹‹““––™™œœŸŸ¡¡¢¢££¤¤££¢¢ 
šš––’ååââÝÝÖÖÎÎÆƾ¾¶¶­­ŸŸ||mm_[/quote]

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)
{
    thanx
Link to comment
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
UUXX[[^^aaccffhhkkmmnnppqqqqqqqqppnnlljjhhffddbb``__]]\\ZZYYXXWWVVUUTTTTSSSSSS
’’’’’’’’’’’’’[/quote]

these are ok

[quote]
€€€€€€€€€€€€€€€€€€[/quote]
Link to comment
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"); 
or
$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
Link to comment
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
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.