Spaces:
Sleeping
Sleeping
File size: 12,440 Bytes
37c6d1c f1e4300 37c6d1c 7ad6f9b 37c6d1c f1e4300 37c6d1c 7ad6f9b 37c6d1c bfe9dec 37c6d1c f1e4300 37c6d1c 7ad6f9b f1e4300 7ad6f9b 37c6d1c f1e4300 37c6d1c f1e4300 37c6d1c f1e4300 37c6d1c 7ad6f9b f1e4300 37c6d1c f1e4300 7ad6f9b f1e4300 7ad6f9b f1e4300 7ad6f9b 37c6d1c f1e4300 37c6d1c f1e4300 37c6d1c | 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 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 | <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Voice Detection Verification Tool</title>
<style>
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
background-color: #f4f4f9;
color: #333;
padding: 20px;
}
.container {
max-width: 600px;
margin: 0 auto;
background: #fff;
padding: 30px;
border-radius: 8px;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}
h1 {
text-align: center;
color: #444;
}
.form-group {
margin-bottom: 20px;
}
label {
display: block;
margin-bottom: 5px;
font-weight: bold;
}
input[type="text"],
input[type="url"],
textarea {
width: 100%;
padding: 10px;
border: 1px solid #ddd;
border-radius: 4px;
box-sizing: border-box;
}
input[type="file"] {
border: 1px solid #ddd;
padding: 10px;
width: 100%;
border-radius: 4px;
background: #fafafa;
}
button {
width: 100%;
padding: 12px;
background-color: #007bff;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
font-size: 16px;
}
button:hover {
background-color: #0056b3;
}
#response {
margin-top: 20px;
background: #f8f9fa;
padding: 15px;
border-radius: 4px;
border: 1px solid #ddd;
word-wrap: break-word;
white-space: pre-wrap;
display: none;
}
.audio-player {
margin-top: 15px;
padding: 15px;
background: #f0f8ff;
border-radius: 4px;
border: 1px solid #b3d9ff;
display: none;
}
.audio-player audio {
width: 100%;
margin-top: 10px;
}
.audio-label {
font-weight: bold;
color: #0066cc;
margin-bottom: 5px;
}
.error {
color: #dc3545;
}
.success {
color: #28a745;
}
.tabs {
display: flex;
margin-bottom: 20px;
border-bottom: 1px solid #ddd;
}
.tab {
padding: 10px 20px;
cursor: pointer;
border-bottom: 2px solid transparent;
}
.tab.active {
border-bottom: 2px solid #007bff;
color: #007bff;
font-weight: bold;
}
</style>
</head>
<body>
<div class="container">
<h1>Voice Detection Tool</h1>
<div style="background: #e9ecef; padding: 15px; border-radius: 4px; margin-bottom: 20px;">
<h3>Generate AI Audio (Murf.ai)</h3>
<div class="form-group">
<label for="murfText">Text to Speak</label>
<input type="text" id="murfText" placeholder="Hello, this is a test.">
</div>
<div class="form-group">
<label for="murfKey">Murf API Key</label>
<input type="text" id="murfKey" placeholder="Enter Murf API Key">
</div>
<button onclick="generateAudio()" style="background-color: #28a745;">Generate Audio</button>
<div id="genStatus" style="margin-top:10px;"></div>
<!-- Audio Player for Generated AI Audio -->
<div id="generatedAudioPlayer" class="audio-player">
<div class="audio-label">🎵 Generated AI Audio (Click to Play)</div>
<audio id="generatedAudio" controls>
Your browser does not support the audio element.
</audio>
</div>
</div>
<div class="form-group">
<label for="apiUrl">API Endpoint URL</label>
<input type="text" id="apiUrl" value="/detect" placeholder="/detect">
</div>
<div class="form-group">
<label for="apiKey">API Key (Authorization)</label>
<input type="text" id="apiKey" value="my_secret_key_123" placeholder="Enter API Key">
</div>
<div class="form-group">
<label for="message">Test Message (Optional)</label>
<textarea id="message" rows="2" placeholder="Describe this test..."></textarea>
</div>
<h3>Select Audio Source</h3>
<div class="tabs">
<div class="tab active" onclick="switchTab('url')">Audio URL</div>
<div class="tab" onclick="switchTab('file')">Upload File</div>
</div>
<!-- URL Input Section -->
<div id="urlSection" class="form-group">
<label for="audioUrl">Audio File URL (MP3)</label>
<input type="url" id="audioUrl" placeholder="https://example.com/sample.mp3"
oninput="updateTestAudioPlayerFromUrl()">
</div>
<!-- File Input Section -->
<div id="fileSection" class="form-group" style="display:none;">
<label for="audioFile">Upload Audio File (MP3, WAV, M4A)</label>
<input type="file" id="audioFile" accept="audio/*" onchange="updateTestAudioPlayerFromFile()">
</div>
<!-- Audio Player for Test Audio -->
<div id="testAudioPlayer" class="audio-player">
<div class="audio-label">🎧 Test Audio Preview (Click to Play)</div>
<audio id="testAudio" controls>
Your browser does not support the audio element.
</audio>
</div>
<button onclick="testEndpoint()">Test Endpoint</button>
<div id="response"></div>
</div>
<script>
let currentMode = 'url'; // 'url' or 'file'
function switchTab(mode) {
currentMode = mode;
// Update tabs
document.querySelectorAll('.tab').forEach(t => t.classList.remove('active'));
document.querySelector(`.tab[onclick="switchTab('${mode}')"]`).classList.add('active');
// Show/hide sections
if (mode === 'url') {
document.getElementById('urlSection').style.display = 'block';
document.getElementById('fileSection').style.display = 'none';
updateTestAudioPlayerFromUrl();
} else {
document.getElementById('urlSection').style.display = 'none';
document.getElementById('fileSection').style.display = 'block';
updateTestAudioPlayerFromFile();
}
}
async function generateAudio() {
const text = document.getElementById('murfText').value;
const murfKey = document.getElementById('murfKey').value;
const statusDiv = document.getElementById('genStatus');
const audioUrlInput = document.getElementById('audioUrl');
if (!text || !murfKey) {
alert("Please enter Text and Murf API Key");
return;
}
statusDiv.innerHTML = "Generating...";
statusDiv.className = '';
try {
const response = await fetch('/generate', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
text: text,
murf_api_key: murfKey
})
});
const data = await response.json();
if (response.ok) {
statusDiv.innerHTML = "Generated! URL copied to input below.";
statusDiv.className = 'success';
// Switch to URL mode
switchTab('url');
audioUrlInput.value = data.audio_url;
// Show and load the generated audio player
const generatedPlayer = document.getElementById('generatedAudioPlayer');
const generatedAudio = document.getElementById('generatedAudio');
generatedAudio.src = data.audio_url;
generatedPlayer.style.display = 'block';
// Also update the test audio player
updateTestAudioPlayerFromUrl();
} else {
statusDiv.innerHTML = "Error: " + (data.detail || JSON.stringify(data));
statusDiv.className = 'error';
}
} catch (e) {
statusDiv.innerHTML = "Error: " + e.message;
statusDiv.className = 'error';
}
}
function updateTestAudioPlayerFromUrl() {
const audioUrl = document.getElementById('audioUrl').value;
const testPlayer = document.getElementById('testAudioPlayer');
const testAudio = document.getElementById('testAudio');
if (currentMode === 'url' && audioUrl && audioUrl.trim() !== '') {
testAudio.src = audioUrl;
testPlayer.style.display = 'block';
} else if (currentMode === 'url') {
testPlayer.style.display = 'none';
}
}
function updateTestAudioPlayerFromFile() {
const fileInput = document.getElementById('audioFile');
const testPlayer = document.getElementById('testAudioPlayer');
const testAudio = document.getElementById('testAudio');
if (currentMode === 'file' && fileInput.files && fileInput.files[0]) {
const file = fileInput.files[0];
const fileUrl = URL.createObjectURL(file);
testAudio.src = fileUrl;
testPlayer.style.display = 'block';
} else if (currentMode === 'file') {
testPlayer.style.display = 'none';
}
}
async function testEndpoint() {
const apiUrl = document.getElementById('apiUrl').value;
const apiKey = document.getElementById('apiKey').value;
const message = document.getElementById('message').value;
const responseDiv = document.getElementById('response');
responseDiv.style.display = 'block';
responseDiv.innerHTML = 'Sending request...';
responseDiv.className = '';
const formData = new FormData();
formData.append('message', message);
// Add authorization header
const headers = {
'x-api-key': apiKey
};
if (currentMode === 'url') {
const audioUrl = document.getElementById('audioUrl').value;
if (!audioUrl) {
alert("Please enter an Audio URL");
return;
}
formData.append('audio_url', audioUrl);
} else {
const fileInput = document.getElementById('audioFile');
if (!fileInput.files || !fileInput.files[0]) {
alert("Please select a file to upload");
return;
}
formData.append('file', fileInput.files[0]);
}
try {
const response = await fetch(apiUrl, {
method: 'POST',
headers: headers,
body: formData
});
const data = await response.json();
if (response.ok) {
responseDiv.innerHTML = '<strong>Success!</strong>\n' + JSON.stringify(data, null, 2);
responseDiv.className = 'success';
} else {
responseDiv.innerHTML = '<strong>Error ' + response.status + ':</strong>\n' + JSON.stringify(data, null, 2);
responseDiv.className = 'error';
}
} catch (error) {
responseDiv.innerHTML = '<strong>Network Error:</strong> ' + error.message;
responseDiv.className = 'error';
}
}
</script>
</body>
</html> |