Spaces:
Running
Running
Update templates/index.html
Browse files- templates/index.html +315 -320
templates/index.html
CHANGED
@@ -1,321 +1,316 @@
|
|
1 |
-
<!DOCTYPE html>
|
2 |
-
<html lang="ja">
|
3 |
-
<head>
|
4 |
-
<meta charset="UTF-8" />
|
5 |
-
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
6 |
-
<title>Voice Recorder Interface</title>
|
7 |
-
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
|
8 |
-
<script src="https://cdn.tailwindcss.com"></script>
|
9 |
-
</head>
|
10 |
-
<body class="flex flex-col items-center justify-center h-screen bg-gray-900 text-white">
|
11 |
-
<!-- メンバーを登録ボタン -->
|
12 |
-
<div class="flex items-center mb-5">
|
13 |
-
<button
|
14 |
-
id="registerButton"
|
15 |
-
onclick="showUserRegister()"
|
16 |
-
class="px-4 py-2 bg-blue-600 rounded-md hover:bg-blue-700 transition"
|
17 |
-
>
|
18 |
-
メンバーを登録
|
19 |
-
</button>
|
20 |
-
</div>
|
21 |
-
|
22 |
-
<!-- チャート表示部 -->
|
23 |
-
<div class="chart w-72 h-72 mb-5">
|
24 |
-
<canvas id="speechChart"></canvas>
|
25 |
-
</div>
|
26 |
-
|
27 |
-
<!-- 録音フォーム -->
|
28 |
-
<form
|
29 |
-
id="recordForm"
|
30 |
-
action="/submit"
|
31 |
-
method="POST"
|
32 |
-
class="flex items-center space-x-2 w-full sm:w-auto"
|
33 |
-
onsubmit="event.preventDefault();"
|
34 |
-
>
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
}
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
let
|
95 |
-
|
96 |
-
|
97 |
-
let
|
98 |
-
let
|
99 |
-
let
|
100 |
-
|
101 |
-
//
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
if (!
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
updateChart();
|
155 |
-
}
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
speechChart.data.
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
};
|
200 |
-
|
201 |
-
mediaRecorder.
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
|
312 |
-
window.location.href = "
|
313 |
-
}
|
314 |
-
|
315 |
-
|
316 |
-
fetch("/reset");
|
317 |
-
window.location.href = "userregister";
|
318 |
-
}
|
319 |
-
</script>
|
320 |
-
</body>
|
321 |
</html>
|
|
|
1 |
+
<!DOCTYPE html>
|
2 |
+
<html lang="ja">
|
3 |
+
<head>
|
4 |
+
<meta charset="UTF-8" />
|
5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
6 |
+
<title>Voice Recorder Interface</title>
|
7 |
+
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
|
8 |
+
<script src="https://cdn.tailwindcss.com"></script>
|
9 |
+
</head>
|
10 |
+
<body class="flex flex-col items-center justify-center h-screen bg-gray-900 text-white">
|
11 |
+
<!-- メンバーを登録ボタン -->
|
12 |
+
<div class="flex items-center mb-5">
|
13 |
+
<button
|
14 |
+
id="registerButton"
|
15 |
+
onclick="showUserRegister()"
|
16 |
+
class="px-4 py-2 bg-blue-600 rounded-md hover:bg-blue-700 transition"
|
17 |
+
>
|
18 |
+
メンバーを登録
|
19 |
+
</button>
|
20 |
+
</div>
|
21 |
+
|
22 |
+
<!-- チャート表示部 -->
|
23 |
+
<div class="chart w-72 h-72 mb-5">
|
24 |
+
<canvas id="speechChart"></canvas>
|
25 |
+
</div>
|
26 |
+
|
27 |
+
<!-- 録音フォーム -->
|
28 |
+
<form
|
29 |
+
id="recordForm"
|
30 |
+
action="/submit"
|
31 |
+
method="POST"
|
32 |
+
class="flex items-center space-x-2 w-full sm:w-auto"
|
33 |
+
onsubmit="event.preventDefault();"
|
34 |
+
>
|
35 |
+
|
36 |
+
<!-- 録音ボタン -->
|
37 |
+
<button type="button" class="record-button" id="recordButton" onclick="toggleRecording()">
|
38 |
+
<div class="record-icon" id="recordIcon"></div>
|
39 |
+
</button>
|
40 |
+
</form>
|
41 |
+
|
42 |
+
<!-- 結果ボタン -->
|
43 |
+
<div class="flex mt-5">
|
44 |
+
<button
|
45 |
+
id="historyButton"
|
46 |
+
onclick="showTalkdetail()"
|
47 |
+
class="result-button px-4 py-2 mx-2 bg-green-600 rounded-md hover:bg-green-700 transition"
|
48 |
+
>
|
49 |
+
会話履歴を表示
|
50 |
+
</button>
|
51 |
+
<button
|
52 |
+
id="feedbackButton"
|
53 |
+
onclick="showResults()"
|
54 |
+
class="result-button px-4 py-2 mx-2 bg-blue-600 rounded-md hover:bg-blue-700 transition"
|
55 |
+
>
|
56 |
+
フィードバック画面を表示
|
57 |
+
</button>
|
58 |
+
</div>
|
59 |
+
|
60 |
+
<style>
|
61 |
+
.record-button {
|
62 |
+
width: 80px;
|
63 |
+
height: 80px;
|
64 |
+
background-color: transparent;
|
65 |
+
border-radius: 50%;
|
66 |
+
border: 4px solid white;
|
67 |
+
display: flex;
|
68 |
+
justify-content: center;
|
69 |
+
align-items: center;
|
70 |
+
cursor: pointer;
|
71 |
+
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.4);
|
72 |
+
transition: all 0.2s ease;
|
73 |
+
}
|
74 |
+
.record-icon {
|
75 |
+
width: 60px;
|
76 |
+
height: 60px;
|
77 |
+
background-color: #d32f2f;
|
78 |
+
border-radius: 50%;
|
79 |
+
transition: all 0.2s ease;
|
80 |
+
}
|
81 |
+
.recording .record-icon {
|
82 |
+
width: 40px;
|
83 |
+
height: 40px;
|
84 |
+
border-radius: 10%;
|
85 |
+
}
|
86 |
+
</style>
|
87 |
+
|
88 |
+
<script>
|
89 |
+
let isRecording = false;
|
90 |
+
let mediaRecorder;
|
91 |
+
let audioChunks = [];
|
92 |
+
let recordingInterval;
|
93 |
+
let count_voice = 0;
|
94 |
+
let before_rate = 0;
|
95 |
+
|
96 |
+
// メンバーとチャートの初期化
|
97 |
+
let members = [];
|
98 |
+
let voiceData = [];
|
99 |
+
let baseMemberColors = ["#4caf50", "#007bff", "#ffc107", "#dc3545", "#28a745", "#9c27b0", "#ff9800"];
|
100 |
+
|
101 |
+
// Chart.js の初期化
|
102 |
+
const ctx = document.getElementById("speechChart").getContext("2d");
|
103 |
+
const speechChart = new Chart(ctx, {
|
104 |
+
type: "doughnut",
|
105 |
+
data: {
|
106 |
+
labels: members,
|
107 |
+
datasets: [
|
108 |
+
{
|
109 |
+
data: voiceData,
|
110 |
+
backgroundColor: getMemberColors(members.length),
|
111 |
+
},
|
112 |
+
],
|
113 |
+
},
|
114 |
+
options: {
|
115 |
+
responsive: true,
|
116 |
+
plugins: {
|
117 |
+
legend: {
|
118 |
+
display: true,
|
119 |
+
position: "bottom",
|
120 |
+
labels: { color: "white" },
|
121 |
+
},
|
122 |
+
},
|
123 |
+
},
|
124 |
+
});
|
125 |
+
|
126 |
+
// サーバーからメンバー情報を取得してチャートを更新する関数
|
127 |
+
async function updateChartFrom() {
|
128 |
+
try {
|
129 |
+
const response = await fetch("/confirm");
|
130 |
+
if (!response.ok) {
|
131 |
+
throw new Error(`HTTP error! status: ${response.status}`);
|
132 |
+
}
|
133 |
+
const data = await response.json();
|
134 |
+
|
135 |
+
if (!data || !data.members || !Array.isArray(data.members)) {
|
136 |
+
console.error("Invalid member data received:", data);
|
137 |
+
members = ["member1"];
|
138 |
+
voiceData = [50, 50];
|
139 |
+
updateChart();
|
140 |
+
return;
|
141 |
+
}
|
142 |
+
|
143 |
+
members = data.members;
|
144 |
+
voiceData = [];
|
145 |
+
for (let i = 0; i < members.length; i++) {
|
146 |
+
voiceData.push(100 / members.length);
|
147 |
+
}
|
148 |
+
|
149 |
+
updateChart();
|
150 |
+
} catch (error) {
|
151 |
+
console.error("Failed to fetch member data:", error);
|
152 |
+
members = ["member1"];
|
153 |
+
voiceData = [50, 50];
|
154 |
+
updateChart();
|
155 |
+
}
|
156 |
+
}
|
157 |
+
|
158 |
+
function updateChart() {
|
159 |
+
// 一人モードの場合は、ユーザーとグレー(無音)の比率をチャートに表示
|
160 |
+
if (members.length === 1) {
|
161 |
+
const userName = members[0];
|
162 |
+
speechChart.data.labels = [userName, "無音"];
|
163 |
+
speechChart.data.datasets[0].backgroundColor = ["#4caf50", "#757575"];
|
164 |
+
} else {
|
165 |
+
// 複数メンバーの場合は通常通りの処理
|
166 |
+
speechChart.data.labels = members;
|
167 |
+
speechChart.data.datasets[0].backgroundColor = getMemberColors(members.length);
|
168 |
+
}
|
169 |
+
|
170 |
+
speechChart.data.datasets[0].data = voiceData;
|
171 |
+
speechChart.update();
|
172 |
+
}
|
173 |
+
|
174 |
+
// ページ読み込み時にチャート情報を更新
|
175 |
+
updateChartFrom();
|
176 |
+
|
177 |
+
// 録音ボタンの録音開始/停止処理
|
178 |
+
async function toggleRecording() {
|
179 |
+
const recordButton = document.getElementById("recordButton");
|
180 |
+
|
181 |
+
if (!isRecording) {
|
182 |
+
// 録音開始
|
183 |
+
isRecording = true;
|
184 |
+
recordButton.classList.add("recording");
|
185 |
+
try {
|
186 |
+
const stream = await navigator.mediaDevices.getUserMedia({ audio: true });
|
187 |
+
mediaRecorder = new MediaRecorder(stream);
|
188 |
+
audioChunks = [];
|
189 |
+
|
190 |
+
mediaRecorder.ondataavailable = (event) => {
|
191 |
+
if (event.data.size > 0) {
|
192 |
+
audioChunks.push(event.data);
|
193 |
+
}
|
194 |
+
};
|
195 |
+
|
196 |
+
mediaRecorder.onstop = () => {
|
197 |
+
sendAudioChunks([...audioChunks]);
|
198 |
+
audioChunks = [];
|
199 |
+
};
|
200 |
+
|
201 |
+
mediaRecorder.start();
|
202 |
+
} catch (error) {
|
203 |
+
console.error("マイクへのアクセスに失敗しました:", error);
|
204 |
+
isRecording = false;
|
205 |
+
recordButton.classList.remove("recording");
|
206 |
+
}
|
207 |
+
} else {
|
208 |
+
// 録音停止
|
209 |
+
isRecording = false;
|
210 |
+
recordButton.classList.remove("recording");
|
211 |
+
if (mediaRecorder && mediaRecorder.state === "recording") {
|
212 |
+
mediaRecorder.stop();
|
213 |
+
count_voice = 0;
|
214 |
+
before_rate = 0;
|
215 |
+
}
|
216 |
+
}
|
217 |
+
}
|
218 |
+
|
219 |
+
function sendAudioChunks(chunks) {
|
220 |
+
const audioBlob = new Blob(chunks, { type: "audio/wav" });
|
221 |
+
const reader = new FileReader();
|
222 |
+
reader.onloadend = () => {
|
223 |
+
const base64String = reader.result.split(",")[1];
|
224 |
+
const form = document.getElementById("recordForm");
|
225 |
+
const nameInput = form.querySelector('input[name="name"]');
|
226 |
+
const name = nameInput ? nameInput.value : "unknown";
|
227 |
+
fetch("/upload_audio", {
|
228 |
+
method: "POST",
|
229 |
+
headers: { "Content-Type": "application/json" },
|
230 |
+
body: JSON.stringify({ audio_data: base64String, name: name }),
|
231 |
+
})
|
232 |
+
.then((response) => response.json())
|
233 |
+
.then((data) => {
|
234 |
+
if (data.error) {
|
235 |
+
alert("エラー: " + data.error);
|
236 |
+
console.error(data.details);
|
237 |
+
} else if (data.rate !== undefined) {
|
238 |
+
updateChartData(data.rate);
|
239 |
+
}
|
240 |
+
})
|
241 |
+
.catch((error) => {
|
242 |
+
console.error("エラー:", error);
|
243 |
+
});
|
244 |
+
};
|
245 |
+
reader.readAsDataURL(audioBlob);
|
246 |
+
}
|
247 |
+
|
248 |
+
function getMemberColors(memberCount) {
|
249 |
+
// 一人モードの場合は特別な処理をしない(updateChartで処理するため)
|
250 |
+
if (memberCount <= 1) {
|
251 |
+
return ["#4caf50", "#757575"];
|
252 |
+
} else {
|
253 |
+
let colors = [];
|
254 |
+
for (let i = 0; i < memberCount; i++) {
|
255 |
+
colors.push(baseMemberColors[i % baseMemberColors.length]);
|
256 |
+
}
|
257 |
+
return colors;
|
258 |
+
}
|
259 |
+
}
|
260 |
+
|
261 |
+
function updateChartData(newRate) {
|
262 |
+
// 一人モードの時の処理
|
263 |
+
if (members.length === 1) {
|
264 |
+
if (count_voice === 0) {
|
265 |
+
speechChart.data.datasets[0].data = [newRate, 100 - newRate];
|
266 |
+
before_rate = newRate;
|
267 |
+
} else if (count_voice === 1) {
|
268 |
+
let tmp_rate = (newRate + before_rate) / 2;
|
269 |
+
speechChart.data.datasets[0].data = [tmp_rate, 100 - tmp_rate];
|
270 |
+
before_rate = tmp_rate;
|
271 |
+
} else {
|
272 |
+
let tmp_rate = (newRate + before_rate * 2) / 3;
|
273 |
+
speechChart.data.datasets[0].data = [tmp_rate, 100 - tmp_rate];
|
274 |
+
before_rate = tmp_rate;
|
275 |
+
}
|
276 |
+
count_voice++;
|
277 |
+
|
278 |
+
// 一人モードでは常に緑色とグレーの組み合わせを使用
|
279 |
+
speechChart.data.labels = [members[0], "無音"];
|
280 |
+
speechChart.data.datasets[0].backgroundColor = ["#4caf50", "#757575"];
|
281 |
+
} else {
|
282 |
+
// 複数メンバーの場合は元の処理
|
283 |
+
if (count_voice === 0) {
|
284 |
+
speechChart.data.datasets[0].data = [newRate, 100 - newRate];
|
285 |
+
before_rate = newRate;
|
286 |
+
} else if (count_voice === 1) {
|
287 |
+
let tmp_rate = (newRate + before_rate) / 2;
|
288 |
+
speechChart.data.datasets[0].data = [tmp_rate, 100 - tmp_rate];
|
289 |
+
before_rate = tmp_rate;
|
290 |
+
} else {
|
291 |
+
let tmp_rate = (newRate + before_rate * 2) / 3;
|
292 |
+
speechChart.data.datasets[0].data = [tmp_rate, 100 - tmp_rate];
|
293 |
+
before_rate = tmp_rate;
|
294 |
+
}
|
295 |
+
count_voice++;
|
296 |
+
speechChart.data.datasets[0].backgroundColor = getMemberColors(members.length);
|
297 |
+
}
|
298 |
+
|
299 |
+
speechChart.update();
|
300 |
+
}
|
301 |
+
|
302 |
+
function showTalkdetail() {
|
303 |
+
window.location.href = "talk_detail";
|
304 |
+
}
|
305 |
+
|
306 |
+
function showResults() {
|
307 |
+
window.location.href = "feedback";
|
308 |
+
}
|
309 |
+
|
310 |
+
function showUserRegister() {
|
311 |
+
fetch("/reset");
|
312 |
+
window.location.href = "userregister";
|
313 |
+
}
|
314 |
+
</script>
|
315 |
+
</body>
|
|
|
|
|
|
|
|
|
|
|
316 |
</html>
|