html5实现录音、拍摄功能

<span style="white-space:pre"></span><audio controls autoplay></audio>  
<input type="button" value="开始录音" onclick="startRecording()"/>  
<input type="button" value="获取录音" onclick="obtainRecord()"/>  
<input type="button" value="停止录音" onclick="stopRecord()"/>  
<input type="button" value="播放录音" onclick="playRecord()"/>  
  
<video id="video1" width="320px" height="240px" controls autoplay ></video>  
<video id="video2" width="320px" height="240px" controls autoplay ></video>  
<canvas id="canvas1" width="320" height="240"></canvas>  
<input type="button" value="拍摄" onclick="scamera()"/>  
<input type="button" value="播放视频" onclick="playVideo()"/> 
(function (window) {  
    //兼容  
    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;      //采样数位 8, 16  
        config.sampleRate = config.sampleRate || (44100 / 6);   //采样率(1/6 44100)  
  
          
        //创建一个音频环境对象  
        audioContext = window.AudioContext || window.webkitAudioContext;  
        var context = new audioContext();  
  
        //将声音输入这个对像  
        var audioInput = context.createMediaStreamSource(stream);  
          
        //设置音量节点  
        var volume = context.createGain();  
        audioInput.connect(volume);  
  
        //创建缓存,用来缓存声音  
        var bufferSize = 4096;  
  
        // 创建声音的缓存节点,createScriptProcessor方法的  
        // 第二个和第三个参数指的是输入和输出都是双声道。  
        var recorder = context.createScriptProcessor(bufferSize, 2, 2);  
  
        var audioData = {  
            size: 0          //录音文件长度  
            , buffer: []     //录音缓存  
            , inputSampleRate: context.sampleR
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值