File size: 34,448 Bytes
68a99fc 444be0b 68a99fc 5ed4c17 68a99fc aa3ab7e 68a99fc 444be0b 68a99fc 444be0b 68a99fc 4e37ea9 db918ab 4e37ea9 db918ab 4e37ea9 db918ab 4e37ea9 db918ab 4e37ea9 db918ab 4e37ea9 db918ab 4e37ea9 db918ab 4e37ea9 db918ab 4e37ea9 db918ab 4e37ea9 db918ab 4e37ea9 db918ab 4e37ea9 db918ab 4e37ea9 db918ab 4e37ea9 db918ab 4e37ea9 db918ab 4e37ea9 db918ab 4e37ea9 db918ab 4e37ea9 db918ab 4e37ea9 db918ab 4e37ea9 db918ab 4e37ea9 db918ab 4e37ea9 db918ab 4e37ea9 db918ab 4e37ea9 db918ab 4e37ea9 db918ab 68a99fc 249f430 68a99fc 249f430 68a99fc 249f430 7f974bd 249f430 7f974bd 249f430 7f974bd 249f430 7f974bd 249f430 7f974bd 249f430 68a99fc aa3ab7e 68a99fc aa3ab7e 5ed4c17 68a99fc aa3ab7e 5ed4c17 68a99fc aa3ab7e 68a99fc 444be0b 68a99fc aa3ab7e 68a99fc |
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 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 |
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>TTS Generator</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
:root {
--bg: #0a0e27;
--surface: #141b3d;
--primary: #00ff88;
--secondary: #ff00ff;
--accent: #00d4ff;
--error: #ff1744;
--text: #ffffff;
--border: 4px;
}
body {
font-family: 'Space Grotesk', 'Courier New', monospace;
background: var(--bg);
color: var(--text);
min-height: 100vh;
overflow-x: hidden;
position: relative;
}
body::before {
content: '';
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background:
radial-gradient(circle at 20% 50%, rgba(0, 255, 136, 0.1) 0%, transparent 50%),
radial-gradient(circle at 80% 80%, rgba(255, 0, 255, 0.1) 0%, transparent 50%),
radial-gradient(circle at 40% 20%, rgba(0, 212, 255, 0.1) 0%, transparent 50%);
pointer-events: none;
z-index: 0;
}
.container {
max-width: 1400px;
margin: 0 auto;
padding: 2rem;
position: relative;
z-index: 1;
}
header {
text-align: center;
margin-bottom: 3rem;
animation: slideDown 0.6s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}
@keyframes slideDown {
from {
opacity: 0;
transform: translateY(-50px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
h1 {
font-size: clamp(2rem, 5vw, 4rem);
font-weight: 900;
background: linear-gradient(135deg, var(--primary) 0%, var(--accent) 50%, var(--secondary) 100%);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
background-clip: text;
text-transform: uppercase;
letter-spacing: -2px;
margin-bottom: 1rem;
position: relative;
display: inline-block;
}
h1::after {
content: '';
position: absolute;
bottom: -10px;
left: 50%;
transform: translateX(-50%);
width: 60%;
height: 6px;
background: linear-gradient(90deg, transparent, var(--primary), transparent);
animation: glow 2s ease-in-out infinite;
}
@keyframes glow {
0%,
100% {
opacity: 0.5;
}
50% {
opacity: 1;
}
}
.subtitle {
font-size: 1.2rem;
color: var(--accent);
letter-spacing: 2px;
}
.input-section {
background: var(--surface);
border: var(--border) solid var(--primary);
box-shadow: 8px 8px 0 var(--primary);
padding: 2rem;
margin-bottom: 3rem;
position: relative;
transition: all 0.3s ease;
animation: slideUp 0.6s cubic-bezier(0.68, -0.55, 0.265, 1.55) 0.2s both;
}
@keyframes slideUp {
from {
opacity: 0;
transform: translateY(50px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
.input-section:hover {
transform: translate(-2px, -2px);
box-shadow: 12px 12px 0 var(--primary);
}
textarea {
width: 100%;
height: 150px;
background: rgba(0, 212, 255, 0.05);
border: 3px solid var(--accent);
color: var(--text);
padding: 1rem;
font-family: inherit;
font-size: 1.1rem;
resize: vertical;
margin-bottom: 1.5rem;
transition: all 0.3s ease;
}
textarea:focus {
outline: none;
border-color: var(--primary);
background: rgba(0, 255, 136, 0.05);
}
.controls {
display: flex;
gap: 1rem;
margin-bottom: 1.5rem;
flex-wrap: wrap;
}
.control-group {
flex: 1;
min-width: 200px;
}
label {
display: block;
margin-bottom: 0.5rem;
color: var(--accent);
font-weight: bold;
}
select,
input[type="number"] {
width: 100%;
padding: 0.8rem;
background: var(--bg);
border: 2px solid var(--accent);
color: var(--text);
font-family: inherit;
font-size: 1rem;
}
.btn {
background: var(--primary);
color: var(--bg);
border: var(--border) solid var(--bg);
padding: 1rem 2rem;
font-size: 1.1rem;
font-weight: 900;
text-transform: uppercase;
cursor: pointer;
transition: all 0.2s ease;
box-shadow: 4px 4px 0 var(--bg);
letter-spacing: 1px;
position: relative;
width: 100%;
}
.btn:hover:not(:disabled) {
transform: translate(-2px, -2px);
box-shadow: 6px 6px 0 var(--bg);
}
.btn:active:not(:disabled) {
transform: translate(2px, 2px);
box-shadow: 2px 2px 0 var(--bg);
}
.btn:disabled {
opacity: 0.6;
cursor: not-allowed;
}
.btn-secondary {
background: var(--accent);
}
.btn-small {
padding: 0.5rem 1rem;
font-size: 0.85rem;
box-shadow: 3px 3px 0 var(--bg);
text-decoration: none;
display: inline-block;
color: var(--bg);
}
.btn-small:hover:not(:disabled) {
box-shadow: 4px 4px 0 var(--bg);
transform: translate(-2px, -2px);
}
.table-section {
animation: slideUp 0.6s cubic-bezier(0.68, -0.55, 0.265, 1.55) 0.4s both;
}
.table-wrapper {
overflow-x: auto;
background: var(--surface);
border: var(--border) solid var(--secondary);
box-shadow: 8px 8px 0 var(--secondary);
}
table {
width: 100%;
border-collapse: collapse;
}
thead {
background: linear-gradient(135deg, var(--primary), var(--accent));
}
th {
padding: 1.5rem 1rem;
text-align: left;
font-weight: 900;
text-transform: uppercase;
letter-spacing: 1px;
color: var(--bg);
border-right: 3px solid var(--bg);
}
th:last-child {
border-right: none;
}
tbody tr {
border-bottom: 2px solid rgba(0, 212, 255, 0.2);
transition: all 0.3s ease;
animation: fadeIn 0.5s ease;
}
@keyframes fadeIn {
from {
opacity: 0;
}
to {
opacity: 1;
}
}
tbody tr:hover {
background: rgba(0, 255, 136, 0.1);
}
td {
padding: 1.5rem 1rem;
color: var(--text);
}
.status {
display: inline-block;
padding: 0.5rem 1rem;
border: 3px solid;
font-weight: 900;
text-transform: uppercase;
font-size: 0.85rem;
letter-spacing: 1px;
}
.status-not_started {
background: var(--bg);
border-color: var(--accent);
color: var(--accent);
}
.status-processing {
background: var(--bg);
border-color: var(--primary);
color: var(--primary);
animation: pulse 1.5s ease-in-out infinite;
}
@keyframes pulse {
0%,
100% {
opacity: 1;
}
50% {
opacity: 0.6;
}
}
.status-completed {
background: var(--primary);
border-color: var(--primary);
color: var(--bg);
}
.status-failed {
background: var(--error);
border-color: var(--error);
color: var(--text);
}
/* Progress display */
.status-progress {
display: flex;
flex-direction: column;
gap: 0.3rem;
min-width: 120px;
}
.progress-bar-container {
width: 100%;
height: 6px;
background: rgba(0, 212, 255, 0.2);
border: 1px solid var(--accent);
overflow: hidden;
}
.progress-bar {
height: 100%;
background: linear-gradient(90deg, var(--primary), var(--accent));
transition: width 0.3s ease;
animation: progressPulse 1.5s ease-in-out infinite;
}
@keyframes progressPulse {
0%,
100% {
opacity: 1;
}
50% {
opacity: 0.7;
}
}
.progress-text {
font-size: 0.7rem;
color: var(--accent);
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.text-cell {
max-width: 300px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.empty-state {
text-align: center;
padding: 4rem 2rem;
color: var(--accent);
font-size: 1.2rem;
}
.refresh-btn {
position: fixed;
bottom: 2rem;
right: 2rem;
width: 60px;
height: 60px;
border-radius: 50%;
background: var(--secondary);
border: var(--border) solid var(--bg);
box-shadow: 4px 4px 0 var(--bg);
cursor: pointer;
transition: all 0.3s ease;
display: flex;
align-items: center;
justify-content: center;
font-size: 1.5rem;
z-index: 1000;
}
.refresh-btn:hover {
transform: rotate(180deg) scale(1.1);
box-shadow: 6px 6px 0 var(--bg);
}
/* Loader styles */
.loader-overlay {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(10, 14, 39, 0.95);
display: flex;
align-items: center;
justify-content: center;
z-index: 9999;
animation: fadeIn 0.3s ease;
}
.loader {
width: 80px;
height: 80px;
border: 6px solid var(--surface);
border-top: 6px solid var(--primary);
border-right: 6px solid var(--accent);
border-bottom: 6px solid var(--secondary);
border-radius: 50%;
animation: spin 1s linear infinite;
}
@keyframes spin {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}
.loader-text {
position: absolute;
margin-top: 120px;
font-size: 1.2rem;
font-weight: 900;
color: var(--primary);
text-transform: uppercase;
letter-spacing: 2px;
}
@media (max-width: 768px) {
.container {
padding: 1rem;
}
.input-section,
.table-wrapper {
box-shadow: 4px 4px 0 var(--primary);
}
th,
td {
padding: 1rem 0.5rem;
font-size: 0.9rem;
}
.text-cell {
max-width: 150px;
}
}
.notification {
position: fixed;
top: 2rem;
right: 2rem;
padding: 1.5rem 2rem;
background: var(--primary);
color: var(--bg);
border: var(--border) solid var(--bg);
box-shadow: 6px 6px 0 var(--bg);
font-weight: 900;
z-index: 2000;
animation: slideInRight 0.5s ease, slideOutRight 0.5s ease 3.5s;
}
@keyframes slideInRight {
from {
transform: translateX(400px);
opacity: 0;
}
to {
transform: translateX(0);
opacity: 1;
}
}
@keyframes slideOutRight {
to {
transform: translateX(400px);
opacity: 0;
}
}
/* Text Popup Modal */
.text-modal-overlay {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(10, 14, 39, 0.95);
display: flex;
align-items: center;
justify-content: center;
z-index: 9999;
animation: fadeIn 0.3s ease;
padding: 2rem;
}
.text-modal {
background: var(--surface);
border: var(--border) solid var(--accent);
box-shadow: 8px 8px 0 var(--accent);
max-width: 800px;
width: 100%;
max-height: 80vh;
display: flex;
flex-direction: column;
animation: slideUp 0.3s ease;
}
.text-modal-header {
display: flex;
justify-content: space-between;
align-items: center;
padding: 1rem 1.5rem;
background: linear-gradient(135deg, var(--primary), var(--accent));
border-bottom: 3px solid var(--bg);
}
.text-modal-header h3 {
color: var(--bg);
font-weight: 900;
text-transform: uppercase;
letter-spacing: 1px;
}
.text-modal-close {
background: var(--bg);
border: 2px solid var(--bg);
color: var(--primary);
width: 36px;
height: 36px;
font-size: 1.2rem;
cursor: pointer;
display: flex;
align-items: center;
justify-content: center;
transition: all 0.2s ease;
}
.text-modal-close:hover {
background: var(--error);
color: var(--text);
}
.text-modal-content {
padding: 1.5rem;
overflow-y: auto;
flex: 1;
}
.text-modal-content pre {
white-space: pre-wrap;
word-wrap: break-word;
font-family: inherit;
font-size: 1rem;
line-height: 1.6;
color: var(--text);
margin: 0;
}
.text-modal-footer {
padding: 1rem 1.5rem;
border-top: 2px solid rgba(0, 212, 255, 0.2);
display: flex;
gap: 1rem;
justify-content: flex-end;
}
.btn-view-text {
background: var(--accent);
padding: 0.4rem 0.8rem;
font-size: 0.8rem;
box-shadow: 2px 2px 0 var(--bg);
}
.btn-view-text:hover {
transform: translate(-1px, -1px);
box-shadow: 3px 3px 0 var(--bg);
}
.text-cell-wrapper {
display: flex;
align-items: center;
gap: 0.5rem;
}
.text-cell-wrapper .text-preview {
max-width: 200px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
</style>
</head>
<body>
<div class="container">
<header>
<h1>TTS Generator</h1>
<p class="subtitle">Text β’ Process β’ Audio</p>
</header>
<div class="input-section">
<h2 style="margin-bottom: 1.5rem; color: var(--primary);">Generate Audio</h2>
<textarea id="textInput" placeholder="Enter text to convert to speech..."></textarea>
<div class="controls">
<div class="control-group">
<label>Voice</label>
<select id="voiceSelect">
<!-- Index 0: Default -->
<option value="0" style="display: none;">Default Mix (af)</option>
<!-- American Female (indices 1-11) -->
<optgroup label="American Female">
<option value="1">Alloy</option>
<option value="2">Aoede</option>
<option value="3">Bella</option>
<option value="4">Heart</option>
<option value="5">Jessica</option>
<option value="6">Kore</option>
<option value="7">Nicole</option>
<option value="8">Nova</option>
<option value="9">River</option>
<option value="10">Sarah</option>
<option value="11">Sky</option>
</optgroup>
<!-- American Male (indices 12-20) -->
<optgroup label="American Male">
<option value="12">Adam</option>
<option value="13">Echo</option>
<option value="14">Eric</option>
<option value="15">Fenrir</option>
<option value="16">Liam</option>
<option value="17">Michael</option>
<option value="18">Onyx</option>
<option value="19">Puck</option>
<option value="20">Santa</option>
</optgroup>
<!-- British Female (indices 21-24) -->
<optgroup label="British Female">
<option value="21">Alice</option>
<option value="22">Emma</option>
<option value="23">Isabella</option>
<option value="24">Lily</option>
</optgroup>
<!-- British Male (indices 25-28) -->
<optgroup label="British Male">
<option value="25">Daniel</option>
<option value="26">Fable</option>
<option value="27">George</option>
<option value="28" selected>Lewis</option>
</optgroup>
<!-- European (indices 29-31) -->
<optgroup label="European">
<option value="29">Dora (Female)</option>
<option value="30">Alex (Male)</option>
<option value="31">Santa (Male)</option>
</optgroup>
<!-- French (index 32) -->
<optgroup label="French">
<option value="32">Siwis (Female)</option>
</optgroup>
<!-- Hindi (indices 33-36) -->
<optgroup label="Hindi">
<option value="33">Alpha (Female)</option>
<option value="34">Beta (Female)</option>
<option value="35">Omega (Male)</option>
<option value="36">Psi (Male)</option>
</optgroup>
<!-- Italian (indices 37-38) -->
<optgroup label="Italian">
<option value="37">Sara (Female)</option>
<option value="38">Nicola (Male)</option>
</optgroup>
<!-- Japanese (indices 39-43) -->
<optgroup label="Japanese">
<option value="39">Alpha (Female)</option>
<option value="40">Gongitsune (Female)</option>
<option value="41">Nezumi (Female)</option>
<option value="42">Tebukuro (Female)</option>
<option value="43">Kumo (Male)</option>
</optgroup>
<!-- Portuguese (indices 44-46) -->
<optgroup label="Portuguese">
<option value="44">Dora (Female)</option>
<option value="45">Alex (Male)</option>
<option value="46">Santa (Male)</option>
</optgroup>
<!-- Chinese Female (indices 47-50) -->
<optgroup label="Chinese Female">
<option value="47">Xiaobei</option>
<option value="48">Xiaoni</option>
<option value="49">Xiaoxiao</option>
<option value="50">Xiaoyi</option>
</optgroup>
<!-- Chinese Male (indices 51-54) -->
<optgroup label="Chinese Male">
<option value="51">Yunjian</option>
<option value="52">Yunxi</option>
<option value="53">Yunxia</option>
<option value="54">Yunyang</option>
</optgroup>
</select>
</div>
<div class="control-group">
<label>Speed</label>
<input type="number" id="speedInput" value="1.0" step="0.1" min="0.5" max="2.0">
</div>
</div>
<div style="display: flex; gap: 1rem; flex-wrap: wrap;">
<button class="btn" id="generateBtn" style="flex: 1; min-width: 200px;">
π Generate Audio
</button>
<button class="btn btn-secondary" id="uploadBtn" style="flex: 1; min-width: 200px;">
π Upload File
</button>
<input type="file" id="fileInput" accept=".txt,.md,.text" style="display: none;">
</div>
</div>
<div class="table-section">
<h2 style="margin-bottom: 1.5rem; color: var(--secondary);">Processing Queue</h2>
<div class="table-wrapper">
<table>
<thead>
<tr>
<th>Text</th>
<th>Status</th>
<th>Audio</th>
<th>Created</th>
<th>Processed</th>
</tr>
</thead>
<tbody id="filesTable">
<tr>
<td colspan="5" class="empty-state">No tasks yet. Start by generating audio!
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<button class="refresh-btn" id="refreshBtn" title="Refresh">π</button>
<!-- Loader -->
<div class="loader-overlay" id="loader" style="display: none;">
<div>
<div class="loader"></div>
<div class="loader-text">Queuing...</div>
</div>
</div>
<script>
const API_URL = '/api';
// Elements
const textInput = document.getElementById('textInput');
const voiceSelect = document.getElementById('voiceSelect');
const speedInput = document.getElementById('speedInput');
const generateBtn = document.getElementById('generateBtn');
const uploadBtn = document.getElementById('uploadBtn');
const fileInput = document.getElementById('fileInput');
const loader = document.getElementById('loader');
const refreshBtn = document.getElementById('refreshBtn');
// Generate button
generateBtn.addEventListener('click', async () => {
const text = textInput.value.trim();
if (!text) {
showNotification('Please enter some text!', 'error');
return;
}
const voice = voiceSelect.value;
const speed = parseFloat(speedInput.value);
// Show loader
loader.style.display = 'flex';
generateBtn.disabled = true;
try {
const response = await fetch(`${API_URL}/generate`, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
text,
voice,
speed
})
});
const data = await response.json();
if (response.ok) {
showNotification('Task queued successfully! π');
textInput.value = '';
loadFiles();
} else {
showNotification(data.error || 'Generation failed', 'error');
}
} catch (error) {
showNotification('Network error: ' + error.message, 'error');
} finally {
// Hide loader
loader.style.display = 'none';
generateBtn.disabled = false;
}
});
// Upload button - opens file picker
uploadBtn.addEventListener('click', () => {
fileInput.click();
});
// File input change - fill textarea with file content
fileInput.addEventListener('change', (e) => {
const file = e.target.files[0];
if (!file) return;
// Read file content
const reader = new FileReader();
reader.onload = (event) => {
const text = event.target.result.trim();
if (!text) {
showNotification('File is empty!', 'error');
fileInput.value = '';
return;
}
// Fill textarea with file content
textInput.value = text;
showNotification(`Loaded "${file.name}" - Ready to generate! π`);
fileInput.value = ''; // Reset for next upload
};
reader.onerror = () => {
showNotification('Error reading file!', 'error');
fileInput.value = '';
};
reader.readAsText(file);
});
// Load files
async function loadFiles() {
try {
const response = await fetch(`${API_URL}/files`);
const files = await response.json();
// Store files data for popup access
filesData = files;
const tbody = document.getElementById('filesTable');
if (files.length === 0) {
tbody.innerHTML = '<tr><td colspan="5" class="empty-state">No tasks yet. Start by generating audio!</td></tr>';
return;
}
tbody.innerHTML = files.map((file, index) => {
// Escape text for HTML attribute and display
const escapedText = escapeHtml(file.text);
const truncatedText = file.text.length > 50 ? file.text.substring(0, 50) + '...' : file.text;
// Build status display with progress
let statusDisplay = '';
if (file.status === 'processing') {
const progressPercent = file.progress || 0;
const progressText = file.progress_text || 'Processing...';
statusDisplay = `
<div class="status-progress">
<span class="status status-${file.status}">${progressPercent}%</span>
<div class="progress-bar-container">
<div class="progress-bar" style="width: ${progressPercent}%"></div>
</div>
<span class="progress-text">${escapeHtml(progressText)}</span>
</div>
`;
} else {
statusDisplay = `<span class="status status-${file.status}">${file.status.replace('_', ' ')}</span>`;
}
return `
<tr>
<td>
<div class="text-cell-wrapper">
<span class="text-preview" title="${escapedText}">${escapeHtml(truncatedText)}</span>
<button class="btn btn-small btn-view-text" onclick="showTextPopup(${index})">ποΈ View</button>
</div>
</td>
<td>${statusDisplay}</td>
<td>
${file.status === 'completed' && file.output_file ?
`<a href="${API_URL}/download/${file.id}" class="btn btn-small btn-secondary" target="_blank">β¬οΈ</a>`
: 'β'}
</td>
<td>${new Date(file.created_at).toLocaleString()}</td>
<td>${file.processed_at ? new Date(file.processed_at).toLocaleString() : 'β'}</td>
</tr>
`;
}).join('');
} catch (error) {
console.error('Error loading files:', error);
}
}
// Refresh button
refreshBtn.addEventListener('click', () => {
loadFiles();
const icon = refreshBtn.textContent;
refreshBtn.textContent = 'β³';
setTimeout(() => refreshBtn.textContent = icon, 500);
});
// Auto-refresh every 10 minutes
setInterval(loadFiles, 1000 * 60 * 10);
// Initial load
loadFiles();
// Notification system
function showNotification(message, type = 'success') {
const notification = document.createElement('div');
notification.className = 'notification';
if (type === 'error') {
notification.style.background = 'var(--error)';
notification.style.borderColor = 'var(--error)';
}
notification.textContent = message;
document.body.appendChild(notification);
setTimeout(() => {
notification.remove();
}, 4000);
}
// Store files data for popup access
let filesData = [];
// Escape HTML to prevent XSS
function escapeHtml(text) {
const div = document.createElement('div');
div.textContent = text;
return div.innerHTML;
}
// Show text popup
function showTextPopup(index) {
const file = filesData[index];
if (!file) return;
// Create modal overlay
const overlay = document.createElement('div');
overlay.className = 'text-modal-overlay';
overlay.onclick = (e) => {
if (e.target === overlay) overlay.remove();
};
// Create modal content
overlay.innerHTML = `
<div class="text-modal">
<div class="text-modal-header">
<h3>π Full Text</h3>
<button class="text-modal-close" onclick="this.closest('.text-modal-overlay').remove()">β</button>
</div>
<div class="text-modal-content">
<pre>${escapeHtml(file.text)}</pre>
</div>
<div class="text-modal-footer">
<button class="btn btn-small btn-secondary" onclick="copyTextToClipboard(${index})">π Copy Text</button>
<button class="btn btn-small" onclick="this.closest('.text-modal-overlay').remove()">Close</button>
</div>
</div>
`;
document.body.appendChild(overlay);
// Close on Escape key
const handleEscape = (e) => {
if (e.key === 'Escape') {
overlay.remove();
document.removeEventListener('keydown', handleEscape);
}
};
document.addEventListener('keydown', handleEscape);
}
// Copy text to clipboard
function copyTextToClipboard(index) {
const file = filesData[index];
if (!file) return;
navigator.clipboard.writeText(file.text).then(() => {
showNotification('Text copied to clipboard! π');
}).catch((err) => {
console.error('Failed to copy:', err);
showNotification('Failed to copy text', 'error');
});
}
</script>
</body>
</html> |