Pages: 1 2 [3]   Go Down
Author Topic: How to play Raw audio?  (Read 3380 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Edison Member
*
Karma: 8
Posts: 1341
If you're not living on the Edge, you're taking up too much space!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

If you fall... I'll be there for you!
-Floor

Skype Brighteyes3333
(262) 696-9619

South Africa
Offline Offline
Newbie
*
Karma: 0
Posts: 1
Marriage is what you make it
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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
http://apcmag.com/arduino-project-5-digital-audio-player.htm
Logged

Live life

Offline Offline
Sr. Member
****
Karma: 7
Posts: 468
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.

Quote
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.
Logged

Offline Offline
Edison Member
*
Karma: 8
Posts: 1341
If you're not living on the Edge, you're taking up too much space!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

If you fall... I'll be there for you!
-Floor

Skype Brighteyes3333
(262) 696-9619

Offline Offline
Edison Member
*
Karma: 8
Posts: 1341
If you're not living on the Edge, you're taking up too much space!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I plan on doing it like this:
http://www.w3schools.com/html/html5_audio.asp
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?
Logged

If you fall... I'll be there for you!
-Floor

Skype Brighteyes3333
(262) 696-9619

Offline Offline
Sr. Member
****
Karma: 7
Posts: 468
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I plan on doing it like this:
http://www.w3schools.com/html/html5_audio.asp
Content-type headers are not needed?

If your wav is "part" of a fancier web page i.e.
Code:
<audio controls>
  <source src="sound.wav" type="audio/wav">
  <source src="sound.mp3" type="audio/mpeg">
Your browser does not support the audio element.
</audio>

then as I wrote previously, yes you need them, however if you are only giving the users a URL directly to your sound file:
i.e.
h t t p://www.YourWebSite.com/YourSoundFIle.wav
then you don't need it.

BTW, if you know before hand that all users devices handle the wav format, then you can dispense with the extra code in the html code above which the browser interprets as follows:

Code:
<audio controls> 
If available and can play it, then play this one ----->  sound.wav
else if not available or can't play the one above, try this one ---->  sound.mp3
if can't find or play either, display this message ------->  Your browser does not support the audio element.
</audio>

Quote
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?

You will have to check the compatibility (permissions, any modules to be loaded on server) with your hosting provider.
« Last Edit: November 13, 2013, 01:07:37 pm by UnoDueTre » Logged

Offline Offline
Edison Member
*
Karma: 8
Posts: 1341
If you're not living on the Edge, you're taking up too much space!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm doing it like in the example I linked above.  So I need them.  What does need them mean?  Just specify them in the HTML5 code like above?  What if the wav file is coming from another host?  How does it send the  Content-type headers?
Logged

If you fall... I'll be there for you!
-Floor

Skype Brighteyes3333
(262) 696-9619

Offline Offline
Sr. Member
****
Karma: 7
Posts: 468
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Just specify them in the HTML5 code like above?  
Yes.

Quote
What if the wav file is coming from another host?  How does it send the  Content-type headers?

I don't quite understand your question.
Are you saying that the html page is on one server and the wav file on another?
If that is the case, then you would put the fully qualified URL of the wav file on the other server in the code.
Note however that depending on server settings, some admins are over paranoid about things like cross-site scripting and set the permissions wrongly and it has unwanted side effects of which one is blocking what you are trying to achieve.

You can certainly try:

Code:
<audio controls>
  <source src="http://www.TheOtherServer.com/sound.wav" type="audio/wav">
</audio>

Now this is where it gets interesting with mime-types and content-types.
The other server is simply feeding a resource of type wav/x-wav as specified in the mime-types section of it's config and so it's happy, the actual server which has the html code, may need the content-type depending on how it's set up even though it's not actually feeding client with the resource.
Some browsers also require it to be present to select the right codec to play it whilst some make the decision based on the extension.
Either way it will not hurt to include it.

EDIT:

Welcome to the supposed standard of html.  smiley
There are plenty of these oddities, for example how different browsers handle the ACCESSKEY tag and even the ALT tag for images which are not standard on all browsers.
Firefox and Chrome also handle the new graphics capabilities of html 5 differently causing lots of mayhem and confusion.
« Last Edit: November 13, 2013, 02:14:31 pm by UnoDueTre » Logged

Offline Offline
Sr. Member
****
Karma: 0
Posts: 351
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

No experience in streaming data online, but if you have the chance to choose the data format you have a few options...
WAVE PCM 8 bit is unsigned( probably the easiest and lighter to implement on a uC ( good for speech); 16 bit unsigned if you need more quality. Anything else might be a bit too much to handle in real time, specially if the sound is not the main aim of your project/code.
Or just PCM , given the chance, of course !
I started documenting the WAVE format from an embedded pont of view, as an option to an add-on for one of my projects.... Gives you a good insight into other related formats as well  AVI, RIFF and compression related ones, etc.
Hope it comes handy !
http://dubworks.blogspot.co.uk/2013/11/wav-file-format-and-brief-intro-into.html
« Last Edit: November 16, 2013, 08:07:29 pm by iyahdub » Logged

10 LET Loop=Infinite
20 GO TO 10

Pages: 1 2 [3]   Go Up
Jump to: