Link to home
Create AccountLog in
Avatar of Bluejay86

asked on

Store and Retrieve ".wav" recordings

I have a website where users record sound and save sounds for later playback.  Using "ogg compression", most sounds are no larger than 20K.  The website is published with Director 11's Shockwave.   I would like to upload, store, and retrieve sounds with a mySQL database identified by each users ID number.  Currently, my users have a folder on my server and the sounds are uploaded to this folder.  When the recorded sound for the user is needed for playback at a later time, the sound is downloaded to the user's machine and then the sound is played.  I need a quicker, more efficient model.  Can mySQL and php solve this problem?  Thanks for your help!

Avatar of Bobaran98
Flag of United States of America image

Since your sound files are so small, there's no reason you can't saved them directly into a BLOB field in your MySQL database (removing the need for separate directories).  I can show you the code for that, if you'd like.

Of course, for playback, I don't think you can just load an OGG file and expect the browser to translate it as audio, in which case the user would still need to download the file to play.

Tell me, though... it sounds like your Shockwave app is doing some sort of audio file editing... do you have a way of converting that OGG file code back into WAV on the fly?  Because if so, I think we can get you to what you're looking for.  Let me know!
Avatar of Bluejay86


Thanks for your help.  Yes, my Shockwave app is doing some audio file editing.  After the user records a sound, the file is compressed using ogg compression - the compressed file is stored is as a smaller "wav" file in each students folder after it is uploaded.  This site is designed for elementary classroom teachers and their students.  Since each student has a portfolio approximately 100 recorded sounds throughout the school year, thousands of sounds  need to be available at any given moment, depending on which student has been selected in a pull-down menu.  That is why I was hoping I could play each sound file from the web as opposed to downloading the file and then playing the sound.  Your thougths....and thanks again for the assistance!  (PS - I do have a beta sight if that would help to look at.  Let me know)
Okay, tell me if the code below makes sense to you.

I'm using a MySQL database here.  The following all works... I guess my biggest question would be the format of your OGG file data, which we need to get properly assigned to the $content variable.

Note that the type of BLOB you use in your table definition sets the upper limit on your file size.  Your options (for this application, at least) are:
  • TINYBLOB - 255 bytes
  • BLOB - 64 KB
It sounds to me like what you'll want is a straight BLOB.

The final code I include here-- the downloading segment-- is intended to stand alone as its own file.  For example, you might modify it so $id=$_REQUEST[id];  Then you could simply save it as, say, oggDownloader.php and link to:

... and loading that URL would automatically bring up a Save As dialog for your OGG file.

Now, if you want to add in your OGG-to-WAV conversion in that downloader file right before your header() definitions, then you could spit out a WAV file instead... and the browser should interpret that as something to be played rather than something to be downloaded.  Either way, the clicked link (leading to this file) should not redirect the browser or cause a new window to open.  It's all very smooth.

