Spaces:
Sleeping
Sleeping
Update index.html
Browse files- index.html +42 -28
index.html
CHANGED
@@ -70,6 +70,7 @@
|
|
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>
|
@@ -77,6 +78,32 @@
|
|
77 |
let mediaRecorder;
|
78 |
let audioChunks = [];
|
79 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
80 |
async function toggleRecording() {
|
81 |
const recordButton = document.getElementById('recordButton');
|
82 |
const recordIcon = document.getElementById('recordIcon');
|
@@ -100,7 +127,8 @@
|
|
100 |
const audioBlob = new Blob(audioChunks, { type: 'audio/wav' });
|
101 |
const reader = new FileReader();
|
102 |
reader.onloadend = () => {
|
103 |
-
|
|
|
104 |
// サーバーへ音声データを送信
|
105 |
fetch('/upload_audio', {
|
106 |
method: 'POST',
|
@@ -111,7 +139,16 @@
|
|
111 |
})
|
112 |
.then(response => response.json())
|
113 |
.then(data => {
|
114 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
115 |
})
|
116 |
.catch(error => {
|
117 |
console.error('エラー:', error);
|
@@ -137,33 +174,10 @@
|
|
137 |
}
|
138 |
|
139 |
function showResults() {
|
140 |
-
|
|
|
|
|
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>
|
|
|
70 |
<button class="record-button" id="recordButton" onclick="toggleRecording()">
|
71 |
<div class="record-icon" id="recordIcon"></div>
|
72 |
</button>
|
73 |
+
<!-- 結果表示用のボタンは、必要に応じて別画面に遷移させるなどの実装に変更可能です -->
|
74 |
<button class="result-button" id="resultButton" onclick="showResults()">結果を表示</button>
|
75 |
|
76 |
<script>
|
|
|
78 |
let mediaRecorder;
|
79 |
let audioChunks = [];
|
80 |
|
81 |
+
// Chart.jsの初期化
|
82 |
+
const ctx = document.getElementById('speechChart').getContext('2d');
|
83 |
+
const speechChart = new Chart(ctx, {
|
84 |
+
type: 'doughnut',
|
85 |
+
data: {
|
86 |
+
labels: ['自分', '他の人'],
|
87 |
+
datasets: [{
|
88 |
+
// 初期値は仮のデータとして [30, 70] を設定
|
89 |
+
data: [30, 70],
|
90 |
+
backgroundColor: ['#4caf50', '#757575'],
|
91 |
+
}],
|
92 |
+
},
|
93 |
+
options: {
|
94 |
+
responsive: true,
|
95 |
+
plugins: {
|
96 |
+
legend: {
|
97 |
+
display: true,
|
98 |
+
position: 'bottom',
|
99 |
+
labels: {
|
100 |
+
color: 'white'
|
101 |
+
}
|
102 |
+
}
|
103 |
+
}
|
104 |
+
}
|
105 |
+
});
|
106 |
+
|
107 |
async function toggleRecording() {
|
108 |
const recordButton = document.getElementById('recordButton');
|
109 |
const recordIcon = document.getElementById('recordIcon');
|
|
|
127 |
const audioBlob = new Blob(audioChunks, { type: 'audio/wav' });
|
128 |
const reader = new FileReader();
|
129 |
reader.onloadend = () => {
|
130 |
+
// Base64エンコードされた文字列を取得
|
131 |
+
const base64String = reader.result.split(',')[1];
|
132 |
// サーバーへ音声データを送信
|
133 |
fetch('/upload_audio', {
|
134 |
method: 'POST',
|
|
|
139 |
})
|
140 |
.then(response => response.json())
|
141 |
.then(data => {
|
142 |
+
if(data.error) {
|
143 |
+
alert('エラー: ' + data.error);
|
144 |
+
console.error(data.details);
|
145 |
+
return;
|
146 |
+
}
|
147 |
+
// data.rate はパーセンテージ(例: 40なら自分の音声が40%)\n
|
148 |
+
// 円グラフのデータを更新:自分の音声をdata.rate、他の音声を(100 - data.rate)として設定
|
149 |
+
speechChart.data.datasets[0].data = [data.rate, 100 - data.rate];
|
150 |
+
speechChart.update();
|
151 |
+
alert('音声の解析が完了しました。自分の音声: ' + data.rate.toFixed(2) + '%, 他の人: ' + (100 - data.rate).toFixed(2) + '%');
|
152 |
})
|
153 |
.catch(error => {
|
154 |
console.error('エラー:', error);
|
|
|
174 |
}
|
175 |
|
176 |
function showResults() {
|
177 |
+
// 結果表示の別画面へ遷移する場合の処理例(必要に応じて実装してください):
|
178 |
+
// window.location.href = 'feedback.html';
|
179 |
+
alert('結果は円グラフ上に反映されています。');
|
180 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
181 |
</script>
|
182 |
</body>
|
183 |
</html>
|