Solved

Store and Retrieve ".wav" recordings

Posted on 2009-05-09
35
993 Views
Last Modified: 2013-12-20
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!

0
Comment
Question by:Bluejay86
  • 14
  • 12
  • 9
35 Comments
 
LVL 8

Expert Comment

by:Bobaran98
ID: 24344364
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!
0
 

Author Comment

by:Bluejay86
ID: 24344493
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)
0
 
LVL 8

Expert Comment

by:Bobaran98
ID: 24344590
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
  • MEDIUMBLOB - 16 MB
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.

<!-- HERE'S THE SQL DEFINITION FOR THE MySQL TABLE FOR STORING FILES //-->

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`)

) ENGINE=MyISAM DEFAULT CHARSET=utf8
 
 

<!-- HERE'S YOUR PHP CODE FOR SAVING INTO A MySQL DB //-->

<?php
 

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

	mysql_close();
 

?>
 
 

<!-- HERE'S YOUR PHP CODE FOR CREATING A FILE DOWNLOAD FROM A MySQL DB //-->

<?php
 

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

	exit;
 

	mysql_close();
 

?>

Open in new window

0
 

Author Comment

by:Bluejay86
ID: 24344818
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
0
 
LVL 8

Expert Comment

by:Bobaran98
ID: 24344907
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!
0
 
LVL 8

Expert Comment

by:Bobaran98
ID: 24344944
And yes, in terms of what the user experiences on your website, your interpretation above is correct.
0
 

Author Comment

by:Bluejay86
ID: 24344952
The answer to all three questions is "Yes".  Currently, the file is compressed and uploaded to each users folder on my server (bluehost.com).

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

0
 
LVL 8

Expert Comment

by:Bobaran98
ID: 24345068
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?
0
 

Author Comment

by:Bluejay86
ID: 24346129
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?
0
 

Author Comment

by:Bluejay86
ID: 24346145
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?
0
 
LVL 8

Expert Comment

by:Bobaran98
ID: 24346520
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?
0
 

Author Comment

by:Bluejay86
ID: 24346564
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?
0
 
LVL 8

Expert Comment

by:Bobaran98
ID: 24346763
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 bobaran98@hotmail.com... 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.
0
 

Author Comment

by:Bluejay86
ID: 24346839
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.
0
 
LVL 19

Expert Comment

by:NerdsOfTech
ID: 24349432
Bluejay86,

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.

=NerdsOfTech
0
 

Author Comment

by:Bluejay86
ID: 24349454
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"
0
 
LVL 19

Expert Comment

by:NerdsOfTech
ID: 24349528
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?

Thanks!
=NerdsOfTech

Please use this list to help answer these questions:
1.
2.
3.
4.
5.
6.
7.
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 19

Expert Comment

by:NerdsOfTech
ID: 24349576
mp3 is capable of stream in director -- just like swa; that is why this is probably the best solve.
0
 
LVL 19

Expert Comment

by:NerdsOfTech
ID: 24349584
Upload mp3 .
Reference location in director by URL .
figure out the best preload time ...etc.etc ...
0
 
LVL 19

Expert Comment

by:NerdsOfTech
ID: 24349590
I found this interesting temporary storage sound upload/player
http://www.richapps.de/files/filereferencemp3/LoadMp2Filereference.html
0
 
LVL 19

Expert Comment

by:NerdsOfTech
ID: 24349595
Anyways like I said before MP3 is probably the best media to convert to from WAV


Stream a linked Shockwave Audio or MP3 sound

   1.

      Select Insert > Media Element > Shockwave Audio.

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

      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.
   3.

      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.
   4.

      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.

0
 
LVL 19

Expert Comment

by:NerdsOfTech
ID: 24349600
0
 

Author Comment

by:Bluejay86
ID: 24350266
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.
0
 
LVL 19

Expert Comment

by:NerdsOfTech
ID: 24350754
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 :)

http://www.webreference.com/js/column20/embed.html

You could then use PHP do dynamically filling the SRC

Let me know if you need help doing this.
0
 
LVL 8

Expert Comment

by:Bobaran98
ID: 24350976
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.
0
 

Author Comment

by:Bluejay86
ID: 24351072
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!)
0
 
LVL 8

Expert Comment

by:Bobaran98
ID: 24351152
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.

Thoughts?
0
 

Author Comment

by:Bluejay86
ID: 24351195
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.
0
 
LVL 19

Expert Comment

by:NerdsOfTech
ID: 24351402
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.

 
0
 
LVL 19

Expert Comment

by:NerdsOfTech
ID: 24351449
0
 
LVL 19

Accepted Solution

by:
NerdsOfTech earned 500 total points
ID: 24351456
So really the possibilities are limitless.

Therefore, what we need to know is: what would you like this to do?

What are your specifications.

From start to finish, what needs to happen? What has already been implemented?

Thanks
=NerdsOfTech
0
 

Author Comment

by:Bluejay86
ID: 24353294
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.

0
 
LVL 19

Expert Comment

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

Sincerely,
=NerdsOfTech
0
 

Author Comment

by:Bluejay86
ID: 24353413
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.
0
 

Author Closing Comment

by:Bluejay86
ID: 31579781
Thanks for all the help!
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
This article discusses how to create an extensible mechanism for linked drop downs.
The purpose of this video is to demonstrate how to Import and export files in WordPress. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: mywebsite.com/wp-login.php : Click on Too…
The purpose of this video is to demonstrate how to integrate Mailchimp with Facebook. This will be demonstrated using a Windows 8 PC. Mailchimp and Facebook will be used. Log into your Mailchimp account. : Click on your name. Go to Account Setti…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now