CREATE TABLE  `dbName`.`tableName` (
  `fileID` int(11) NOT NULL auto_increment,
  `filename` varchar(50) NOT NULL default '',
  `filetype` varchar(50) NOT NULL default '',
  `filesize` int(11) NOT NULL default '0',
  `filecontent` mediumblob NOT NULL,
  `filedesc` varchar(100) default NULL,
  PRIMARY KEY  (`fileID`)
	//you'll want to define the following variables, probably:
        $content = $yourFileData;
	$fileName = "";
	$fileSize = "";
	$fileType = "application/ogg"; //I'm guessing here
	$filedesc = "";	//just so you have something to show users besides the filename
	//processing save to DB
	if(!get_magic_quotes_gpc())	{
		$fileName = addslashes($fileName);
	$db = mysql_connect($DB_LOCATION, $DB_USERNAME, $DB_PASSWORD);
	mysql_select_db($DB_NAME,$db) or die( "Unable to select database");
	mysql_query("INSERT INTO tableName (filename, filesize, filetype, filecontent, filedesc) VALUES ('$fileName', '$fileSize', '$fileType', '$content','$filedesc')");
	$db = mysql_connect($DB_LOCATION, $DB_USERNAME, $DB_PASSWORD);
	mysql_select_db($DB_NAME,$db) or die( "Unable to select database");
	$id = 5; //replace this with the ID value for the file you want to download
	$query = "SELECT filename, filetype, filesize, filecontent FROM tableName WHERE fileID=$id;";
	$result = mysql_query($query);
	list($name, $type, $size, $content) = mysql_fetch_array($result);
	header("Content-length: $size");
	header("Content-type: $type");
	header("Content-Disposition: attachment; filename=$name");
	echo $content;

Open in new window

Hi, I am now officially lost because I do not know phP or mySQl.   I am a "self-taught" programmer.  I only know VB code and Director's Lingo syntax.  I would like to accept this solution so you can receive your points.  I can then pay someone to implement this code im my Director file.  

So...I think that you are saying that the user can click a "Play Sound" button, and this code, or something close to this code can retrieve the sound for the current student and play the sound as a BLOB file.  Am I correct in my interpretation?  If so, this is very exciting and after I hear from you, I can accept the solution.  Let me know - Brian in Omaha
Sorry, when you posted your question in the PHP and MySQL zones, I kinda assumed you were looking for a PHP/MySQL solution.

Answer me the following questions, and maybe you can keep your wallet in your pocket. :-)
  • In Director, can you set things up so that when a user records their sound, the file is saved to a directory on the website?
  • Is your website capable of executing PHP scripts?
  • Do you already have a MySQL database setup?
If we can get to a Yes in answer to those questions, I think we can work through this ourselves.  Let me know!
And yes, in terms of what the user experiences on your website, your interpretation above is correct.
The answer to all three questions is "Yes".  Currently, the file is compressed and uploaded to each users folder on my server (

My shockwave site currently uses php scritps and a mySQL database to store and retrieve name information and userID numbers.

Okay, then, this is what I propose.  Create a folder named TempOggs or some such, and instead of saving your OGG files in user-specific directories, you save them all there.  You would then load a PHP script that would take that newly saved file and stick it in the database, then deleting the file from the TempOggs directory.

So at this point, we've got the sound in the database.  Now what I propose is creating a second PHP script that will return that sound from the database as if it's an OGG file.  Then you can just put that PHP filename into your Director file and pretend it's an OGG file, and Director can convert it to WAV and play it on the fly.

Does that sound like it would meet your needs?  Are you comfortable with doing in Director what I've just described?
Yes, I am comfortable doing what you have described in Director.  The question then becomes, would the sound file be played with a reference to a  specifi URL?
Take two, I am not sure I made much sense with the previous post.  My question is this:  does the sound file play with Lingo/Java Script (in Director) or does the sound play with php script?
For all intents and purposes, you would program your Director Shockwave as if you had a repository full of OGG files.  However, each time you go to open one of those files, however, instead of referencing soundfile1.ogg, soundfile2.ogg, and soundfile3.ogg, you would actually be referencing generator.php?id=1, generator.php?id=2, and generator.php?id=3.  But Director won't know the difference-- all it will know is that it's getting a file with the expected mime type of "application/ogg".  Then you take it from there with Director, presumably by having the file converted to WAV and played.

Are we on the same page?

The only thing you'll need from within Director is that ID number... do you have an established way of accessing the database from within Director, or do we have to think of something else?
I do have an established way of accessing the database from within Director.

My id # is "m c201708".  We currently retrieved stored text and place this is in various text boxes at the shockwave site with php and mySQL using this id #.

If this works, I cannot just have you "get points".  I would like to compensate you for all your time and insightfulness.  I am with you conceptually, but not technically.  Do you need my password to access the database at my server?
First of all, please don't worry about compensation (I'm not even sure it would be in keeping with EE's standards to accept anything anyway!).  It's not a major project, we've just been a bit limited in our communication by the fact that I can't look at your setup directly.  So yes, I don't at all mind taking a look at your code, etc.

Please, please, please, however, do not post any personal information here-- no phone, email, or login credentials.  Instead, send me an email at then post here again to tell me what time your email went. :-)  I don't care if the world has that address... it's nothing but my junk mail recipient.

Anyway, send me your email or phone-- whatever you prefer-- and we'll go from there.
Okay, I sent you an e-mail at 11:36 CST on 5-9-09.  I sent you the code in the "onStart" movie handler which creates global variables and the php connection with mySQL database.  Thanks again.
Avatar of NerdsOfTech

Your project sounds very interesting. Since you will be dealing with 1000s of sounds I would implement MP3 conversion instead. MP3 is universally accepted and usable. Or, if your host provides enough space stick with .wav w/o conversion.

Let me know what you think.

It is a fascinating project and very humbling.  Your comment leads me to the following question, can Adobe Director play mp3 sounds?  Prior to Director 11 and Shockwave 11, it was very easy to upload a swa file and play it by calling a url path.  The students rollover sound constantly in this app, the sound needs to happen "quickly".  Your thoughts...?

P.S. I love Director, but I know it is "old school"
1. What programs are you using?
2. Are you allowing the students to upload anything they want?
3. How are you playing back the sounds?
4. What are you using to playback the sounds, any program, api, or control?
5. What size limitation do you have if any for allocation of uploads?
6. What language is your current project written in?
7. What version of director are you using?


Please use this list to help answer these questions:
mp3 is capable of stream in director -- just like swa; that is why this is probably the best solve.
Upload mp3 .
Reference location in director by URL .
figure out the best preload time ...etc.etc ...
I found this interesting temporary storage sound upload/player
Anyways like I said before MP3 is probably the best media to convert to from WAV

Stream a linked Shockwave Audio or MP3 sound


      Select Insert > Media Element > Shockwave Audio.

      This process creates a cast member that controls the streaming Shockwave Audio.

      In the SWA Cast Member Properties dialog box that appears, click Browse and select a Shockwave Audio file on a local disk, or enter a URL in the Link Address text box.

      Unless you select a file in the same folder as the movie, the movie always links to the exact location that you specify.

      Set the remaining cast member properties in the Property inspector:

            To set the volume of the sound, use the Volume slider in the SWA tab in the Property inspector.

            To select the sound channel for the sound, select a number from the Channel menu in the SWA tab. To avoid potential conflicts, select Any, which causes the sound to play in the highest-numbered available sound channel.

            To specify the size of the stream buffer, use the Preload option in the SWA tab. Director attempts to load enough sound data to play for the specified time in seconds. This prevents gaps in sounds that play over slow or interruption-prone Internet connections.

      Drag the Shockwave Audio cast member to a sprite channel (not to one of the sound channels) to create a sprite. Extend the sprite through all frames in which the sound should play, or use the tempo channel to make the movie wait for the end of the sound. For more information, see Synchronizing media.

      You cant place streaming audio cast members in the sound channels. The sound streams from the source location when the movie plays.

Nerds of Tech:, all audio is recorded, uploaded, and played via the web.  This is a preschool to 3rd grade web site.  Students just click play, stop, save to web or listen from web.  Sounds must be saved to web server so that the site is portable.
Now you thought director was old school... You could actually do this with wav and HTML believe it or not.

<EMBED> would work in this case :)

