283 lines
8.5 KiB
HTML
283 lines
8.5 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="zh-CN">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Text to BlendShapes 测试</title>
|
|
<style>
|
|
* { margin: 0; padding: 0; box-sizing: border-box; }
|
|
body {
|
|
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
|
|
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
|
min-height: 100vh;
|
|
padding: 20px;
|
|
}
|
|
.container {
|
|
max-width: 800px;
|
|
margin: 0 auto;
|
|
background: white;
|
|
border-radius: 12px;
|
|
padding: 30px;
|
|
box-shadow: 0 20px 60px rgba(0,0,0,0.3);
|
|
}
|
|
h1 {
|
|
color: #333;
|
|
margin-bottom: 10px;
|
|
font-size: 28px;
|
|
}
|
|
.subtitle {
|
|
color: #666;
|
|
margin-bottom: 30px;
|
|
font-size: 14px;
|
|
}
|
|
.input-group {
|
|
margin-bottom: 20px;
|
|
}
|
|
label {
|
|
display: block;
|
|
margin-bottom: 8px;
|
|
color: #555;
|
|
font-weight: 500;
|
|
}
|
|
input, textarea, select {
|
|
width: 100%;
|
|
padding: 12px;
|
|
border: 2px solid #e0e0e0;
|
|
border-radius: 6px;
|
|
font-size: 14px;
|
|
transition: border-color 0.3s;
|
|
}
|
|
input:focus, textarea:focus, select:focus {
|
|
outline: none;
|
|
border-color: #667eea;
|
|
}
|
|
textarea {
|
|
resize: vertical;
|
|
min-height: 100px;
|
|
font-family: inherit;
|
|
}
|
|
button {
|
|
width: 100%;
|
|
padding: 14px;
|
|
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
|
color: white;
|
|
border: none;
|
|
border-radius: 6px;
|
|
font-size: 16px;
|
|
font-weight: 600;
|
|
cursor: pointer;
|
|
transition: transform 0.2s, box-shadow 0.2s;
|
|
}
|
|
button:hover {
|
|
transform: translateY(-2px);
|
|
box-shadow: 0 10px 20px rgba(102, 126, 234, 0.3);
|
|
}
|
|
button:active {
|
|
transform: translateY(0);
|
|
}
|
|
button:disabled {
|
|
opacity: 0.6;
|
|
cursor: not-allowed;
|
|
transform: none;
|
|
}
|
|
.loading {
|
|
display: none;
|
|
text-align: center;
|
|
margin: 20px 0;
|
|
color: #667eea;
|
|
}
|
|
.loading.show {
|
|
display: block;
|
|
}
|
|
.result {
|
|
margin-top: 30px;
|
|
padding: 20px;
|
|
background: #f8f9fa;
|
|
border-radius: 6px;
|
|
display: none;
|
|
}
|
|
.result.show {
|
|
display: block;
|
|
}
|
|
.result h3 {
|
|
color: #333;
|
|
margin-bottom: 15px;
|
|
}
|
|
.stats {
|
|
display: grid;
|
|
grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
|
|
gap: 15px;
|
|
margin-bottom: 20px;
|
|
}
|
|
.stat-card {
|
|
background: white;
|
|
padding: 15px;
|
|
border-radius: 6px;
|
|
text-align: center;
|
|
}
|
|
.stat-value {
|
|
font-size: 24px;
|
|
font-weight: bold;
|
|
color: #667eea;
|
|
}
|
|
.stat-label {
|
|
font-size: 12px;
|
|
color: #666;
|
|
margin-top: 5px;
|
|
}
|
|
.frames-preview {
|
|
max-height: 300px;
|
|
overflow-y: auto;
|
|
background: white;
|
|
padding: 15px;
|
|
border-radius: 6px;
|
|
font-family: monospace;
|
|
font-size: 12px;
|
|
}
|
|
.error {
|
|
background: #fee;
|
|
color: #c33;
|
|
padding: 15px;
|
|
border-radius: 6px;
|
|
margin-top: 20px;
|
|
display: none;
|
|
}
|
|
.error.show {
|
|
display: block;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="container">
|
|
<h1>Text to BlendShapes</h1>
|
|
<p class="subtitle">将文字转换为 52 个 ARKit 形态键</p>
|
|
|
|
<div class="input-group">
|
|
<label for="text">输入文字</label>
|
|
<textarea id="text" placeholder="请输入要转换的文字...">你好世界,这是一个测试。</textarea>
|
|
</div>
|
|
|
|
<div class="input-group">
|
|
<label for="language">语言</label>
|
|
<select id="language">
|
|
<option value="zh-CN">中文</option>
|
|
<option value="en">English</option>
|
|
<option value="ja">日本語</option>
|
|
<option value="ko">한국어</option>
|
|
</select>
|
|
</div>
|
|
|
|
<div class="input-group">
|
|
<label for="apiUrl">API 地址</label>
|
|
<input type="text" id="apiUrl" value="http://localhost:5001/text-to-blendshapes">
|
|
</div>
|
|
|
|
<button id="submitBtn" onclick="convert()">转换</button>
|
|
|
|
<div class="loading" id="loading">
|
|
<p>⏳ 处理中,请稍候...</p>
|
|
</div>
|
|
|
|
<div class="error" id="error"></div>
|
|
|
|
<div class="result" id="result">
|
|
<h3>转换结果</h3>
|
|
<div class="stats">
|
|
<div class="stat-card">
|
|
<div class="stat-value" id="frameCount">0</div>
|
|
<div class="stat-label">总帧数</div>
|
|
</div>
|
|
<div class="stat-card">
|
|
<div class="stat-value" id="duration">0s</div>
|
|
<div class="stat-label">时长</div>
|
|
</div>
|
|
<div class="stat-card">
|
|
<div class="stat-value">52</div>
|
|
<div class="stat-label">形态键数量</div>
|
|
</div>
|
|
</div>
|
|
<h4 style="margin-bottom: 10px;">帧数据预览</h4>
|
|
<div class="frames-preview" id="framesPreview"></div>
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
async function convert() {
|
|
const text = document.getElementById('text').value.trim();
|
|
const language = document.getElementById('language').value;
|
|
const apiUrl = document.getElementById('apiUrl').value;
|
|
|
|
if (!text) {
|
|
showError('请输入文字');
|
|
return;
|
|
}
|
|
|
|
const submitBtn = document.getElementById('submitBtn');
|
|
const loading = document.getElementById('loading');
|
|
const result = document.getElementById('result');
|
|
const error = document.getElementById('error');
|
|
|
|
submitBtn.disabled = true;
|
|
loading.classList.add('show');
|
|
result.classList.remove('show');
|
|
error.classList.remove('show');
|
|
|
|
try {
|
|
const response = await fetch(apiUrl, {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
},
|
|
body: JSON.stringify({
|
|
text: text,
|
|
language: language
|
|
})
|
|
});
|
|
|
|
const data = await response.json();
|
|
|
|
if (!response.ok || !data.success) {
|
|
throw new Error(data.error || '请求失败');
|
|
}
|
|
|
|
displayResult(data);
|
|
|
|
} catch (err) {
|
|
showError(err.message);
|
|
} finally {
|
|
submitBtn.disabled = false;
|
|
loading.classList.remove('show');
|
|
}
|
|
}
|
|
|
|
function displayResult(data) {
|
|
const result = document.getElementById('result');
|
|
const frameCount = document.getElementById('frameCount');
|
|
const duration = document.getElementById('duration');
|
|
const framesPreview = document.getElementById('framesPreview');
|
|
|
|
const frames = data.frames || [];
|
|
frameCount.textContent = frames.length;
|
|
|
|
if (frames.length > 0) {
|
|
const lastFrame = frames[frames.length - 1];
|
|
duration.textContent = lastFrame.timeCode.toFixed(2) + 's';
|
|
}
|
|
|
|
framesPreview.textContent = JSON.stringify(frames.slice(0, 3), null, 2);
|
|
if (frames.length > 3) {
|
|
framesPreview.textContent += '\n\n... 共 ' + frames.length + ' 帧';
|
|
}
|
|
|
|
result.classList.add('show');
|
|
}
|
|
|
|
function showError(message) {
|
|
const error = document.getElementById('error');
|
|
error.textContent = '错误: ' + message;
|
|
error.classList.add('show');
|
|
}
|
|
</script>
|
|
</body>
|
|
</html>
|