How to play Raw audio?

I should explain to prevent confusion. The audio files are generated in real time. I cannot convert them to MP3 or any arbitrary format in advance thru a manual process because the data is constantly changing.

Do you mean you are constantly uploading the audio to the website, like a webcam?

It seems many browsers support HTML5 Audio? But not IE9
http://blog.deepbluesky.com/blog/-/browser-support-for-css3-and-html5_72/

Here's how to test yours:

Like a Webcam without Video! Except only when triggered by an event.

sbright33:
I should explain to prevent confusion. The audio files are generated in real time. I cannot convert them to MP3 or any arbitrary format in advance thru a manual process because the data is constantly changing.

Well there is real time and nearly realtime (delayed by perhaps a few hundred milliseconds).
Keep in mind that if you upload the wav file (already with header added by arduino) to the servers script, it will take that server very little time to make that file in wav available and automatically convert that wav to mp3 and make that available as well.

You also mention that the uploading is only done when triggered by an event, so it's not as if it's like streaming mpeg video like in a IPTV setup and presumably you have a few hundred milliseconds to spare between events that trigger the upload.

I should say near real time. It will take a few seconds after the recording is complete before it can finish sending it to the server, then to the browser. I don't see the need for MP3 conversion, since I plan to use uLaw in addition to PCM. Unless it's simple. Would you be able to help me when I get to that point? CGI or Javascript?

Can the HTML5 Audio object play a uLaw encoded WAV file? On iPhone?
Then I'd only need 1 file format...

sbright33:
Would you be able to help me when I get to that point? CGI or Javascript?

Sure, I prefer Perl over php.
I suggest going for CGI as then it's run server side and you are not relying on the users device having to support js.

Can the HTML5 Audio object play a uLaw encoded WAV file? On iPhone?

Can't say for sure, but my guess would be no, probably only uncompressed PCM.

EDIT:

See here:

Then scroll down to Browser compatibility then click on the tables tabs Desktop or Mobile to check compatibility.

If you want to use .wav headers, you can't upload "in real-time" as in "streaming". The wave file header has a couple fields that require the data size to be known in advance. That means you either have to process the entirety of the audio on the Arduino so you can add the header and upload the whole file at once, or you have to have random access to the file on your server, so you can stream the data, then go back and modify the header once the recording ends. Or you have to record fixed-length chunks.

In terms of codec support, there are usually media plugins that can handle any common format, whether the browser natively supports it or not. If you have QuickTime or WMP or VLC plugins installed and enabled, you shouldn't have to concern yourself with whether the browser understands that format. Test and verify of course.

According to this page, these two voice sample formats are supported by the wave container:

0x0006	WAVE_FORMAT_ALAW	8-bit ITU-T G.711 A-law
0x0007	WAVE_FORMAT_MULAW	8-bit ITU-T G.711 µ-law

Others can be, with the extensible format header.

According to your link PCM in WAV is the only format that works on 3 of the 5 browsers completely including iPhone Safari. Those are my requirements. If I want to include all browsers I have to use a Flash Player in addition, since iPhones don't do Flash. This will be easy since I already have the AU/uLaw file data. The header is only a few constant bytes which do not depend on length. I will process the whole file at once. uLaw does not work together with HTML5 audio in WAV. PCM is required for 3 out of 5 browser compatibility. So I will create 2 files. PCM and AU. Perhaps I will truncate the WAV data to 8 bits while the uLaw stays at 10 for better quality. The file sizes will then be the same. If I choose I can archive the uLaw data only. So much work to do...

Read it again SirNick. Fixed length files! That's a grand idea! Then I can start streaming with the constant WAV header. Since I already know the length I don't have to go back to fix it. No random access or CGI needed. All the processing is done on the microcontroller. I like Simple. Much less RAM needed.