You could then use PHP do dynamically filling the SRC

Let me know if you need help doing this.
NerdsOfTech brings up a good question.  BlueJay86, what all is your Director app doing?  If its whole purpose is to do what we've been discussing here-- to upload, store, and play audio files-- then Nerds is right.  Simplify and go with plain ole HTML and PHP.

Let us know.
That is a great question.  Director allows my graphic artist to do really nice animation and artwork.   After students have recorded the sounds, the students use the sounds in various games and book building activities.  Essentially, the games are voiced by the user.  Director is a great app for simple (and complex) game programming.  The thing is, the student's voice needs to be available immediately for use in the activities section of the web site.  Currently, my user has to wait 4 or 5 seconds to hear their downloaded voice.  That is why I thought phP could be a good fix because we retrieve saved text so quickly with phP from mySQL   I have had many people tell me that phP and mySQL are not the solution.  I hope you guys are right (you guys are actually making some sense out of my problem!)
I would think PHP/MySQL should work fine for you, especially given that your file sizes are small.  NerdsOfTech is probably right that you should consider saving your files in WAV or MP3 format, though... anything to cut down on processing time.

Nerds, it's been about seven years since I played with Director, which means I remember... exactly nothing.  No wait, I remember being annoyed that so much of it reminded me of Flash, yet it was different enough to cause a lot of frustration.  Anyway, is there a way Bluejay can preload his (PHP generated) sound files, perhaps incur a slight delay at load time, and then have instant playback the rest of the time?

