How to capture audio from a browser? - java

My client needs to let a user record a message from the browser, then export the message as an audio file (e.g., WAV).
How is this best accomplished? Flash, Java, HTML5? By best, I mean something that is straightforward to implement and also broadly supported.
What are people's experiences using HTML5?
Thanks!

Flash is one option but you need a media streaming server (Adobe Media Server, Wowza, Red5). There is no way to capture and store audio on Flash locally to a file.
If you are willing to go with Java applets there are multiple solutions. All of them require access to local filesystem and will ask users for additional permissions. For example try http://www.javasonics.com/ or Google "applet record audio".
Update: since Flash 10.0 there is option to use Microphone with SampleDataEvent.SAMPLE_DATA. This gives access to raw audio data from microphone. See this project for implementation: http://code.google.com/p/micrecorder/

Well I suspect that such a feature of HTML5 would be pretty non-standard, and the browser support would differ a lot (with many browsers not including any).
Java is not as popular as flash and there are many people who don't have JRE's at all.
So all in all I would go for the Flash solution in this case. And maybe with an HTML5 fallback for some limited cases, shall resources allow.

Assuming you mean "export" to a server, here is an open-source Flash solution that does NOT require a flash media server:
https://code.google.com/p/wami-recorder/
The recording is transferred via HTTP post to a server-side technology of your choosing. In the simplest case, you can capture and save audio with 4 lines of PHP code:
<?
$content = file_get_contents('php://input');
$fh = fopen('output.wav', 'w') or die("can't open file");
fwrite($fh, $content);
fclose($fh);
?>
As for HTML5 support, keep an eye on getUserMedia()

Related

Java, serve HLS live video streams

I know the topic is not an easy one, but I am looking for a Java class to send an HLS stream from the server to the client.
I have files being generated greater and greater:
out.m3u8
out0.ts
out1.ts
out2.ts
out3.ts
out4.ts
out5.ts
out6.ts
This is generated using ffmpeg from an original source:
ffmpeg -i http://sourceurl.com:9981/stream/channel/1232131 out.m3u8
I can play it using VLC.
Somehow, I need to stream this live to the clients.
At this point, I do not really care about different bit rates, i just want live streaming to work, in mobile browsers and on desktop browsers.
I found this class:
https://github.com/Red5/red5-hls-plugin/blob/master/plugin/src/main/java/org/red5/stream/http/servlet/PlayList.java
Which might be doing something like that.
I have pulled in hls.js into my application in hopes of using it for desktops.
HLS should however work IOS devices without hls.js right now.
How should one serve HLS content from the server? It's very difficult to find any good and simple example to do that.
Anyone knows of the steps needed to do that ?
I've looked into Wowza and Red5 just a little bit, but unsure what they can provide for me at this stage and seems to be overly complicated to setup just to serve some files. But please explain to me why that's not the case.
The H in HLS stands for HTTP. The point of streaming tech such as HLS DASH HDS smooth streaming, etc is that no special server is necessary. Just plain HTTP. you can use something like nginx, or any HTTP server class/library available for Java or any other language.

sound recognition in web

I am building a web page where i need to do something when a particular sound is caught by the microphone. I searched a lot and found this link :
Write a Program Which Recognizes a Sound and Performs Action
I am stuck at two things:
how to use java based sound recognizers though a webpage or
javascript
how to match two sounds (one from the mic. and other from saved file) using any recognizer
For sound recognizer, I am using Sphinx-4 .
To use java sound recognizers, you will need to: either submit/stream the content recorded in the browser, or use a local processing (applet/javafx).
An applet/javafx might not be a bad idea at all; since recording might yield a large data blob, you can do the processing in the local machine. My bet is that the applet will need to be signed to access the mic. You could also stream the audio data to the server, websockets might be a cool shot.
For Javascript, i think you need to use HTML5 for microphone recording or Flash.
For audio comparison, i think you want audio fingerprinting. That is a summary of the audio file. You need to search your own database for the "best match" from what you got among what you have.
I'm not sure Sphinx is the man here. Both Musicg and MusicUri have audio fingerprinting.

Uploading huge files with PHP or any other language?

