Spaces:
Sleeping
Sleeping
Update index.html
Browse files- index.html +148 -169
index.html
CHANGED
@@ -1,190 +1,169 @@
|
|
1 |
<!DOCTYPE html>
|
2 |
-
<html lang="
|
3 |
<head>
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
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 |
-
.result-button:hover {
|
67 |
-
background-color: #388e3c;
|
68 |
-
}
|
69 |
-
</style>
|
70 |
-
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
|
71 |
</head>
|
72 |
<body>
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
<script>
|
81 |
-
|
82 |
-
let isRecording = false;
|
83 |
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
recordButton.classList.remove('recording');
|
93 |
-
}
|
94 |
-
}
|
95 |
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
const chart = new Chart(ctx, {
|
102 |
-
type: 'doughnut',
|
103 |
-
data: {
|
104 |
-
labels: ['自分', '他の人'],
|
105 |
-
datasets: [{
|
106 |
-
data: [30, 70],
|
107 |
-
backgroundColor: ['#4caf50', '#757575'],
|
108 |
-
}],
|
109 |
-
},
|
110 |
-
options: {
|
111 |
-
responsive: true,
|
112 |
-
plugins: {
|
113 |
-
legend: {
|
114 |
-
display: true,
|
115 |
-
position: 'bottom',
|
116 |
-
labels: {
|
117 |
-
color: 'white'
|
118 |
-
}
|
119 |
-
}
|
120 |
-
}
|
121 |
-
}
|
122 |
-
});
|
123 |
-
</script>
|
124 |
-
|
125 |
-
<script>
|
126 |
-
let mode = 'False';
|
127 |
-
let mediaRecorder;
|
128 |
-
let audioChunks = [];
|
129 |
-
const startRecordingBtn = document.getElementById('recordButton');
|
130 |
-
const sendToServerBtn = document.getElementById('result-button');
|
131 |
-
|
132 |
-
// 音声録音の開始
|
133 |
-
startRecordingBtn.addEventListener('click', async () => {
|
134 |
-
if (mode){
|
135 |
-
mediaRecorder.stop();
|
136 |
-
startRecordingBtn.disabled = false;
|
137 |
-
stopRecordingBtn.disabled = true;
|
138 |
-
mode = 'False';
|
139 |
-
}
|
140 |
const stream = await navigator.mediaDevices.getUserMedia({ audio: true });
|
141 |
mediaRecorder = new MediaRecorder(stream);
|
142 |
-
|
|
|
143 |
mediaRecorder.ondataavailable = event => {
|
144 |
-
|
|
|
|
|
145 |
};
|
146 |
-
|
147 |
mediaRecorder.onstop = () => {
|
148 |
const audioBlob = new Blob(audioChunks, { type: 'audio/wav' });
|
149 |
const reader = new FileReader();
|
150 |
-
|
151 |
reader.onloadend = () => {
|
152 |
-
const base64String = reader.result.split(',')[1]; // Base64
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
.
|
167 |
-
.then(data => {
|
168 |
-
alert('音声がバックエンドに送信されました。');
|
169 |
-
})
|
170 |
-
.catch(error => {
|
171 |
-
console.error('エラー:', error);
|
172 |
-
});
|
173 |
});
|
174 |
};
|
175 |
-
|
176 |
reader.readAsDataURL(audioBlob);
|
177 |
};
|
178 |
-
|
179 |
mediaRecorder.start();
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
189 |
</body>
|
190 |
-
</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 |
+
<style>
|
8 |
+
body {
|
9 |
+
display: flex;
|
10 |
+
flex-direction: column;
|
11 |
+
justify-content: center;
|
12 |
+
align-items: center;
|
13 |
+
height: 100vh;
|
14 |
+
margin: 0;
|
15 |
+
background-color: #121212;
|
16 |
+
color: white;
|
17 |
+
}
|
18 |
+
.chart {
|
19 |
+
width: 300px;
|
20 |
+
height: 300px;
|
21 |
+
margin-bottom: 20px;
|
22 |
+
}
|
23 |
+
.record-button {
|
24 |
+
position: fixed;
|
25 |
+
bottom: 30px;
|
26 |
+
width: 80px;
|
27 |
+
height: 80px;
|
28 |
+
background-color: transparent;
|
29 |
+
border-radius: 50%;
|
30 |
+
border: 4px solid white;
|
31 |
+
display: flex;
|
32 |
+
justify-content: center;
|
33 |
+
align-items: center;
|
34 |
+
cursor: pointer;
|
35 |
+
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.4);
|
36 |
+
transition: all 0.2s ease;
|
37 |
+
}
|
38 |
+
.record-icon {
|
39 |
+
width: 60px;
|
40 |
+
height: 60px;
|
41 |
+
background-color: #d32f2f;
|
42 |
+
border-radius: 50%;
|
43 |
+
transition: all 0.2s ease;
|
44 |
+
}
|
45 |
+
.recording .record-icon {
|
46 |
+
width: 40px;
|
47 |
+
height: 40px;
|
48 |
+
border-radius: 10%;
|
49 |
+
}
|
50 |
+
.result-button {
|
51 |
+
margin-top: 20px;
|
52 |
+
padding: 10px 20px;
|
53 |
+
background-color: #4caf50;
|
54 |
+
border: none;
|
55 |
+
border-radius: 5px;
|
56 |
+
color: white;
|
57 |
+
cursor: pointer;
|
58 |
+
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.4);
|
59 |
+
}
|
60 |
+
.result-button:hover {
|
61 |
+
background-color: #388e3c;
|
62 |
+
}
|
63 |
+
</style>
|
64 |
+
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
|
|
|
|
|
|
|
|
|
|
|
|
|
65 |
</head>
|
66 |
<body>
|
67 |
+
<div class="chart">
|
68 |
+
<canvas id="speechChart"></canvas>
|
69 |
+
</div>
|
70 |
+
<button class="record-button" id="recordButton" onclick="toggleRecording()">
|
71 |
+
<div class="record-icon" id="recordIcon"></div>
|
72 |
+
</button>
|
73 |
+
<button class="result-button" id="resultButton" onclick="showResults()">結果を表示</button>
|
|
|
|
|
|
|
74 |
|
75 |
+
<script>
|
76 |
+
let isRecording = false;
|
77 |
+
let mediaRecorder;
|
78 |
+
let audioChunks = [];
|
79 |
|
80 |
+
async function toggleRecording() {
|
81 |
+
const recordButton = document.getElementById('recordButton');
|
82 |
+
const recordIcon = document.getElementById('recordIcon');
|
|
|
|
|
|
|
83 |
|
84 |
+
if (!isRecording) {
|
85 |
+
// 録音開始
|
86 |
+
isRecording = true;
|
87 |
+
recordButton.classList.add('recording');
|
88 |
+
try {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
89 |
const stream = await navigator.mediaDevices.getUserMedia({ audio: true });
|
90 |
mediaRecorder = new MediaRecorder(stream);
|
91 |
+
audioChunks = [];
|
92 |
+
|
93 |
mediaRecorder.ondataavailable = event => {
|
94 |
+
if (event.data.size > 0) {
|
95 |
+
audioChunks.push(event.data);
|
96 |
+
}
|
97 |
};
|
98 |
+
|
99 |
mediaRecorder.onstop = () => {
|
100 |
const audioBlob = new Blob(audioChunks, { type: 'audio/wav' });
|
101 |
const reader = new FileReader();
|
|
|
102 |
reader.onloadend = () => {
|
103 |
+
const base64String = reader.result.split(',')[1]; // Base64 エンコードされた音声データ
|
104 |
+
// サーバーへ音声データを送信
|
105 |
+
fetch('/upload_audio', {
|
106 |
+
method: 'POST',
|
107 |
+
headers: {
|
108 |
+
'Content-Type': 'application/json',
|
109 |
+
},
|
110 |
+
body: JSON.stringify({ audio_data: base64String }),
|
111 |
+
})
|
112 |
+
.then(response => response.json())
|
113 |
+
.then(data => {
|
114 |
+
alert('音声がバックエンドに送信されました。');
|
115 |
+
})
|
116 |
+
.catch(error => {
|
117 |
+
console.error('エラー:', error);
|
|
|
|
|
|
|
|
|
|
|
|
|
118 |
});
|
119 |
};
|
|
|
120 |
reader.readAsDataURL(audioBlob);
|
121 |
};
|
122 |
+
|
123 |
mediaRecorder.start();
|
124 |
+
} catch (error) {
|
125 |
+
console.error('マイクへのアクセスに失敗しました:', error);
|
126 |
+
isRecording = false;
|
127 |
+
recordButton.classList.remove('recording');
|
128 |
+
}
|
129 |
+
} else {
|
130 |
+
// 録音停止
|
131 |
+
isRecording = false;
|
132 |
+
recordButton.classList.remove('recording');
|
133 |
+
if (mediaRecorder && mediaRecorder.state !== 'inactive') {
|
134 |
+
mediaRecorder.stop();
|
135 |
+
}
|
136 |
+
}
|
137 |
+
}
|
138 |
+
|
139 |
+
function showResults() {
|
140 |
+
window.location.href = 'feedback.html';
|
141 |
+
}
|
142 |
+
|
143 |
+
// Chart.js の初期化
|
144 |
+
const ctx = document.getElementById('speechChart').getContext('2d');
|
145 |
+
const speechChart = new Chart(ctx, {
|
146 |
+
type: 'doughnut',
|
147 |
+
data: {
|
148 |
+
labels: ['自分', '他の人'],
|
149 |
+
datasets: [{
|
150 |
+
data: [30, 70],
|
151 |
+
backgroundColor: ['#4caf50', '#757575'],
|
152 |
+
}],
|
153 |
+
},
|
154 |
+
options: {
|
155 |
+
responsive: true,
|
156 |
+
plugins: {
|
157 |
+
legend: {
|
158 |
+
display: true,
|
159 |
+
position: 'bottom',
|
160 |
+
labels: {
|
161 |
+
color: 'white'
|
162 |
+
}
|
163 |
+
}
|
164 |
+
}
|
165 |
+
}
|
166 |
+
});
|
167 |
+
</script>
|
168 |
</body>
|
169 |
+
</html>
|