Originially, my thoughts on the upload-and-save process-- in case they weren't clear from above-- were for Bluejay's Director file to do the upload and compress/convert to OGG, then somehow launch a PHP script in a derivative process, sending the file data as a POST variable.  However, if Bluejay were to go with WAV rather than OGG, his process could be something more like this:
  • Include an "Upload Audio File" link in the Director project
  • Clicking that link takes user to a straight HTML form with a file upload input field
  • Form submission action is a PHP script which uploads file and inserts in MySQL db
  • User never sees the PHP script, because it does a header redirect back to the Director project after upload is complete.
Or, of course, we could still have the "Upload Audio File" link open in a new window, meaning the original project continues to run uninterupted.  Then when the upload is complete, there's simply a "Close Window" button.

If it helps, the oggVorbis compression that I am using keeps the original wav file as a wav file after the original wave file has been compressed.  This compression is done with a Director xtra called Audio Xtra 6.1 which is an "add on" to Director that I purchased.
Another option:

Localized playback via file:// URL could be done for this project.

E.G. the student "loads" the record in mySQL opposed to the UPLOAD.. so a "no upload" solution. The files resides on the clients "student's" computer and allows instant playback... The only way that would work is if they used the same station.

Just a thought.

As far as the question bob asked about preload.
You can most definitely preload the sound file(s) using javascript headers.
So instant playback should be easy.

Avatar of NerdsOfTech
Flag of United States of America image

Link to home
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Currently Implemented:  Students record files with audio xtra.  Students save recording into their own folder on my server.  When student plays various games, sound is downloaded to the machine currently being used with ShockFiler xtra and sound is then played with audioXtra in Director.

What needs to happen:  Sound needs to be uploaded into mySQL database.  When saved sound is needed, sound is retrieved and played from the web so that website can be used on any machine.

NerdsOfTech, as I had mentioned earleir to Bobaron, I am a teacher who has developed this concept of linking learning with home and school, so portability of the sound is critical.  I use Director because I am "self-taught" programmer.  Director actually makes it look like a know what I am doing sometimes.

If you guys have a solution with php, I can probably implement it in Director because I had purchased code to save and retrieve text files with php and mySQL.   At this point, if it is possilbe, I can hire someone to solve this problem if it goes beyond Director since I am not a programmer.  If I can get sound stored and play "fairly quickly" from the web, this would be a dream come true for me becuase voice is everything in my software. I have been testing a beta copy this year in my classroom and parents and students love it.  I need to take the "next step" and will implement whatever you guys think is best - Bluejays86.

You can email me at:
admin {at sign} nerdsoftech {dot} com
replace the {symbol} with the actual symbol.

One more comment to add to previous post, latest version of Director 11 can be scripted with Lingo ( its original scripting language ) or JavaScript.  So If JavaScript can help solve the problem, that may be of help with Director - Thanks for all your insights, Bluejays86.
Thanks for all the help!