H5 operation sound recording / playback method

Xiaobian to share the H5 operation sound recording / playback method, I believe that most people don’t know much, so share this article to everyone, I hope everyone has a big harvest after reading this article. Let’s take a look at it!

HTML code:

  H5 call sound         

VAR Recorder; var Audio = Document.QuerySelector 'Audio'); Function StartRecording () {hzrecorder.get (Function (REC) {Recorder = Rec; Recorder.Start ();}, {SampleBits: 16, SampleRate: 16000});} FunctionStopRecording () {recorder.stop (); var blob = recorder.getblob (); var URL = url.createObjectURL (blob); var p = document.createElement ('p'); var au = document.createElement ('AUDIO '); var hf = document.createElement (' a '); au.controls = true; au.src = url; hf.href = url; hf.download = new date (). toisostring () +' .wav ' ; hf.innerHTML = hf.download; p.appendChild (au); p.appendChild (hf); recordingslist.appendChild (p);} function playRecording () {recorder.play (audio);} function uploadAudio () {recOrder.upload ("Handler1.ASHX", Function (State, E) {switch (state) {copy 'uploading': // var percentcomplete = math.round (E.LOADED * 100 / E.TOTAL) + '%' Break; Case 'OK': //Alert ("Upload Success"); Break; Case 'Error': Alert ("Upload Failed"); Break; Case 'Cancel': Alert ("Upload canceled"); Break;}});}
HzRecorder.js

(function (window) {// compatible window.URL = window.URL || window.webkitURL; navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia; Var hzrecorder = function (stream, config) {config = config || {}; config.samplebits = config.samplebits || 8 // Sample number 8, 16 config.samplerate = config.samplerate || (44100/6); // sampling rate (1/6 44100) var context = new (window.webkitAudioContext || window.AudioContext) (); var audioInput = context.createMediaStreamSource (stream); var createScript = context.createScriptProcessor || context.createJavaScriptNode; var Recorder = Createscript.Apply (Context, [4096, 1, 1]); Var Mp3ReceiveSuccess, CurrenterRorCallback; VAR Audiodata = {Size: 0 // Recording file length, buffer: [] // Record cache, input.samplete // Enter the sample rate, inputsamplebits: 16 // Enter sample number 8, 16, OutputSample: config .samplerate // output sampling rate, OututsampleBits: config.samplebits // Output sampling number 8, 16, input: function (data) {this.buffer.push (new float32aray (data)); this.size + = data.length ;}, compress: function () {// Merge compression // Merge var data = new float32Array (this.size); var offset = 0; for (var i = 0; i The above is all the contents of the H5 operation sound recording / playback, thank you for reading! I believe everyone has a certain understanding, I hope to share the content, if you want to learn more knowledge, welcome attention TumiCloud Industry Information Channel!
© Copyright Notice
THE END
Just support it if you like
like0
share
comment Grab the couch

Please log in to comment