rein0421 commited on
Commit
9daa331
·
verified ·
1 Parent(s): d9e7de9

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +148 -169
index.html CHANGED
@@ -1,190 +1,169 @@
1
  <!DOCTYPE html>
2
- <html lang="en">
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
-
19
- .chart {
20
- width: 300px;
21
- height: 300px;
22
- margin-bottom: 20px;
23
- }
24
-
25
- .record-button {
26
- position: fixed;
27
- bottom: 30px;
28
- width: 80px;
29
- height: 80px;
30
- background-color: transparent;
31
- border-radius: 50%;
32
- border: 4px solid white;
33
- display: flex;
34
- justify-content: center;
35
- align-items: center;
36
- cursor: pointer;
37
- box-shadow: 0 4px 6px rgba(0, 0, 0, 0.4);
38
- transition: all 0.2s ease;
39
- }
40
-
41
- .record-icon {
42
- width: 60px;
43
- height: 60px;
44
- background-color: #d32f2f;
45
- border-radius: 50%;
46
- transition: all 0.2s ease;
47
- }
48
-
49
- .recording .record-icon {
50
- width: 40px;
51
- height: 40px;
52
- border-radius: 10%;
53
- }
54
-
55
- .result-button {
56
- margin-top: 20px;
57
- padding: 10px 20px;
58
- background-color: #4caf50;
59
- border: none;
60
- border-radius: 5px;
61
- color: white;
62
- cursor: pointer;
63
- box-shadow: 0 4px 6px rgba(0, 0, 0, 0.4);
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
- <div class="chart">
74
- <canvas id="speechChart"></canvas>
75
- </div>
76
- <button class="record-button" id="recordButton" onclick="toggleRecording()">
77
- <div class="record-icon" id="recordIcon"></div>
78
- </button>
79
- <button class="result-button" onclick="showResults()">結果を表示</button>
80
- <script>
81
-
82
- let isRecording = false;
83
 
84
- function toggleRecording() {
85
- const recordButton = document.getElementById('recordButton');
86
- const recordIcon = document.getElementById('recordIcon');
87
- isRecording = !isRecording;
88
 
89
- if (isRecording) {
90
- recordButton.classList.add('recording');
91
- } else {
92
- recordButton.classList.remove('recording');
93
- }
94
- }
95
 
96
- function showResults() {
97
- window.location.href = 'feedback.html';
98
- }
99
-
100
- const ctx = document.getElementById('speechChart').getContext('2d');
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
- audioChunks.push(event.data);
 
 
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
- sendToServerBtn.disabled = false;
154
-
155
- sendToServerBtn.addEventListener('click', () => {
156
- // 音声をバックエンドに送信
157
- fetch('/upload_audio', {
158
- method: 'POST',
159
- headers: {
160
- 'Content-Type': 'application/json',
161
- },
162
- body: JSON.stringify({
163
- audio_data: base64String,
164
- }),
165
- })
166
- .then(response => response.json())
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
- startRecordingBtn.disabled = true;
181
- stopRecordingBtn.disabled = false;
182
- mode = 'True';
183
- });
184
-
185
- // 音声録音の停止
186
-
187
- </script>
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>