I have a problem I've been dealing with lately. My application asks its users to upload videos, to be shared with a private community. They are teaching videos, which are not always optimized for web quality to start with. The problem is, many of the videos are huge, way over the 50 megs I've seen in another question. In one case, a video was over a gig, and the only solution I had was to take the client's video from box.net, upload it to the video server via FTP, then associate it with the client's account by updating the database manually. Obviously, we don't want to deal with videos this way, we need it to all be handled automatically.
I've considered using either the box.net or dropbox API to facilitate large uploads, but would rather not go that way if I don't have to. We're using PHP for the main logic of the site, though I'm comfortable with many other languages, especially Python, but including Java, C++, or Perl. If I have to dedicate a whole server or server instance to handling the uploads, I will.
I'd rather do the client-side using native browser JavaScript, instead of Flash or other proprietary tech.
What is the final answer to uploading huge files though the web, by handling the server response in PHP or any other language?
It is possible to raise the limits in Apache and PHP to handle files of this size. The basic HTTP upload mechanism does not offer progressive information, however, so I would usually consider this acceptable only for LAN-type connections.
The normal alternative is to locate a Flash or Javascript uploader widget. These have the bonus that they can display progressive information and will integrate well with a PHP-based website.
For php http://php.net/manual/en/features.file-upload.php
Note the ini files changes in the first comment.
Edit: Assuming you are running into timeout issues.

Is there a way of recording audio of streaming broadcast from a webpage?

I'm looking to create webpage for record streaming audio from source (like online radio).
At first I thought of doing something like recording from speakers, but solutions like flash, java and javascript refer to recording from microphone and not directly from speakers.
Other alternative is to try capturing the streaming and save to local file, but I couldn't find any way of doing so from a webpage.
Solutions like this refer to iPad platfrom, and not suitable for standard webpage.
Any help will be much appreciated, as any development environment (python, ruby, php..).
The sound coming through the system is generally (1) available through one of the TargetDataLines of the Java Sound (sampled) API. Hook into that TargetDataLine & write the bytes directly to disk.
(Assuming you have the right to do so, of course.)
See the Capturing Audio lesson in the Java Tutorial for details. See my answer to JavaSound mixer with both Port(s) and DataLine(s)? for source to easily explore the available data lines. It is probably the "Primary Sound Capture Driver" that you need for this.
Java code must be trusted (or running with no security manager) to eavesdrop on the sound lines.
On some systems Java Sound does not seem to be able to detect all the lines. For those systems, there is little short of a hardware based audio loop-back (e.g. a cable connecting the speaker output back to the microphone) that will fix the problem.

Playing a sound file on website media player

Hey all, i'm new to web development so i'm really dumb when it comes to tools for working on it. I have .amr files recorded from my BB application that are sent and saved on a server. I want to be able to play these files via a webplayer on a website, I have a couple of questions regarding this:
1) Would it be sound to convert these files to something like mp3 o wav instead of trying to play using the amr format? The sound files are received by a java web service and saved as files on my hard drive with the URL saved on a MySQL database. So if a conversion method is suggested I would prefer it be in Java.
2) What player can I use and how, to play these files? Be it the amr files or converted files
3) How can I create a link that will point to said audio file so people can go to it and hear it? I know this differs a little from my original question line but I have to able to do it as well.
thanks in advance
1) MP3 or wav would be a good idea. You could use something like LAMEonJ (http://openinnowhere.sourceforge.net/lameonj/) for wav -> mp3. And with luck there's something similar for AMR.
2) Is the <audio> tag in HTML5 likely to be an option? The users could then play the file directly in the browser, and you could just render HTML on the website, rather than providing it through a webservice.
I think you are suggesting an applet on a web page, that connects to the server via a webservice, which would certainly be possible but a lot more work.
Otherwise, if you're just serving a music file, you're not going to be able to control what player is used on the client side, once they have your file they can do with it whatever they like.
The only down side of HTML5 is that they'll need a relatively recent browser.
3) If you're using <audio> then this is already taken care of.
If you google for the <audio> tag I think you'll find a lot of information,as well as strategies for providing alternative players to older browsers.

Categories