Spaces:
Running
Running
Update templates/index.html
Browse files- templates/index.html +82 -201
templates/index.html
CHANGED
@@ -4,80 +4,52 @@
|
|
4 |
<meta charset="UTF-8" />
|
5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
6 |
<title>Voice Recorder Interface</title>
|
7 |
-
<
|
8 |
-
|
9 |
-
|
10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
<style>
|
12 |
-
body {
|
13 |
-
display: flex;
|
14 |
-
flex-direction: column;
|
15 |
-
justify-content: center;
|
16 |
-
align-items: center;
|
17 |
-
height: 100vh;
|
18 |
-
margin: 0;
|
19 |
-
background-color: #121212;
|
20 |
-
color: white;
|
21 |
-
}
|
22 |
-
/* トグルスイッチ(基準音声保存用) */
|
23 |
-
.toggle-container {
|
24 |
-
display: flex;
|
25 |
-
align-items: center;
|
26 |
-
margin-bottom: 20px;
|
27 |
-
}
|
28 |
-
.toggle-label {
|
29 |
-
margin-right: 10px;
|
30 |
-
}
|
31 |
-
.toggle-switch {
|
32 |
-
position: relative;
|
33 |
-
display: inline-block;
|
34 |
-
width: 50px;
|
35 |
-
height: 24px;
|
36 |
-
}
|
37 |
-
.toggle-switch input {
|
38 |
-
opacity: 0;
|
39 |
-
width: 0;
|
40 |
-
height: 0;
|
41 |
-
}
|
42 |
-
.slider {
|
43 |
-
position: absolute;
|
44 |
-
cursor: pointer;
|
45 |
-
top: 0;
|
46 |
-
left: 0;
|
47 |
-
right: 0;
|
48 |
-
bottom: 0;
|
49 |
-
background-color: #757575;
|
50 |
-
transition: 0.2s;
|
51 |
-
border-radius: 34px;
|
52 |
-
}
|
53 |
-
.slider::before {
|
54 |
-
content: "";
|
55 |
-
position: absolute;
|
56 |
-
height: 18px;
|
57 |
-
width: 18px;
|
58 |
-
left: 4px;
|
59 |
-
bottom: 3px;
|
60 |
-
background-color: white;
|
61 |
-
transition: 0.2s;
|
62 |
-
border-radius: 50%;
|
63 |
-
}
|
64 |
-
input:checked + .slider {
|
65 |
-
background-color: #4caf50;
|
66 |
-
}
|
67 |
-
input:checked + .slider::before {
|
68 |
-
transform: translateX(26px);
|
69 |
-
}
|
70 |
-
/* チャートのスタイル */
|
71 |
-
.chart {
|
72 |
-
width: 300px;
|
73 |
-
height: 300px;
|
74 |
-
margin-bottom: 20px; /* 円グラフとボタンの間隔を狭く */
|
75 |
-
}
|
76 |
-
.controls {
|
77 |
-
display: flex;
|
78 |
-
flex-direction: column;
|
79 |
-
align-items: center;
|
80 |
-
}
|
81 |
.record-button {
|
82 |
width: 80px;
|
83 |
height: 80px;
|
@@ -91,6 +63,7 @@
|
|
91 |
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.4);
|
92 |
transition: all 0.2s ease;
|
93 |
}
|
|
|
94 |
.record-icon {
|
95 |
width: 60px;
|
96 |
height: 60px;
|
@@ -98,83 +71,35 @@
|
|
98 |
border-radius: 50%;
|
99 |
transition: all 0.2s ease;
|
100 |
}
|
|
|
101 |
.recording .record-icon {
|
102 |
width: 40px;
|
103 |
height: 40px;
|
104 |
border-radius: 10%;
|
105 |
}
|
106 |
-
.result-button {
|
107 |
-
margin-left: 10px;
|
108 |
-
|
109 |
-
margin-top: 20px;
|
110 |
-
padding: 10px 20px;
|
111 |
-
background-color: #4caf50;
|
112 |
-
border: none;
|
113 |
-
border-radius: 5px;
|
114 |
-
color: white;
|
115 |
-
cursor: pointer;
|
116 |
-
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.4);
|
117 |
-
}
|
118 |
-
.result {
|
119 |
-
display: flex;
|
120 |
-
}
|
121 |
-
.result-button:hover {
|
122 |
-
background-color: #388e3c;
|
123 |
-
}
|
124 |
-
header {
|
125 |
-
display: flex;
|
126 |
-
}
|
127 |
</style>
|
128 |
-
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
|
129 |
-
</head>
|
130 |
-
<body>
|
131 |
-
<!-- トグルスイッチ:基準音声保存モード -->
|
132 |
-
<div class="toggle-container">
|
133 |
-
<span class="toggle-label">基準音声を保存</span>
|
134 |
-
<label class="toggle-switch">
|
135 |
-
<input type="checkbox" id="baseVoiceToggle" />
|
136 |
-
<span class="slider"></span>
|
137 |
-
</label>
|
138 |
-
</div>
|
139 |
-
|
140 |
-
<!-- チャート表示部 -->
|
141 |
-
<div class="chart">
|
142 |
-
<canvas id="speechChart"></canvas>
|
143 |
-
</div>
|
144 |
-
|
145 |
-
<!-- 録音ボタン -->
|
146 |
-
<button class="record-button" id="recordButton" onclick="toggleRecording()">
|
147 |
-
<div class="record-icon" id="recordIcon"></div>
|
148 |
-
</button>
|
149 |
-
|
150 |
-
<!-- 結果ボタン -->
|
151 |
-
<div class="result-buttons">
|
152 |
-
<button class="result-button" id="historyButton" onclick="showHistory()">
|
153 |
-
会話履歴を表示
|
154 |
-
</button>
|
155 |
-
<button class="result-button" id="feedbackButton" onclick="showResults()">
|
156 |
-
フィードバック画面を表示
|
157 |
-
</button>
|
158 |
-
</div>
|
159 |
|
160 |
<script>
|
161 |
let isRecording = false;
|
162 |
let mediaRecorder;
|
163 |
let audioChunks = [];
|
164 |
-
let recordingInterval;
|
165 |
-
let baseTimeout; // 基準音声モード用のタイマー
|
166 |
let count_voice = 0;
|
167 |
let before_rate = 0;
|
168 |
|
|
|
|
|
|
|
|
|
169 |
// Chart.js の初期化
|
170 |
const ctx = document.getElementById("speechChart").getContext("2d");
|
171 |
const speechChart = new Chart(ctx, {
|
172 |
type: "doughnut",
|
173 |
data: {
|
174 |
-
labels:
|
175 |
datasets: [
|
176 |
{
|
177 |
-
data:
|
178 |
backgroundColor: ["#4caf50", "#757575"],
|
179 |
},
|
180 |
],
|
@@ -191,9 +116,20 @@
|
|
191 |
},
|
192 |
});
|
193 |
|
194 |
-
|
195 |
-
function
|
196 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
197 |
}
|
198 |
|
199 |
async function toggleRecording() {
|
@@ -222,26 +158,6 @@
|
|
222 |
};
|
223 |
|
224 |
mediaRecorder.start();
|
225 |
-
|
226 |
-
if (isBaseVoiceMode()) {
|
227 |
-
// 基準音声モード:10秒後に自動停止するタイマーをセット
|
228 |
-
baseTimeout = setTimeout(() => {
|
229 |
-
if (mediaRecorder && mediaRecorder.state === "recording") {
|
230 |
-
mediaRecorder.stop();
|
231 |
-
// 10秒経過しても録音ボタンがONなら強制的に停止&トグルをオフにする
|
232 |
-
isRecording = false;
|
233 |
-
recordButton.classList.remove("recording");
|
234 |
-
document.getElementById("baseVoiceToggle").checked = false;
|
235 |
-
}
|
236 |
-
}, 10000);
|
237 |
-
} else {
|
238 |
-
// 通常モード:10秒ごとに自動停止して送信、継続録音する処理
|
239 |
-
recordingInterval = setInterval(() => {
|
240 |
-
if (mediaRecorder && mediaRecorder.state === "recording") {
|
241 |
-
mediaRecorder.stop();
|
242 |
-
}
|
243 |
-
}, 10000);
|
244 |
-
}
|
245 |
} catch (error) {
|
246 |
console.error("マイクへのアクセスに失敗しました:", error);
|
247 |
isRecording = false;
|
@@ -251,11 +167,6 @@
|
|
251 |
// 手動停止
|
252 |
isRecording = false;
|
253 |
recordButton.classList.remove("recording");
|
254 |
-
if (isBaseVoiceMode()) {
|
255 |
-
clearTimeout(baseTimeout);
|
256 |
-
} else {
|
257 |
-
clearInterval(recordingInterval);
|
258 |
-
}
|
259 |
if (mediaRecorder && mediaRecorder.state === "recording") {
|
260 |
mediaRecorder.stop();
|
261 |
count_voice = 0;
|
@@ -269,11 +180,7 @@
|
|
269 |
const reader = new FileReader();
|
270 |
reader.onloadend = () => {
|
271 |
const base64String = reader.result.split(",")[1]; // Base64エンコードされた音声データ
|
272 |
-
|
273 |
-
const endpoint = isBaseVoiceMode()
|
274 |
-
? "/upload_base_audio"
|
275 |
-
: "/upload_audio";
|
276 |
-
fetch(endpoint, {
|
277 |
method: "POST",
|
278 |
headers: {
|
279 |
"Content-Type": "application/json",
|
@@ -285,7 +192,7 @@
|
|
285 |
if (data.error) {
|
286 |
alert("エラー: " + data.error);
|
287 |
console.error(data.details);
|
288 |
-
} else if (data.rate !== undefined
|
289 |
// 通常モードの場合、解析結果をチャートに反映
|
290 |
if (count_voice === 0) {
|
291 |
speechChart.data.datasets[0].data = [
|
@@ -310,55 +217,29 @@
|
|
310 |
}
|
311 |
count_voice++;
|
312 |
speechChart.update();
|
313 |
-
} else {
|
314 |
-
// 基準音声モードまたは解析結果がない場合
|
315 |
-
if (isBaseVoiceMode()) {
|
316 |
-
//alert('基準音声が保存されました。');
|
317 |
-
// トグルをリセット
|
318 |
-
document.getElementById("baseVoiceToggle").checked = false;
|
319 |
-
} else {
|
320 |
-
//alert('音声がバックエンドに送信されました。');
|
321 |
-
}
|
322 |
-
}
|
323 |
-
// 通常モードの場合、録音が継続中なら次の録音を開始(自動連続録音)
|
324 |
-
if (
|
325 |
-
!isBaseVoiceMode() &&
|
326 |
-
isRecording &&
|
327 |
-
mediaRecorder &&
|
328 |
-
mediaRecorder.state === "inactive"
|
329 |
-
) {
|
330 |
-
mediaRecorder.start();
|
331 |
}
|
332 |
})
|
333 |
.catch((error) => {
|
334 |
console.error("エラー:", error);
|
335 |
-
if (
|
336 |
-
!isBaseVoiceMode() &&
|
337 |
-
isRecording &&
|
338 |
-
mediaRecorder &&
|
339 |
-
mediaRecorder.state === "inactive"
|
340 |
-
) {
|
341 |
-
mediaRecorder.start();
|
342 |
-
}
|
343 |
});
|
344 |
};
|
345 |
reader.readAsDataURL(audioBlob);
|
346 |
}
|
347 |
|
348 |
-
function showHistory() {
|
349 |
-
|
350 |
-
|
351 |
-
}
|
352 |
|
353 |
-
function showResults() {
|
354 |
-
|
355 |
-
|
356 |
-
}
|
357 |
|
358 |
-
function showLogin() {
|
359 |
-
|
360 |
-
|
361 |
-
}
|
362 |
</script>
|
363 |
</body>
|
364 |
</html>
|
|
|
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
|
11 |
+
class="flex flex-col items-center justify-center h-screen bg-gray-900 text-white"
|
12 |
+
>
|
13 |
+
<!-- メンバーを登録ボタン -->
|
14 |
+
<div class="flex items-center mb-5">
|
15 |
+
<button
|
16 |
+
id="registerButton"
|
17 |
+
onclick="window.location.href='userRegister.html'"
|
18 |
+
class="px-4 py-2 bg-blue-600 rounded-md hover:bg-blue-700 transition"
|
19 |
+
>
|
20 |
+
メンバーを登録
|
21 |
+
</button>
|
22 |
+
</div>
|
23 |
+
|
24 |
+
<!-- チャート表示部 -->
|
25 |
+
<div class="chart w-72 h-72 mb-5">
|
26 |
+
<canvas id="speechChart"></canvas>
|
27 |
+
</div>
|
28 |
+
|
29 |
+
<!-- 録音ボタン -->
|
30 |
+
<button class="record-button" id="recordButton" onclick="toggleRecording()">
|
31 |
+
<div class="record-icon" id="recordIcon"></div>
|
32 |
+
</button>
|
33 |
+
|
34 |
+
<!-- 結果ボタン -->
|
35 |
+
<div class="flex mt-5">
|
36 |
+
<button
|
37 |
+
id="historyButton"
|
38 |
+
onclick="window.location.href = 'history.html'"
|
39 |
+
class="result-button px-4 py-2 mx-2 bg-green-600 rounded-md hover:bg-green-700 transition"
|
40 |
+
>
|
41 |
+
会話履歴を表示
|
42 |
+
</button>
|
43 |
+
<button
|
44 |
+
id="feedbackButton"
|
45 |
+
onclick="window.location.href = 'feedback.html'"
|
46 |
+
class="result-button px-4 py-2 mx-2 bg-blue-600 rounded-md hover:bg-blue-700 transition"
|
47 |
+
>
|
48 |
+
フィードバック画面を表示
|
49 |
+
</button>
|
50 |
+
</div>
|
51 |
+
|
52 |
<style>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
53 |
.record-button {
|
54 |
width: 80px;
|
55 |
height: 80px;
|
|
|
63 |
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.4);
|
64 |
transition: all 0.2s ease;
|
65 |
}
|
66 |
+
|
67 |
.record-icon {
|
68 |
width: 60px;
|
69 |
height: 60px;
|
|
|
71 |
border-radius: 50%;
|
72 |
transition: all 0.2s ease;
|
73 |
}
|
74 |
+
|
75 |
.recording .record-icon {
|
76 |
width: 40px;
|
77 |
height: 40px;
|
78 |
border-radius: 10%;
|
79 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
80 |
</style>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
81 |
|
82 |
<script>
|
83 |
let isRecording = false;
|
84 |
let mediaRecorder;
|
85 |
let audioChunks = [];
|
86 |
+
let recordingInterval;
|
|
|
87 |
let count_voice = 0;
|
88 |
let before_rate = 0;
|
89 |
|
90 |
+
// 初期設定:人数と名前を受け取って円グラフを作成
|
91 |
+
let members = ["自分", "ahaha", "nufufu", "不明"];
|
92 |
+
let voiceData = [50, 20, 20, 10]; // 自分と不明の割合を仮設定
|
93 |
+
|
94 |
// Chart.js の初期化
|
95 |
const ctx = document.getElementById("speechChart").getContext("2d");
|
96 |
const speechChart = new Chart(ctx, {
|
97 |
type: "doughnut",
|
98 |
data: {
|
99 |
+
labels: members,
|
100 |
datasets: [
|
101 |
{
|
102 |
+
data: voiceData,
|
103 |
backgroundColor: ["#4caf50", "#757575"],
|
104 |
},
|
105 |
],
|
|
|
116 |
},
|
117 |
});
|
118 |
|
119 |
+
//録音ボタン見た目変化
|
120 |
+
function toggleRecording() {
|
121 |
+
isRecording = !isRecording;
|
122 |
+
const recordIcon = document.getElementById("recordIcon");
|
123 |
+
if (isRecording) {
|
124 |
+
recordIcon.classList.add("w-10", "h-10", "bg-red-900", "rounded-md");
|
125 |
+
} else {
|
126 |
+
recordIcon.classList.remove(
|
127 |
+
"w-10",
|
128 |
+
"h-10",
|
129 |
+
"bg-red-900",
|
130 |
+
"rounded-md"
|
131 |
+
);
|
132 |
+
}
|
133 |
}
|
134 |
|
135 |
async function toggleRecording() {
|
|
|
158 |
};
|
159 |
|
160 |
mediaRecorder.start();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
161 |
} catch (error) {
|
162 |
console.error("マイクへのアクセスに失敗しました:", error);
|
163 |
isRecording = false;
|
|
|
167 |
// 手動停止
|
168 |
isRecording = false;
|
169 |
recordButton.classList.remove("recording");
|
|
|
|
|
|
|
|
|
|
|
170 |
if (mediaRecorder && mediaRecorder.state === "recording") {
|
171 |
mediaRecorder.stop();
|
172 |
count_voice = 0;
|
|
|
180 |
const reader = new FileReader();
|
181 |
reader.onloadend = () => {
|
182 |
const base64String = reader.result.split(",")[1]; // Base64エンコードされた音声データ
|
183 |
+
fetch("/upload_audio", {
|
|
|
|
|
|
|
|
|
184 |
method: "POST",
|
185 |
headers: {
|
186 |
"Content-Type": "application/json",
|
|
|
192 |
if (data.error) {
|
193 |
alert("エラー: " + data.error);
|
194 |
console.error(data.details);
|
195 |
+
} else if (data.rate !== undefined) {
|
196 |
// 通常モードの場合、解析結果をチャートに反映
|
197 |
if (count_voice === 0) {
|
198 |
speechChart.data.datasets[0].data = [
|
|
|
217 |
}
|
218 |
count_voice++;
|
219 |
speechChart.update();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
220 |
}
|
221 |
})
|
222 |
.catch((error) => {
|
223 |
console.error("エラー:", error);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
224 |
});
|
225 |
};
|
226 |
reader.readAsDataURL(audioBlob);
|
227 |
}
|
228 |
|
229 |
+
//function showHistory() {
|
230 |
+
//window.location.href = "history";
|
231 |
+
//alert("会話履歴を表示する機能は未実装です。");
|
232 |
+
//}
|
233 |
|
234 |
+
//function showResults() {
|
235 |
+
// フィードバック画面へ遷移
|
236 |
+
//window.location.href = "feedback";
|
237 |
+
//}
|
238 |
|
239 |
+
//function showLogin() {
|
240 |
+
// ログイン画面へ遷移
|
241 |
+
//window.location.href = "login";
|
242 |
+
//}
|
243 |
</script>
|
244 |
</body>
|
245 |
</html>
|