Skip to content
This repository was archived by the owner on Jan 12, 2023. It is now read-only.

Commit 610337d

Browse files
committed
Adds client audio recording feature
1 parent 79534c1 commit 610337d

File tree

5 files changed

+49
-4
lines changed

5 files changed

+49
-4
lines changed

camera.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,8 @@ def record(self,upload, cloud):
101101
cloud.upload_file(f, 'video' + timestr + ".avi")
102102

103103

104-
104+
def playAudio(self):
105+
winsound.PlaySound("audio.wav", winsound.SND_FILENAME)
105106
def endVideo(self):
106107
self.recording = False
107108

cloud.py

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import dropbox
2-
import config
32
class DropObj(object):
43
def __init__(self, conf):
54
self.app_key = 'ck2ifx3agl50908'

server.py

+7
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,13 @@ def gen(camera, save=False, vstart=False):
6363
yield (b'--frame\r\n'
6464
b'Content-Type: image/jpeg\r\n\r\n' + frame + b'\r\n\r\n')
6565

66+
@app.route('/audio', methods=['POST'])
67+
@auth.login_required
68+
def audio():
69+
file = request.files['edition[audio]']
70+
file.save("audio.wav")
71+
cmra.playAudio()
72+
return ('', 204)
6673
@app.route('/video_feed')
6774
@auth.login_required
6875
def video_feed():

static/application.js

+38-1
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,41 @@ $(document).ready(function(){
5353
$("#btn-cloud").toggleClass('btn-info');
5454
$("#cloud-note").toggle("slow");
5555
});
56-
});
56+
var recordRTC = null;
57+
$("#btn-sound").click(function(e){
58+
e.preventDefault();
59+
60+
if ($("#btn-sound").hasClass('btn-danger')){
61+
recordRTC.stopRecording(function(audioURL) {
62+
var formData = new FormData();
63+
formData.append('edition[audio]', recordRTC.getBlob())
64+
var uri = location.href + 'audio';
65+
66+
$.ajax({
67+
type: 'POST',
68+
url: uri,
69+
data: formData,
70+
contentType: false,
71+
cache: false,
72+
processData: false,
73+
})
74+
});
75+
}
76+
else
77+
{
78+
var session = {
79+
audio: true,
80+
video: false
81+
};
82+
83+
navigator.getUserMedia(session, function (MediaStream) {
84+
recordRTC = RecordRTC(MediaStream);
85+
recordRTC.startRecording();
86+
}, onError);
87+
}
88+
$("#btn-sound").toggleClass('btn-danger');
89+
})
90+
});
91+
function onError() {
92+
console.log("ERROR");
93+
}

templates/index.html

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap-theme.min.css">
99
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
1010
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
11+
<script src="//cdn.WebRTC-Experiment.com/RecordRTC.js"></script>
1112
<script type="text/javascript" src="{{ url_for('static', filename='application.js') }}"></script>
1213
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='addtohomescreen.css') }}">
1314
<script src="{{ url_for('static', filename='addtohomescreen.js') }}"></script>
@@ -122,7 +123,7 @@ <h3 align="left">Stream</h3>
122123

123124

124125
<button type="button" id="btn-image" class="btn btn-success" title="Capture a Photo" onclick="document.location.href='get_frame?options=save';"><span class="glyphicon glyphicon-camera"/></button>
125-
<button type="button" id="btn-sound" class="btn btn-success" title="Include sound" onclick="alert('feture in develop...')";><span class="glyphicon glyphicon-volume-up"/></button>
126+
<button type="button" id="btn-sound" class="btn btn-success" title="Record yourself and play it at home" ><span class="glyphicon glyphicon-volume-up"/></button>
126127
<button type="button" id="btn-lg2" class="btn btn-success" title="Download a Photo" onclick="document.location.href='get_frame';"><span class="glyphicon glyphicon-download-alt"/></button>
127128

128129
</div>

0 commit comments

Comments
 (0)