rein0421 commited on
Commit
6fc04a2
·
verified ·
1 Parent(s): 29f9ef3

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +151 -113
index.html CHANGED
@@ -1,124 +1,162 @@
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
- let isRecording = false;
82
 
83
- function toggleRecording() {
84
- const recordButton = document.getElementById('recordButton');
85
- const recordIcon = document.getElementById('recordIcon');
86
- isRecording = !isRecording;
87
-
88
- if (isRecording) {
89
- recordButton.classList.add('recording');
90
- } else {
91
- recordButton.classList.remove('recording');
 
 
 
 
 
 
 
 
 
92
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
93
  }
94
-
95
- function showResults() {
96
- window.location.href = 'feedback.html';
 
 
 
97
  }
98
-
99
- const ctx = document.getElementById('speechChart').getContext('2d');
100
- const chart = new Chart(ctx, {
101
- type: 'doughnut',
102
- data: {
103
- labels: ['自分', '他の人'],
104
- datasets: [{
105
- data: [30, 70],
106
- backgroundColor: ['#4caf50', '#757575'],
107
- }],
108
- },
109
- options: {
110
- responsive: true,
111
- plugins: {
112
- legend: {
113
- display: true,
114
- position: 'bottom',
115
- labels: {
116
- color: 'white'
117
- }
118
- }
119
- }
 
 
120
  }
121
- });
122
- </script>
 
 
 
123
  </body>
124
  </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
+ async function toggleRecording() {
80
+ const recordButton = document.getElementById('recordButton');
81
+ const recordIcon = document.getElementById('recordIcon');
82
+ if (!isRecording) {
83
+ // 録音開始
84
+ isRecording = true;
85
+ recordButton.classList.add('recording');
86
+ try {
87
+ const stream = await navigator.mediaDevices.getUserMedia({ audio: true });
88
+ mediaRecorder = new MediaRecorder(stream);
89
+ audioChunks = [];
90
+ mediaRecorder.ondataavailable = event => {
91
+ if (event.data.size > 0) {
92
+ audioChunks.push(event.data);
93
  }
94
+ };
95
+ mediaRecorder.onstop = () => {
96
+ const audioBlob = new Blob(audioChunks, { type: 'audio/wav' });
97
+ const reader = new FileReader();
98
+ reader.onloadend = () => {
99
+ const base64String = reader.result.split(',')[1]; // Base64 エンコードされた音声データ
100
+ // サーバーへ音声データを送信
101
+ fetch('/upload_audio', {
102
+ method: 'POST',
103
+ headers: {
104
+ 'Content-Type': 'application/json',
105
+ },
106
+ body: JSON.stringify({ audio_data: base64String }),
107
+ })
108
+ .then(response => response.json())
109
+ .then(data => {
110
+ alert('音声がバックエンドに送信されました。');
111
+ })
112
+ .catch(error => {
113
+ console.error('エラー:', error);
114
+ });
115
+ };
116
+ reader.readAsDataURL(audioBlob);
117
+ };
118
+ mediaRecorder.start();
119
+ } catch (error) {
120
+ console.error('マイクへのアクセスに失敗しました:', error);
121
+ isRecording = false;
122
+ recordButton.classList.remove('recording');
123
  }
124
+ } else {
125
+ // 録音停止
126
+ isRecording = false;
127
+ recordButton.classList.remove('recording');
128
+ if (mediaRecorder && mediaRecorder.state !== 'inactive') {
129
+ mediaRecorder.stop();
130
  }
131
+ }
132
+ }
133
+ function showResults() {
134
+ window.location.href = 'feedback.html';
135
+ }
136
+ // Chart.js の初期化
137
+ const ctx = document.getElementById('speechChart').getContext('2d');
138
+ const speechChart = new Chart(ctx, {
139
+ type: 'doughnut',
140
+ data: {
141
+ labels: ['自分', '他の人'],
142
+ datasets: [{
143
+ data: [30, 70],
144
+ backgroundColor: ['#4caf50', '#757575'],
145
+ }],
146
+ },
147
+ options: {
148
+ responsive: true,
149
+ plugins: {
150
+ legend: {
151
+ display: true,
152
+ position: 'bottom',
153
+ labels: {
154
+ color: 'white'
155
  }
156
+ }
157
+ }
158
+ }
159
+ });
160
+ </script>
161
  </body>
162
  </html>