mizzzuno commited on
Commit
08e8b96
·
verified ·
1 Parent(s): 4780055

Upload userRegister.html

Browse files
Files changed (1) hide show
  1. templates/userRegister.html +186 -0
templates/userRegister.html ADDED
@@ -0,0 +1,186 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="ja">
3
+ <head>
4
+ <meta charset="UTF-8" />
5
+ <title>ユーザー音声登録</title>
6
+ <script src="https://cdn.tailwindcss.com"></script>
7
+ <style>
8
+ @keyframes pulse-scale {
9
+ 0%,
10
+ 100% {
11
+ transform: scale(1);
12
+ }
13
+ 50% {
14
+ transform: scale(1.1);
15
+ }
16
+ }
17
+ .animate-pulse-scale {
18
+ animation: pulse-scale 1s infinite;
19
+ }
20
+ .record-button {
21
+ width: 50px;
22
+ height: 50px;
23
+ background-color: transparent;
24
+ border-radius: 50%;
25
+ border: 2px solid white;
26
+ display: flex;
27
+ justify-content: center;
28
+ align-items: center;
29
+ cursor: pointer;
30
+ box-shadow: 0 4px 6px rgba(0, 0, 0, 0.4);
31
+ transition: all 0.3s ease;
32
+ }
33
+ .record-icon {
34
+ width: 35px;
35
+ height: 35px;
36
+ background-color: #d32f2f;
37
+ border-radius: 50%;
38
+ transition: all 0.3s ease;
39
+ }
40
+ .record-button.recording .record-icon {
41
+ border-radius: 4px; /* 録音時に赤い部分だけ四角にする */
42
+ }
43
+ .recording .record-icon {
44
+ width: 20px;
45
+ height: 20px;
46
+ border-radius: 50%;
47
+ }
48
+ @media (max-width: 640px) {
49
+ .container {
50
+ padding: 2rem;
51
+ }
52
+ }
53
+ </style>
54
+ </head>
55
+ <body
56
+ class="bg-gray-800 text-gray-100 dark:bg-gray-900 dark:text-gray-300 transition-colors"
57
+ >
58
+ <div class="container mx-auto p-5 max-w-full sm:max-w-2xl">
59
+ <div id="people-list" class="space-y-4"></div>
60
+ <button
61
+ id="add-btn"
62
+ class="mt-6 px-6 py-2 bg-green-500 text-white rounded-lg hover:bg-green-600 transition-colors"
63
+ >
64
+ メンバーを追加
65
+ </button>
66
+
67
+ <!-- 録音画面に戻るボタン -->
68
+ <button
69
+ id="backButton"
70
+ class="mt-6 px-6 py-2 bg-blue-500 text-white rounded-lg hover:bg-blue-600 transition-colors"
71
+ >
72
+ 録音画面に戻る
73
+ </button>
74
+ </div>
75
+
76
+ <script>
77
+ let mediaRecorder;
78
+ let audioChunks = [];
79
+ let userCount = 0; // 追加されたメンバー数を保持
80
+ let isRecording = false; // 録音中かどうかを判定するフラグ
81
+ let currentRecordingButton = null; // 現在録音中のボタンを保持
82
+
83
+ function toggleRecording(button) {
84
+ button.classList.toggle("recording");
85
+ }
86
+
87
+ async function startRecording(button) {
88
+ if (isRecording && currentRecordingButton !== button) return; // 他の人が録音中なら何もしない
89
+ isRecording = true; // 録音中に設定
90
+ currentRecordingButton = button; // 録音中のボタンを記録
91
+
92
+ try {
93
+ const stream = await navigator.mediaDevices.getUserMedia({
94
+ audio: true,
95
+ });
96
+ mediaRecorder = new MediaRecorder(stream);
97
+ mediaRecorder.ondataavailable = (e) => audioChunks.push(e.data);
98
+ mediaRecorder.onstop = () => {
99
+ const audioBlob = new Blob(audioChunks, { type: "audio/wav" });
100
+ console.log("音声データ:", audioBlob);
101
+ audioChunks = [];
102
+ isRecording = false; // 録音停止後はフラグを戻す
103
+ currentRecordingButton = null; // 録音ボタンを解除
104
+ };
105
+ mediaRecorder.start();
106
+ toggleRecording(button);
107
+ } catch (err) {
108
+ console.error("マイクアクセスに失敗しました:", err);
109
+ isRecording = false; // エラー発生時もフラグを戻す
110
+ currentRecordingButton = null;
111
+ }
112
+ }
113
+
114
+ function stopRecording(button) {
115
+ if (!isRecording) return; // 録音中でない場合は停止しない
116
+ mediaRecorder.stop();
117
+ toggleRecording(button);
118
+ }
119
+
120
+ function handleRecording(e) {
121
+ const button = e.target.closest(".record-button");
122
+ if (button) {
123
+ if (isRecording && currentRecordingButton !== button) {
124
+ // 他の人が録音中なら反応しない
125
+ return;
126
+ }
127
+ if (mediaRecorder && mediaRecorder.state === "recording") {
128
+ stopRecording(button);
129
+ } else {
130
+ startRecording(button);
131
+ }
132
+ }
133
+ }
134
+
135
+ document.getElementById("add-btn").addEventListener("click", () => {
136
+ const newItem = document.createElement("div");
137
+ newItem.className = "flex items-center gap-3 flex-wrap";
138
+ newItem.innerHTML = `
139
+ <form
140
+ action="/submit"
141
+ method="POST"
142
+ class="flex items-center space-x-2 w-full sm:w-auto"
143
+ onsubmit="event.preventDefault();"
144
+ >
145
+ <input
146
+ type="text"
147
+ placeholder="名前を入力"
148
+ class="flex-1 px-4 py-2 border rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500 bg-gray-700 text-white"
149
+ />
150
+
151
+ <button type="button" class="record-button" aria-label="音声録音開始">
152
+ <div class="record-icon"></div>
153
+ </button>
154
+
155
+ <button
156
+ type="submit"
157
+ class="submit-button px-4 py-2 border rounded-lg bg-blue-500 text-white hover:bg-blue-600"
158
+ >
159
+ 送信
160
+ </button>
161
+ </form>
162
+ `;
163
+ newItem.addEventListener("click", handleRecording);
164
+ document.getElementById("people-list").appendChild(newItem);
165
+ userCount++; // 新しいメンバーを追加するたびにカウントを増やす
166
+ });
167
+
168
+ // 「録音画面に戻る」ボタンの処理
169
+ document
170
+ .getElementById("backButton")
171
+ .addEventListener("click", function () {
172
+ // メンバーの人数を送信する
173
+ sendUserCount();
174
+
175
+ // index.htmlに戻る
176
+ window.location.href = "index.html";
177
+ });
178
+
179
+ // メンバーの人数を送信する関数
180
+ function sendUserCount() {
181
+ console.log(`追加された人数: ${userCount}`);
182
+ // ここで人数を送信する処理を実行(例: fetchを使ってサーバーに送信)
183
+ }
184
+ </script>
185
+ </body>
186
+ </html>