From 507bb63793899ca2df8ab93a3fdddb549b6384d6 Mon Sep 17 00:00:00 2001 From: eunalee Date: Tue, 21 Jun 2022 16:40:40 +0200 Subject: [PATCH] my first push --- record_show/frabjousish.json | 22 + record_show/game.py | 235 +++++ record_show/shusho.json | 21 + record_show/static/js/app.js | 174 ++++ record_show/static/js/recorder.js | 357 +++++++ record_show/static/js2/app.js | 174 ++++ record_show/static/js2/recorder.js | 357 +++++++ record_show/static/js3/app.js | 174 ++++ record_show/static/js3/recorder.js | 357 +++++++ record_show/t offut.json | 17 + record_show/templates/desktop.css | 201 ++++ record_show/templates/index2.html | 235 +++++ record_show/templates/index3.html | 306 ++++++ record_show/templates/index4.html | 246 +++++ record_show/templates/index5.html | 303 ++++++ record_show/templates/index6.html | 246 +++++ record_show/templates/index7.html | 303 ++++++ show/database.json | 1488 ++++++++++++++++++++++++++++ show/show.py | 461 +++++++++ show/templates/desktop.css | 202 ++++ show/templates/jgs7.ttf | Bin 0 -> 25804 bytes show/templates/sh_first.html | 185 ++++ show/templates/sh_g.html | 88 ++ show/templates/sh_response.html | 173 ++++ show/templates/sh_secondgame1.html | 238 +++++ show/templates/sh_secondgame2.html | 296 ++++++ show/templates/sh_submit.html | 129 +++ show/templates/sh_thanks.html | 88 ++ show/templates/sh_thanks2.html | 88 ++ show/templates/sh_transform.html | 239 +++++ 30 files changed, 7403 insertions(+) create mode 100644 record_show/frabjousish.json create mode 100644 record_show/game.py create mode 100644 record_show/shusho.json create mode 100644 record_show/static/js/app.js create mode 100644 record_show/static/js/recorder.js create mode 100644 record_show/static/js2/app.js create mode 100644 record_show/static/js2/recorder.js create mode 100644 record_show/static/js3/app.js create mode 100644 record_show/static/js3/recorder.js create mode 100644 record_show/t offut.json create mode 100644 record_show/templates/desktop.css create mode 100644 record_show/templates/index2.html create mode 100644 record_show/templates/index3.html create mode 100644 record_show/templates/index4.html create mode 100644 record_show/templates/index5.html create mode 100644 record_show/templates/index6.html create mode 100644 record_show/templates/index7.html create mode 100644 show/database.json create mode 100644 show/show.py create mode 100644 show/templates/desktop.css create mode 100644 show/templates/jgs7.ttf create mode 100644 show/templates/sh_first.html create mode 100644 show/templates/sh_g.html create mode 100644 show/templates/sh_response.html create mode 100644 show/templates/sh_secondgame1.html create mode 100644 show/templates/sh_secondgame2.html create mode 100644 show/templates/sh_submit.html create mode 100644 show/templates/sh_thanks.html create mode 100644 show/templates/sh_thanks2.html create mode 100644 show/templates/sh_transform.html diff --git a/record_show/frabjousish.json b/record_show/frabjousish.json new file mode 100644 index 0000000..503df65 --- /dev/null +++ b/record_show/frabjousish.json @@ -0,0 +1,22 @@ +{ + "frabjousish": [ + "frabjousish", + "frabjousish", + "2022-06-12T11:47:29.814Z.wav", + "flazusish", + "2022-06-12T11:58:20.903Z.wav", + "plabjausi", + "2022-06-12T12:11:30.242Z.wav", + "vlabjaous", + "2022-06-13T19:11:20.473Z.wav", + "blabjaz", + "2022-06-13T19:15:51.208Z.wav", + "Blapjass", + "2022-06-13T20:22:26.755Z.wav", + "blapchas", + "2022-06-19T10:41:18.123Z.wav", + "vrabje", + "2022-06-21T12:45:55.996Z.wav", + "t" + ] +} \ No newline at end of file diff --git a/record_show/game.py b/record_show/game.py new file mode 100644 index 0000000..e58419c --- /dev/null +++ b/record_show/game.py @@ -0,0 +1,235 @@ +from flask import Flask, render_template, request, redirect +import os +import json +from datetime import datetime +import pytz + +app = Flask(__name__) +datap = "" + + +@app.route('/r1/') +def game_r1(): + with open("frabjousish.json", "r") as f: + json_file = f.read() + database = json.loads(json_file) + response = database["frabjousish"] + return render_template("index3.html", response = response) + + +@app.route('/r2/') +def game_r2(): + with open("shusho.json", "r") as f: + json_file = f.read() + database = json.loads(json_file) + response = database["shusho"] + return render_template("index5.html", response = response) + + +@app.route('/r3/') +def game_r3(): + with open("t offut.json", "r") as f: + json_file = f.read() + database = json.loads(json_file) + response = database["t offut"] + return render_template("index7.html", response = response) + + +@app.route("/", methods=['POST', 'GET']) +def game(): + + print("frabjousish.json") + print(os.path.exists("frabjousish.json")) + if not os.path.exists("frabjousish.json"): + with open("frabjousish.json", "w") as fra: + frab = { + "frabjousish": ["frabjousish", "frabjousish"] + } + json.dump(frab, fra, indent=1) + + with open("frabjousish.json", "r") as fra: + json_file = fra.read() + data2 = json.loads(json_file) + datap = data2["frabjousish"][-1] + datap2 = data2["frabjousish"][-2] +# type(datap) + + if request.method == 'GET': + return render_template("index2.html", datap=datap, datap2=datap2) + + else: + if ".wav" in datap: + spel = request.form.get('spel') + + with open("frabjousish.json", "r+") as jsonFile: + data = json.load(jsonFile) + data["frabjousish"].append(spel) + + with open("frabjousish.json", "w") as jsonFile: + json.dump(data, jsonFile, indent=1) + + with open("frabjousish.json", "r") as f: + json_file = f.read() + database = json.loads(json_file) + response = database["frabjousish"] + return render_template("index3.html", database = database, response = response, datap=datap, data2=data2) + +# else: +# if request.method == "POST": +# f = request.files['audio_data'] +# filename = f.filename +# with open(f'{ filename }.wav', 'wb') as audio: +# f.save(audio) +# print(f'file uploaded successfully: { filename }.wav') + +# with open("frabjousish.json", "r+") as jsonFile: +# data = json.load(jsonFile) +# data["frabjousish"].append(filename+".wav") + +# with open("frabjousish.json", "w") as jsonFile: +# json.dump(data, jsonFile, indent=1) + +# return render_template('index3.html', datap=datap) +# else: +# return render_template("index3.html") + + +@app.route("/upload/", methods=['POST']) +def game_post(): + if request.method == "POST": + f = request.files['audio_data'] + filename = f.filename + with open(f'{ filename }.wav', 'wb') as audio: + f.save(audio) + print(f'file uploaded successfully: { filename }.wav') + + with open("frabjousish.json", "r+") as jsonFile: + data = json.load(jsonFile) + data["frabjousish"].append(filename+".wav") + + with open("frabjousish.json", "w") as jsonFile: + json.dump(data, jsonFile, indent=1) + return "uploaded" + +@app.route("/g1/", methods=['POST', 'GET']) +def game2(): + + print("shusho.json") + print(os.path.exists("shusho.json")) + if not os.path.exists("shusho.json"): + with open("shusho.json", "w") as fra: + frab = { + "shusho": ["shusho", "shusho"] + } + json.dump(frab, fra, indent=1) + + with open("shusho.json", "r") as fra: + json_file = fra.read() + data2 = json.loads(json_file) + datap = data2["shusho"][-1] + datap2 = data2["shusho"][-2] +# type(datap) + + if request.method == 'GET': + return render_template("index4.html", datap=datap, datap2=datap2) + + else: + if ".wav" in datap: + spel = request.form.get('spel') + + with open("shusho.json", "r+") as jsonFile: + data = json.load(jsonFile) + data["shusho"].append(spel) + + with open("shusho.json", "w") as jsonFile: + json.dump(data, jsonFile, indent=1) + + with open("shusho.json", "r") as f: + json_file = f.read() + database = json.loads(json_file) + response = database["shusho"] + return render_template("index5.html", database = database, response = response, datap=datap, data2=data2) + + +@app.route("/upload2/", methods=['POST']) +def game2_post(): + if request.method == "POST": + f = request.files['audio_data'] + filename = f.filename + with open(f'{ filename }.wav', 'wb') as audio: + f.save(audio) + print(f'file uploaded successfully: { filename }.wav') + + with open("shusho.json", "r+") as jsonFile: + data = json.load(jsonFile) + data["shusho"].append(filename+".wav") + + with open("shusho.json", "w") as jsonFile: + json.dump(data, jsonFile, indent=1) + return "uploaded" + + + +@app.route("/g2/", methods=['POST', 'GET']) +def game3(): + + print("t offut.json") + print(os.path.exists("t offut.json")) + if not os.path.exists("t offut.json"): + with open("t offut.json", "w") as fra: + frab = { + "t offut": ["t offut", "t offut"] + } + json.dump(frab, fra, indent=1) + + with open("t offut.json", "r") as fra: + json_file = fra.read() + data2 = json.loads(json_file) + datap = data2["t offut"][-1] + datap2 = data2["t offut"][-2] +# type(datap) + + if request.method == 'GET': + return render_template("index6.html", datap=datap, datap2=datap2) + + else: + if ".wav" in datap: + spel = request.form.get('spel') + + with open("t offut.json", "r+") as jsonFile: + data = json.load(jsonFile) + data["t offut"].append(spel) + + with open("t offut.json", "w") as jsonFile: + json.dump(data, jsonFile, indent=1) + + with open("t offut.json", "r") as f: + json_file = f.read() + database = json.loads(json_file) + response = database["t offut"] + return render_template("index7.html", database = database, response = response, datap=datap, data2=data2) + + +@app.route("/upload3/", methods=['POST']) +def game3_post(): + if request.method == "POST": + f = request.files['audio_data'] + filename = f.filename + with open(f'{ filename }.wav', 'wb') as audio: + f.save(audio) + print(f'file uploaded successfully: { filename }.wav') + + with open("t offut.json", "r+") as jsonFile: + data = json.load(jsonFile) + data["t offut"].append(filename+".wav") + + with open("t offut.json", "w") as jsonFile: + json.dump(data, jsonFile, indent=1) + return "uploaded" + + +if __name__ == "__main__": + + app.run(debug=True, port=5050) + + \ No newline at end of file diff --git a/record_show/shusho.json b/record_show/shusho.json new file mode 100644 index 0000000..63ca3fe --- /dev/null +++ b/record_show/shusho.json @@ -0,0 +1,21 @@ +{ + "shusho": [ + "shusho", + "shusho", + "2022-06-13T19:12:24.264Z.wav", + "chouchau", + "2022-06-13T19:24:45.263Z.wav", + "Chocho", + "2022-06-13T19:44:02.689Z.wav", + "chocho", + "2022-06-13T22:35:12.067Z.wav", + "chock chock", + "2022-06-13T22:35:12.067Z.wav", + "tchotchop", + "2022-06-19T12:03:18.841Z.wav", + "peuzau", + "2022-06-20T08:58:28.203Z.wav", + "lei zaaar", + "2022-06-21T12:47:24.960Z.wav" + ] +} \ No newline at end of file diff --git a/record_show/static/js/app.js b/record_show/static/js/app.js new file mode 100644 index 0000000..7fe9103 --- /dev/null +++ b/record_show/static/js/app.js @@ -0,0 +1,174 @@ +// Source: https://stackoverflow.com/questions/60032983/record-voice-with-recorder-js-and-upload-it-to-python-flask-server-but-wav-file + +//webkitURL is deprecated but nevertheless +URL = window.URL || window.webkitURL; + +var gumStream; //stream from getUserMedia() +var rec; //Recorder.js object +var input; //MediaStreamAudioSourceNode we'll be recording + +// shim for AudioContext when it's not avb. +var AudioContext = window.AudioContext || window.webkitAudioContext; +var audioContext //audio context to help us record + +var recordButton = document.getElementById("recordButton"); +var stopButton = document.getElementById("stopButton"); +var pauseButton = document.getElementById("pauseButton"); + +//add events to those 2 buttons +recordButton.addEventListener("click", startRecording); +stopButton.addEventListener("click", stopRecording); +pauseButton.addEventListener("click", pauseRecording); + +function startRecording() { + console.log("recordButton clicked"); + + /* + Simple constraints object, for more advanced audio features see + https://addpipe.com/blog/audio-constraints-getusermedia/ + */ + + var constraints = { audio: true, video:false } + + /* + Disable the record button until we get a success or fail from getUserMedia() + */ + + recordButton.disabled = true; + stopButton.disabled = false; + pauseButton.disabled = false + + /* + We're using the standard promise based getUserMedia() + https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/getUserMedia + */ + + navigator.mediaDevices.getUserMedia(constraints).then(function(stream) { + console.log("getUserMedia() success, stream created, initializing Recorder.js ..."); + + /* + create an audio context after getUserMedia is called + sampleRate might change after getUserMedia is called, like it does on macOS when recording through AirPods + the sampleRate defaults to the one set in your OS for your playback device + + */ + audioContext = new AudioContext(); + + //update the format + //document.getElementById("formats").innerHTML="Format: 1 channel pcm @ "+audioContext.sampleRate/1000+"kHz" + + /* assign to gumStream for later use */ + gumStream = stream; + + /* use the stream */ + input = audioContext.createMediaStreamSource(stream); + + /* + Create the Recorder object and configure to record mono sound (1 channel) + Recording 2 channels will double the file size + */ + rec = new Recorder(input,{numChannels:1}) + + //start the recording process + rec.record() + + console.log("Recording started"); + + }).catch(function(err) { + //enable the record button if getUserMedia() fails + recordButton.disabled = false; + stopButton.disabled = true; + pauseButton.disabled = true + }); +} + +function pauseRecording(){ + console.log("pauseButton clicked rec.recording=",rec.recording ); + if (rec.recording){ + //pause + rec.stop(); + pauseButton.innerHTML="Resume"; + }else{ + //resume + rec.record() + pauseButton.innerHTML="Pause"; + + } +} + +function stopRecording() { + console.log("stopButton clicked"); + + //disable the stop button, enable the record too allow for new recordings + stopButton.disabled = true; + recordButton.disabled = false; + pauseButton.disabled = true; + + //reset button just in case the recording is stopped while paused + pauseButton.innerHTML="Pause"; + + //tell the recorder to stop the recording + rec.stop(); + + //stop microphone access + gumStream.getAudioTracks()[0].stop(); + + //create the wav blob and pass it on to createDownloadLink + rec.exportWAV(createDownloadLink); +} + +function createDownloadLink(blob) { + + var url = URL.createObjectURL(blob); + var au = document.createElement('audio'); + var li = document.createElement('li'); + var link = document.createElement('a'); + + //name of .wav file to use during upload and download (without extendion) + var filename = new Date().toISOString(); + console.log('filename', filename) + + //add controls to the