-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathindex.html
More file actions
201 lines (190 loc) · 8.56 KB
/
index.html
File metadata and controls
201 lines (190 loc) · 8.56 KB
1
2
3
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>MotionPNG Tuber - Browser</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="container">
<h1>MotionPNG Tuber</h1>
<!-- データフォルダ選択 -->
<div class="section" id="setup-section">
<h2>1. データフォルダを選択</h2>
<p>口消し動画、mouth_track.json、口スプライトが入ったフォルダを選択してください。</p>
<input type="file" id="folder-input" webkitdirectory multiple>
<div id="file-status"></div>
</div>
<!-- マイク設定 -->
<div class="section" id="mic-section" style="display: none;">
<h2>2. マイク設定</h2>
<select id="mic-select"></select>
<button id="mic-start-btn">マイクを開始</button>
<button id="mic-stop-btn" disabled>マイク停止</button>
<div class="meter-container">
<div id="volume-meter"></div>
</div>
<div>
<label>感度: <input type="range" id="sensitivity" min="0" max="100" value="50"></label>
<span id="sensitivity-value">50</span>
<span class="hint slider-hint">音量に対する口の開きやすさ</span>
</div>
<div class="toggle-row">
<label><input type="checkbox" id="hq-audio" checked> HQ Audio(キビキビ)</label>
<span class="hint">切替はマイク開始前が安定</span>
</div>
</div>
<!-- プレビュー -->
<div class="section" id="preview-section" style="display: none;">
<h2>3. プレビュー</h2>
<div class="stage-container">
<div class="stage" id="stage">
<video id="base-video" playsinline muted></video>
<canvas id="mouth-canvas"></canvas>
</div>
</div>
<div class="controls">
<button id="start-btn">開始</button>
<button id="stop-btn" disabled>停止</button>
</div>
<div id="debug-info" style="margin-top:10px; font-size:12px; color:#888;"></div>
</div>
</div>
<script src="audio-capture.js"></script>
<script src="lipsync.js"></script>
<script>
document.addEventListener('DOMContentLoaded', () => {
// ========================================
// DOM要素 - LipsyncEngine用
// ========================================
const folderInput = document.getElementById('folder-input');
const fileStatus = document.getElementById('file-status');
const volumeMeter = document.getElementById('volume-meter');
const sensitivitySlider = document.getElementById('sensitivity');
const sensitivityValue = document.getElementById('sensitivity-value');
const hqAudioToggle = document.getElementById('hq-audio');
const startBtn = document.getElementById('start-btn');
const stopBtn = document.getElementById('stop-btn');
const debugInfo = document.getElementById('debug-info');
const micSection = document.getElementById('mic-section');
const previewSection = document.getElementById('preview-section');
// ========================================
// DOM要素 - AudioCapture用
// ========================================
const micSelect = document.getElementById('mic-select');
const micStartBtn = document.getElementById('mic-start-btn');
const micStopBtn = document.getElementById('mic-stop-btn');
// ========================================
// LipsyncEngine初期化
// ========================================
const engine = new LipsyncEngine({
elements: {
video: document.getElementById('base-video'),
mouthCanvas: document.getElementById('mouth-canvas'),
stage: document.getElementById('stage')
},
callbacks: {
onLog: (msg) => {
debugInfo.textContent = msg;
},
onFileStatus: (status, message) => {
fileStatus.className = status;
fileStatus.textContent = message;
},
onVolumeChange: (volume) => {
volumeMeter.style.width = `${volume * 100}%`;
},
onPlayStateChange: (isPlaying) => {
startBtn.disabled = isPlaying;
stopBtn.disabled = !isPlaying;
},
onSectionsVisibility: (visible) => {
micSection.style.display = visible ? 'block' : 'none';
previewSection.style.display = visible ? 'block' : 'none';
},
onError: (message) => {
alert(message);
}
},
// Uncomment below to load character on start
// assets: {
// video: './assets/assets14/pinkchan_mouthless_h264.mp4',
// track: './assets/assets14/mouth_track.json',
// mouth_closed: './assets/assets14/mouth/closed.png',
// mouth_open: './assets/assets14/mouth/open.png',
// mouth_half: './assets/assets14/mouth/half.png',
// mouth_e: './assets/assets14/mouth/e.png',
// mouth_u: './assets/assets14/mouth/u.png'
// },
// options: {
// debug: true, // デバッグログを表示
// hqAudioEnabled: true, // 高品質音声モード(キビキビ動作)
// sensitivity: 50 // 感度(0-100、低いほど口が開きにくい)
// }
});
// ========================================
// AudioCapture初期化
// ========================================
const audioCapture = new AudioCapture({
onVolumeData: (data) => {
engine.processAudioData(data);
},
onStateChange: (isRunning) => {
micStartBtn.disabled = isRunning;
micStopBtn.disabled = !isRunning;
micStartBtn.textContent = isRunning ? 'マイク接続中' : 'マイクを開始';
if (!isRunning) {
engine.resetAudioStats();
}
},
onDevicesLoaded: (devices) => {
micSelect.innerHTML = '';
devices.forEach((device) => {
const option = document.createElement('option');
option.value = device.deviceId;
option.textContent = device.label;
micSelect.appendChild(option);
});
},
onError: (message) => {
alert(message);
}
});
audioCapture.loadDevices();
// ========================================
// イベントリスナー - LipsyncEngine用
// ========================================
folderInput.addEventListener('change', (e) => {
engine.loadFiles(Array.from(e.target.files));
});
sensitivitySlider.addEventListener('input', (e) => {
const value = parseInt(e.target.value, 10);
engine.setSensitivity(value);
sensitivityValue.textContent = value;
});
hqAudioToggle.addEventListener('change', (e) => {
engine.setHQAudioEnabled(e.target.checked);
audioCapture.setHQAudioEnabled(e.target.checked);
});
startBtn.addEventListener('click', () => engine.start());
stopBtn.addEventListener('click', () => engine.stop());
// ========================================
// イベントリスナー - AudioCapture用
// ========================================
micStartBtn.addEventListener('click', () => {
audioCapture.start(micSelect.value);
});
micStopBtn.addEventListener('click', () => {
audioCapture.stop();
});
// ========================================
// 初期値設定
// ========================================
engine.setSensitivity(parseInt(sensitivitySlider.value, 10));
engine.setHQAudioEnabled(hqAudioToggle.checked);
audioCapture.setHQAudioEnabled(hqAudioToggle.checked);
});
</script>
</body>
</html>