Jump to content


Photo

joining two audio file binaries


  • Please log in to reply
10 replies to this topic

#1 nadeemshafi9

nadeemshafi9
  • Members
  • PipPipPip
  • Advanced Member
  • 1,245 posts
  • LocationUK

Posted 02 September 2006 - 07:48 PM

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.

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;

thhanx all
DONT LAY AN EGG OVER IT

#2 pedroas

pedroas
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 02 September 2006 - 11:13 PM

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.


#3 nadeemshafi9

nadeemshafi9
  • Members
  • PipPipPip
  • Advanced Member
  • 1,245 posts
  • LocationUK

Posted 03 September 2006 - 06:02 AM

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
DONT LAY AN EGG OVER IT

#4 nadeemshafi9

nadeemshafi9
  • Members
  • PipPipPip
  • Advanced Member
  • 1,245 posts
  • LocationUK

Posted 03 September 2006 - 06:02 AM

im using windows
DONT LAY AN EGG OVER IT

#5 pedroas

pedroas
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 03 September 2006 - 11:39 PM

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

#6 nadeemshafi9

nadeemshafi9
  • Members
  • PipPipPip
  • Advanced Member
  • 1,245 posts
  • LocationUK

Posted 04 September 2006 - 03:57 AM

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,


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

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.
DONT LAY AN EGG OVER IT

#7 nadeemshafi9

nadeemshafi9
  • Members
  • PipPipPip
  • Advanced Member
  • 1,245 posts
  • LocationUK

Posted 04 September 2006 - 06:47 AM

this kinda stuff is not uploaded

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


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

DONT LAY AN EGG OVER IT

#8 nadeemshafi9

nadeemshafi9
  • Members
  • PipPipPip
  • Advanced Member
  • 1,245 posts
  • LocationUK

Posted 04 September 2006 - 06:52 AM

heres some more thats getting knocked out at db insert even though i am using addslashes()

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


these are ok


€€€€€€€€€€€€€€€€€€


DONT LAY AN EGG OVER IT

#9 pedroas

pedroas
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 04 September 2006 - 12:22 PM

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

#10 nadeemshafi9

nadeemshafi9
  • Members
  • PipPipPip
  • Advanced Member
  • 1,245 posts
  • LocationUK

Posted 04 September 2006 - 07:08 PM

i tyed using wb it has no effect, the feild is a BLOB
DONT LAY AN EGG OVER IT

#11 nadeemshafi9

nadeemshafi9
  • Members
  • PipPipPip
  • Advanced Member
  • 1,245 posts
  • LocationUK

Posted 04 September 2006 - 07:22 PM

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
DONT LAY AN EGG OVER IT




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users