SirNickity:
If you want to use .wav headers, you can't upload "in real-time" as in "streaming". The wave file header has a couple fields that require the data size to be known in advance. That means you either have to process the entirety of the audio on the Arduino so you can add the header and upload the whole file at once, or you have to have random access to the file on your server, so you can stream the data, then go back and modify the header once the recording ends. Or you have to record fixed-length chunks.

Very true, wav is not streaming format.
What I advised sbright33 to do is get either the Arduino to add the required header fields before hand (the easiest method) or upload to the server and the server will add the header and/or also convert to a different format.
Either way, all the data including the header will be present and thus the user can download the sound file.

In terms of codec support, there are usually media plugins that can handle any common format, whether the browser natively supports it or not. If you have QuickTime or WMP or VLC plugins installed and enabled, you shouldn't have to concern yourself with whether the browser understands that format. Test and verify of course.

Yes plug-ins are available but not always for different platforms, plus Quicktime has become such bloatware lately that it's best avoided.

According to this page, these two voice sample formats are supported by the wave container:

0x0006	WAVE_FORMAT_ALAW	8-bit ITU-T G.711 A-law

0x0007 WAVE_FORMAT_MULAW 8-bit ITU-T G.711 µ-law




Others can be, with the extensible format header.

Does that also apply to HTMl 5, I suspect not.
Keep in mind that the whole idea about the

sbright33:
No random access or CGI needed.

Well you will still need CGI depending on how you want to upload the file to the server.
This is pretty simple as most hosting providers already have either Perl or PHP available and uploading scripts are common.

I believe I only need one line of PHP:
file_put_contents('test.WAV', file_get_contents('php://input'));

Technically yes, but you may want to consider things like adding a password and limiting the allowable file size.
Keep in mind that the password will be sent in the clear (i.e. no https) so is not resistant to "man in the middle attack" but will stop casual unwanted uploads by others.
Since you will be adding the header before hand, it makes sense to do some basic checking in the script to ensure the file being uploaded is at least a wav file.

Great advice. You're the most knowledgeable on this topic so far. How about Content-type headers? Are they determined by the file extension automatically? Are they only needed in the HTML5 code? Are they an issue anywhere in this project using HTML5 (not Flash player)?

The most difficult question of all:
Can I use an Electric Imp Agent to directly serve the file to the HTML5 page? I have sent the contents of a file this way before including the WAV headers. The path is binary clean so I don't have to BASE64 encode it.

Saw these tutorials thought they might help

Tutorial: play simple Arduino audio samples
http://dangerousprototypes.com/2011/12/25/tutorial-play-simple-arduino-audio-samples/

Arduino Project 5: Digital audio player

sbright33:
How about Content-type headers? Are they determined by the file extension automatically? Are they only needed in the HTML5 code? Are they an issue anywhere in this project using HTML5 (not Flash player)?

The content-type headers are only applicable to the "download" or users page if the wav is embedded into a html page.
(by embedded I mean referenced to as opposed to the actual binary data being part of the webpage).
If you only provide a direct link to the wav's URL on the server then the users device will get the wav and play it.

Another thing to consider is the mime-type which is part of the servers configuration, however most servers will have the wav ("audio/x-wav" ) set by default.

Have a look at http://www.awardspace.com/ for your hosting needs.
I have used them in the past and no complaints, your millage may vary of course.
They even offer a free option with CGI so you can try with no monetary risk and if you like it you can always upgrade.

The most difficult question of all:
Can I use an Electric Imp Agent to directly serve the file to the HTML5 page? I have sent the contents of a file this way before including the WAV headers. The path is binary clean so I don't have to BASE64 encode it.

You don't need to use Electric Imp Agent or anything else.
All you need to do is a http file upload.

I will dig up some of my scripts that I use for http file uploads, password and file size checking.

@Chris- These are great projects! But I want to record from Uno, and play on iPhone.

I plan on doing it like this:

Content-type headers are not needed?

I know I don't have to use the Electric Imp.
I want to use the Imp, for another related project.
Can I serve the audio file from the Agent to my HTML5 webpage above?