18

It seems I can only use Flash or Java to record voice on a web app. Is there a way of doing it via JavaScript?

Philip Kirkbride
  • 17,347
  • 30
  • 101
  • 195
Tsundoku
  • 8,114
  • 26
  • 88
  • 125
  • 2
    http://stackoverflow.com/questions/12149451/how-can-i-record-a-users-voice-using-javascript-php – karaxuna Feb 26 '13 at 06:24
  • Possible duplicate of [How can I record a user's voice using Javascript/PHP?](https://stackoverflow.com/questions/12149451/how-can-i-record-a-users-voice-using-javascript-php) – Ishara Amarasekera Jul 10 '19 at 07:37

4 Answers4

16

It can be done but the solution won't work across all platforms at the moment.

<input type="file" accept="audio/*;capture=microphone">

See HTML5 Media Capture

Currently Supported By:

Android 3.0 browser, Chrome for Android (0.16), Firefox Mobile 10.0, iOS6 Safari and Chrome (partial support)

Links:

http://www.html5rocks.com/en/tutorials/getusermedia/intro/

Audio capturing with HTML5

Community
  • 1
  • 1
Philip Kirkbride
  • 17,347
  • 30
  • 101
  • 195
  • iOS (all versions up to 9) does not support recording only audio through HTML5 Media Capture. Safari on iOS will bring up the photo/video recording app. – Octavian Naicu Oct 02 '15 at 13:47
  • Some great screenshots with HTML Media Capture in Safari on iOS9 https://addpipe.com/blog/the-new-video-recording-prompt-for-media-capture-in-ios9/ – Octavian Naicu Oct 02 '15 at 14:14
4

Javascript cannot access your hardware directly. What you need, is a client side technology that can. Flash, for one.

Javascript can communicate quite easily with flash, so you can hide your flash recorder and construct your recorder ui with html/js/css.

Here's one example: https://github.com/jwagener/recorder.js/blob/master/examples/example-1.html

Here's another one: http://blogupstairs.com/flashwavrecorder-javascript-flash-audio-recorder/

I realize this is not EXACTLY what you need, but you didn't tell why you want a JS solution. This doesn't fix the flash dependency problem but it solves the UI problem since you can construct the UI without flash.

Jani Hyytiäinen
  • 4,804
  • 32
  • 45
1

Another wellknow solution is WAMI, I know it's not pure javascript but maybe it can help.

"As of this writing, most browsers still do not support WebRTC's getUserMedia(), which promises to give web developers microphone access via Javascript. This project achieves the next best thing for browsers that support Flash. Using the WAMI recorder, you can collect audio on your server without installing any proprietary media server software." https://code.google.com/p/wami-recorder/

Another example using node.js This example application is written in JavaScript and uses Node and Express for the web server and framework. You will need all three installed on your web server in order for this to work, as well as the Node.js WebAPI Library. nodejs voice recording example

tarcnux
  • 63
  • 7
1

Yes there is a pure HTML/JavaScript way but it only works in Firefox and Chrome: http://audior.ec/blog/recording-mp3-using-only-html5-and-javascript-recordmp3-js/

Direct demo: http://audior.ec/recordmp3js/

Octavian Naicu
  • 2,731
  • 26
  • 44