Google
  Web www.spinics.net

Re: Next question about binary files/combining them, etc.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]


Ok, thanks for suggestions/links etc. - think just had maybe not approached
it perfectly in past, but, here's now a test version:
http://www.blindza.co.za/TTS/

Found the relevant code/example on this page:
http://www.splitbrain.org/blog/2006-11/15-joining_wavs_with_php

And, if interested, the source code in the bgsound.php file which is the one
I am calling as the src value for the bgsound element in the page inside the
hidden iframe, is the following:
<?php
function joinWavs($wavs){
   $fields = join('/',array( 'H8ChunkID', 'VChunkSize', 'H8Format',
                             'H8Subchunk1ID', 'VSubchunk1Size',
                             'vAudioFormat', 'vNumChannels', 'VSampleRate',
                             'VByteRate', 'vBlockAlign',
'vBitsPerSample' ));
   $data = '';
   foreach($wavs as $wav){
       $fp     = fopen($wav,'rb');
       $header = fread($fp,36);
       $info   = unpack($fields,$header);
       // read optional extra stuff
       if($info['Subchunk1Size'] > 16){
           $header .= fread($fp,($info['Subchunk1Size']-16));
       }
       // read SubChunk2ID
       $header .= fread($fp,4);
       // read Subchunk2Size
       $size  = unpack('vsize',fread($fp, 4));
       $size  = $size['size'];
       // read data
       $data .= fread($fp,$size);
   }
   return $header.pack('V',strlen($data)).$data;
}
if (isset($_GET["str"])) {
$arFiles = array();
for ($I = 0; $I < strlen($_GET["str"]); $I++) {
if (is_numeric($_GET["str"][$I])) {
array_push($arFiles, "./sClips/" . $_GET["str"][$I] . ".wav");
}
}
$outgoing = joinWavs($arFiles);
header("Content-Type: audio/x-wav");
header("Content-Disposition: attachment; filename=dynamic.wav");
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . strlen( $outgoing));
echo $outgoing;
}
?>

And, those numeric sound clips are not necessarily perfect in terms of file
size, etc., but they were just test ones I generated quickly for testing
this with.

Stay well

Jacob Kruger
Blind Biker
Skype: BlindZA
'...fate had broken his body, but not his spirit...'

----- Original Message ----- From: "Gavin Chalkley" <gavin.chalkley@xxxxxxxxx>
To: <php-windows@xxxxxxxxxxxxx>
Sent: Sunday, May 13, 2012 5:12 PM
Subject: RE:  Next question about binary files/combining them, etc.


Give this a go:

http://lmgtfy.com/?q=combining+sound+files+on+the+fly+with+PHP

-----Original Message-----
From: Jacob Kruger [mailto:jacobk@xxxxxxxxxxxxxx]
Sent: 13 May 2012 12:48
To: php-windows@xxxxxxxxxxxxx
Subject: Re:  Next question about binary files/combining them,
etc.

Thanks.

Will check out those things, and, yes, know of stack overflow, but not
always easiest to find completely useful info on that site...:)

Aside from that, this is more to do with adding things like spoken sound
effects to pages, etc. using small sound clips of TTS output using the
various voices/synthesizers I have here - have like 20 different voices
might want to try use, and the idea is to literally sort of mix short
sentences/phrases together, etc., but aside from hardcoding all the
different, complete sound clips, the idea would be to sort of mix a
somewhat
limited dictionary/collection together into various combinations, but,
they
wouldn't be huge files in terms of file size/bandwidth, etc., and would
most
likely either load them into soundManager using JQuery, or load them sort
of
dynamically as  BGSound sources for something like a somewhat hidden
inline
frame, etc.

Thanks again

STay well

Jacob Kruger
Blind Biker
Skype: BlindZA
'...fate had broken his body, but not his spirit...'

----- Original Message -----
From: "Carl Roett" <carlroett@xxxxxxxxx>
To: <php-windows@xxxxxxxxxxxxx>
Sent: Sunday, May 13, 2012 11:55 AM
Subject:  Next question about binary files/combining them, etc.


Depending on what you're building, it could be very easy or extremely
difficult. When posting on mailing lists, you need to give other
developers more information about your application so we can give you
useful information.

Also, for general web-dev questions, sites like stackoverflow.com can
usually provide better answers, and if you're unfamiliar with google's
site: and inurl:
operators<http://support.google.com/websearch/bin/answer.py?hl=en&p=ad
v_operators&answer=136861>, learning how to use them will make your
life immensely easier.

First off, are you doing this in the client (web browser) or the server?
For mixing audio files on the server side, you'd want to use ffMPEG +
whatever PHP interface library you prefer to control it. You would use
either uncompressed WAV files or a compressed format like MP3
depending on how disk-bound the server is.

For the client side, you would never send the data as a WAV file
because it would use 10 times as much bandwidth as a MP3. Most
developers would use Adobe Flash to load the files and mix them. You
could also experiment with HTML5, but the majority of browsers
*currently in use* don't have enough
HTML5 audio support to get the job done. See the Wikipedia article on
HTML5.

Another consideration is the number and size of audio files. If you're
using simple HTML GET requests to fetch your files, you can't use a
file until the *entire* file has been transferred. If you have big
files or lots of files, this could be a problem. The usual solution is
to use a streaming server like RED5 or LightHTTPD's progressive
download. Look it up on Wikipedia.

Saving the output to disk is another consideration. If you have to do
this, the only practical option would be to do it on the server side.
Writing code to decompress an audio file, mix it, and re-compress it
in Adobe Flash or JavaScript would be a massive project.

So, in terms of "simple/doable" ...depending on whether you're trying
to mix sound-effects for a hack-a-thon web game, or whether you're
trying to build an online DJ mixing system ...you're looking at
anything from a full day's work to a 5-year project.

^C^


===========================================================


How simple/doable would it be to do something like sort of dynamically
combine multiple .wav files into a single file/output track?

Know that should be doable, but firstly wonder if something like .wav
files could be combined into one sort of output file, or if it might
be better to rather trigger their playback using something like
JQuery, or something so they then seemed to be combined, but while
still separate..?

Stay well



--
PHP Windows Mailing List (http://www.php.net/) To unsubscribe, visit:
http://www.php.net/unsub.php


--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP Home]     [PHP Users]     [PHP Install]     [PHP on Windows]     [Programming PHP]     [Kernel Newbies]     [Rice Cooker]     [Home]     [Yosemite News]     [Yosemite Photos]     [PHP Books]

Powered by Linux