Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
File size: 75,737 Bytes
f1a0148 31e54a8 f1a0148 31e54a8 f1a0148 7b0064a afeed38 f1a0148 d462da9 f1a0148 31e54a8 f1a0148 afeed38 f1a0148 afeed38 f1a0148 afeed38 f1a0148 afeed38 f1a0148 afeed38 31e54a8 d462da9 afeed38 d462da9 afeed38 d462da9 f1a0148 afeed38 f1a0148 afeed38 f1a0148 afeed38 f1a0148 afeed38 f1a0148 afeed38 f1a0148 afeed38 f1a0148 afeed38 f1a0148 afeed38 f1a0148 afeed38 f1a0148 afeed38 f1a0148 31e54a8 f1a0148 31e54a8 f1a0148 afeed38 f1a0148 afeed38 f1a0148 afeed38 f1a0148 afeed38 f1a0148 afeed38 f1a0148 31e54a8 f1a0148 31e54a8 f1a0148 afeed38 f1a0148 afeed38 f1a0148 afeed38 f1a0148 afeed38 f1a0148 2563acb afeed38 2563acb f1a0148 afeed38 f1a0148 afeed38 f1a0148 afeed38 f1a0148 afeed38 f1a0148 afeed38 f1a0148 afeed38 f1a0148 afeed38 f1a0148 afeed38 f1a0148 afeed38 f1a0148 afeed38 f1a0148 afeed38 f1a0148 afeed38 f1a0148 afeed38 f1a0148 afeed38 f1a0148 afeed38 f1a0148 afeed38 f1a0148 afeed38 f1a0148 afeed38 f1a0148 31e54a8 f1a0148 d462da9 afeed38 d462da9 afeed38 d462da9 afeed38 958c204 d462da9 f1a0148 31e54a8 afeed38 f1a0148 afeed38 f1a0148 afeed38 f1a0148 afeed38 f1a0148 afeed38 f1a0148 31e54a8 7b0064a 31e54a8 afeed38 31e54a8 afeed38 31e54a8 7b0064a afeed38 7b0064a afeed38 f1a0148 afeed38 f1a0148 afeed38 7b0064a f1a0148 afeed38 f1a0148 afeed38 f1a0148 d462da9 afeed38 d462da9 f1a0148 afeed38 f1a0148 afeed38 f1a0148 afeed38 f1a0148 afeed38 f1a0148 afeed38 f1a0148 afeed38 f1a0148 afeed38 f1a0148 afeed38 f1a0148 afeed38 f1a0148 afeed38 f1a0148 afeed38 f1a0148 afeed38 f1a0148 afeed38 f1a0148 afeed38 f1a0148 afeed38 f1a0148 afeed38 f1a0148 afeed38 f1a0148 afeed38 f1a0148 afeed38 f1a0148 afeed38 f1a0148 afeed38 f1a0148 afeed38 f1a0148 afeed38 f1a0148 afeed38 f1a0148 afeed38 f1a0148 afeed38 f1a0148 afeed38 f1a0148 afeed38 f1a0148 afeed38 f1a0148 afeed38 f1a0148 afeed38 f1a0148 afeed38 f1a0148 afeed38 f1a0148 afeed38 f1a0148 afeed38 f1a0148 afeed38 f1a0148 afeed38 f1a0148 afeed38 f1a0148 afeed38 f1a0148 afeed38 f1a0148 afeed38 f1a0148 afeed38 f1a0148 afeed38 f1a0148 afeed38 f1a0148 afeed38 f1a0148 afeed38 f1a0148 afeed38 f1a0148 afeed38 f1a0148 afeed38 f1a0148 afeed38 f1a0148 afeed38 f1a0148 afeed38 f1a0148 afeed38 f1a0148 afeed38 f1a0148 afeed38 f1a0148 afeed38 f1a0148 afeed38 f1a0148 afeed38 f1a0148 afeed38 7b0064a afeed38 f1a0148 afeed38 f1a0148 afeed38 f1a0148 afeed38 f1a0148 afeed38 f1a0148 afeed38 f1a0148 afeed38 f1a0148 afeed38 f1a0148 afeed38 f1a0148 |
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 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 |
{% extends "base.html" %}
{% block title %}Arena - TTS Arena{% endblock %}
{% block current_page %}Arena{% endblock %}
{% block content %}
<div class="tabs">
<div class="tab active" data-tab="tts">TTS</div>
<div class="tab" data-tab="conversational">Conversational</div>
</div>
<div id="tts-tab" class="tab-content active">
<form class="input-container">
<div class="input-group">
<button type="button" class="segmented-btn random-btn" title="Roll random text">
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-shuffle-icon lucide-shuffle">
<path d="m18 14 4 4-4 4" />
<path d="m18 2 4 4-4 4" />
<path d="M2 18h1.973a4 4 0 0 0 3.3-1.7l5.454-8.6a4 4 0 0 1 3.3-1.7H22" />
<path d="M2 6h1.972a4 4 0 0 1 3.6 2.2" />
<path d="M22 18h-6.041a4 4 0 0 1-3.3-1.8l-.359-.45" />
</svg>
</button>
<input type="text" class="text-input" placeholder="Enter text to synthesize...">
<button type="submit" class="segmented-btn synth-btn">Synthesize</button>
</div>
<button type="submit" class="mobile-synth-btn">Synthesize</button>
</form>
<div id="initial-keyboard-hint" class="keyboard-hint">
Press <kbd>R</kbd> for random text, <kbd>N</kbd> for next random round, <kbd>Enter</kbd> to generate
</div>
<div class="loading-container" style="display: none;">
<div class="loader-wrapper">
<div class="loader-animation">
<div class="sound-wave">
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
</div>
</div>
<div class="loader-text">Generating audio samples...</div>
<div class="loader-subtext">This may take up to 30 seconds</div>
</div>
</div>
<div class="players-container" style="display: none;">
<div class="players-row">
<div class="player">
<div class="player-label">Model A <span class="model-name-display"></span></div>
<div class="wave-player-container" data-model="a"></div>
<button class="vote-btn" data-model="a" disabled>
Vote for A
<span class="shortcut-key">A</span>
<span class="vote-loader" style="display: none;">
<div class="vote-spinner"></div>
</span>
</button>
</div>
<div class="player">
<div class="player-label">Model B <span class="model-name-display"></span></div>
<div class="wave-player-container" data-model="b"></div>
<button class="vote-btn" data-model="b" disabled>
Vote for B
<span class="shortcut-key">B</span>
<span class="vote-loader" style="display: none;">
<div class="vote-spinner"></div>
</span>
</button>
</div>
</div>
</div>
<div class="vote-results" style="display: none;">
<h3 class="results-heading">Vote Recorded!</h3>
<div class="results-content">
<div class="chosen-model">
<strong>You chose:</strong> <span class="chosen-model-name"></span>
</div>
<div class="rejected-model">
<strong>Over:</strong> <span class="rejected-model-name"></span>
</div>
</div>
</div>
<div class="next-round-container" style="display: none;">
<button class="next-round-btn">Next Round</button>
</div>
<div id="playback-keyboard-hint" class="keyboard-hint" style="display: none;">
Press <kbd>Space</kbd> to play/pause, <kbd>A</kbd>/<kbd>B</kbd> to vote, <kbd>R</kbd> for random text, <kbd>N</kbd> for next random round
</div>
</div>
<div id="conversational-tab" class="tab-content">
<div class="podcast-container">
<div class="podcast-controls">
<button type="button" class="segmented-btn random-script-btn" title="Load random script">
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-shuffle-icon lucide-shuffle">
<path d="m18 14 4 4-4 4" />
<path d="m18 2 4 4-4 4" />
<path d="M2 18h1.973a4 4 0 0 0 3.3-1.7l5.454-8.6a4 4 0 0 1 3.3-1.7H22" />
<path d="M2 6h1.972a4 4 0 0 1 3.6 2.2" />
<path d="M22 18h-6.041a4 4 0 0 1-3.3-1.8l-.359-.45" />
</svg>
Random Script
</button>
<button type="button" class="podcast-synth-btn">Generate Podcast</button>
</div>
<div class="podcast-script-container">
<div class="podcast-lines">
<!-- Script lines will be added here -->
</div>
<button type="button" class="add-line-btn">+ Add Line</button>
<div class="keyboard-hint podcast-keyboard-hint">
Press <kbd>Ctrl</kbd>+<kbd>Enter</kbd> or <kbd>Alt</kbd>+<kbd>Enter</kbd> to add a new line
</div>
</div>
<div class="podcast-loading-container" style="display: none;">
<div class="loader-wrapper">
<div class="loader-animation">
<div class="sound-wave">
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
</div>
</div>
<div class="loader-text">Generating podcast...</div>
<div class="loader-subtext">This may take up to a minute</div>
</div>
</div>
<div class="podcast-player-container" style="display: none;">
<div class="players-row">
<div class="player">
<div class="player-label">Model A <span class="model-name-display"></span></div>
<div class="podcast-wave-player-a"></div>
<button class="vote-btn" data-model="a" disabled>
Vote for A
<span class="shortcut-key">A</span>
<span class="vote-loader" style="display: none;">
<div class="vote-spinner"></div>
</span>
</button>
</div>
<div class="player">
<div class="player-label">Model B <span class="model-name-display"></span></div>
<div class="podcast-wave-player-b"></div>
<button class="vote-btn" data-model="b" disabled>
Vote for B
<span class="shortcut-key">B</span>
<span class="vote-loader" style="display: none;">
<div class="vote-spinner"></div>
</span>
</button>
</div>
</div>
<div class="podcast-vote-results vote-results" style="display: none;">
<h3 class="results-heading">Vote Recorded!</h3>
<div class="results-content">
<div class="chosen-model">
<strong>You chose:</strong> <span class="chosen-model-name"></span>
</div>
<div class="rejected-model">
<strong>Over:</strong> <span class="rejected-model-name"></span>
</div>
</div>
</div>
<div class="podcast-next-round-container next-round-container" style="display: none;">
<button class="podcast-next-round-btn next-round-btn">Next Round <span class="shortcut-key">N</span></button>
</div>
</div>
</div>
</div>
{% endblock %}
{% block extra_head %}
<link rel="stylesheet" href="{{ url_for('static', filename='css/waveplayer.css') }}">
<script src="https://unpkg.com/wavesurfer.js@6/dist/wavesurfer.min.js"></script>
<style>
.input-container {
display: flex;
flex-direction: column;
margin-bottom: 24px;
}
.input-group {
display: flex;
width: 100%;
border-radius: var(--radius);
border: 1px solid var(--border-color);
overflow: hidden;
}
/* Override base styles to remove duplicate borders */
.input-group .text-input {
flex: 1;
padding: 12px 16px;
border: none;
border-radius: 0;
font-size: 16px;
outline: none;
height: 48px;
transition: none;
}
.input-group .text-input:focus {
border: none;
outline: none;
background-color: rgba(80, 70, 229, 0.03);
}
.segmented-btn {
background-color: white;
border: none;
height: 48px;
display: flex;
align-items: center;
justify-content: center;
cursor: pointer;
transition: background-color 0.2s;
}
.random-btn {
width: 48px;
border-right: 1px solid var(--border-color);
}
.random-btn svg {
color: var(--primary-color);
}
.synth-btn {
padding: 0 24px;
font-weight: 500;
border-left: 1px solid var(--border-color);
background-color: var(--primary-color);
color: white;
font-size: 1em;
}
.synth-btn:hover {
background-color: #4038c7;
}
.random-btn:hover {
background-color: var(--light-gray);
}
.mobile-synth-btn {
display: none;
width: 100%;
padding: 12px;
margin-top: 12px;
background-color: var(--primary-color);
color: white;
border: none;
border-radius: var(--radius);
font-weight: 500;
cursor: pointer;
font-size: 1em;
}
.loading-container {
display: flex;
justify-content: center;
align-items: center;
margin: 40px 0;
}
.loader-wrapper {
text-align: center;
}
.loader-animation {
margin-bottom: 24px;
}
.loader-text {
font-size: 18px;
font-weight: 600;
margin-bottom: 8px;
color: var(--text-color);
}
.loader-subtext {
font-size: 14px;
color: #666;
}
.sound-wave {
height: 60px;
display: flex;
align-items: center;
justify-content: center;
gap: 8px;
}
.sound-wave span {
display: block;
width: 6px;
height: 20px;
background-color: var(--primary-color);
border-radius: 8px;
animation: sound-wave-animation 1.2s infinite ease-in-out;
}
.sound-wave span:nth-child(2) {
animation-delay: 0.2s;
}
.sound-wave span:nth-child(3) {
animation-delay: 0.4s;
}
.sound-wave span:nth-child(4) {
animation-delay: 0.6s;
}
.sound-wave span:nth-child(5) {
animation-delay: 0.8s;
}
.sound-wave span:nth-child(6) {
animation-delay: 1s;
}
@keyframes sound-wave-animation {
0%, 100% {
height: 20px;
}
50% {
height: 50px;
}
}
.vote-btn {
position: relative;
color: black;
font-size: 1rem;
}
.vote-btn.selected {
background-color: var(--primary-color);
color: white;
}
.vote-btn:disabled {
opacity: 0.7;
cursor: not-allowed;
}
.vote-loader {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
display: flex;
align-items: center;
justify-content: center;
background-color: rgba(255, 255, 255, 0.8);
}
.vote-spinner {
width: 20px;
height: 20px;
border: 2px solid rgba(80, 70, 229, 0.3);
border-radius: 50%;
border-top-color: var(--primary-color);
animation: spin 1s linear infinite;
}
.next-round-container {
margin-top: 24px;
text-align: center;
}
.next-round-btn {
padding: 12px 24px;
background-color: var(--primary-color);
color: white;
border: none;
border-radius: var(--radius);
font-weight: 500;
cursor: pointer;
position: relative;
width: 100%;
font-size: 1rem;
transition: background-color 0.2s;
}
.next-round-btn:hover {
background-color: #4038c7;
}
/* Vote results styling */
.vote-results {
background-color: #f0f4ff;
border: 1px solid #d0d7f7;
border-radius: var(--radius);
padding: 16px;
margin: 24px 0;
}
.results-heading {
color: var(--primary-color);
margin-bottom: 12px;
font-size: 18px;
}
.results-content {
display: flex;
flex-direction: column;
gap: 8px;
}
@keyframes spin {
to {
transform: rotate(360deg);
}
}
/* Tab styling */
.tabs {
display: flex;
border-bottom: 1px solid var(--border-color);
margin-bottom: 24px;
}
.tab {
padding: 12px 24px;
cursor: pointer;
position: relative;
font-weight: 500;
}
.tab.active {
color: var(--primary-color);
}
.tab.active::after {
content: '';
position: absolute;
bottom: -1px;
left: 0;
width: 100%;
height: 2px;
background-color: var(--primary-color);
}
.tab-content {
display: none;
}
.tab-content.active {
display: block;
}
/* Coming soon styling */
.coming-soon-container {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
text-align: center;
padding: 60px 20px;
background-color: var(--light-gray);
border-radius: var(--radius);
margin: 20px 0;
}
.coming-soon-icon {
color: var(--primary-color);
margin-bottom: 20px;
}
.coming-soon-title {
font-size: 24px;
font-weight: 600;
margin-bottom: 16px;
color: var(--text-color);
}
.coming-soon-text {
font-size: 16px;
color: #666;
max-width: 500px;
line-height: 1.5;
}
.model-name-display {
font-size: 0.9em;
color: #666;
font-style: italic;
}
/* WaveSurfer Custom Styles */
.player {
padding-bottom: 20px;
}
.wave-player-container {
margin-bottom: 16px;
}
/* Keyboard shortcut hint */
.keyboard-hint {
text-align: center;
margin-top: 8px;
font-size: 13px;
color: #888;
}
.keyboard-hint kbd {
display: inline-block;
padding: 3px 5px;
font-size: 11px;
line-height: 10px;
color: #444;
vertical-align: middle;
background-color: #fafafa;
border: 1px solid #ccc;
border-radius: 3px;
box-shadow: 0 1px 0 rgba(0,0,0,0.2);
margin: 0 2px;
}
@media (max-width: 768px) {
.input-group {
border-radius: var(--radius);
}
.synth-btn {
display: none;
}
.mobile-synth-btn {
display: block;
}
/* Stack players vertically on mobile */
.players-row {
flex-direction: column;
gap: 16px;
}
}
/* Dark mode styles */
@media (prefers-color-scheme: dark) {
.coming-soon-container {
background-color: var(--light-gray);
}
.coming-soon-text {
color: #aaa;
}
.model-name-display {
color: #aaa;
}
/* Fix vote recorded section in dark mode */
.vote-results {
background-color: var(--light-gray);
border-color: var(--border-color);
}
.results-heading {
color: var(--primary-color);
}
.results-content {
color: var(--text-color);
}
.chosen-model,
.rejected-model {
color: var(--text-color);
}
.chosen-model strong,
.rejected-model strong {
color: var(--text-color);
}
.chosen-model-name,
.rejected-model-name {
color: var(--text-color);
}
.vote-btn {
background-color: var(--light-gray);
color: var(--text-color);
border-color: var(--border-color);
}
.vote-btn:hover {
background-color: rgba(255, 255, 255, 0.1);
border-color: var(--border-color);
}
.vote-btn.selected {
background-color: var(--primary-color);
color: white;
border-color: var(--primary-color);
}
.shortcut-key {
background-color: rgba(255, 255, 255, 0.1);
color: var(--text-color);
border-color: var(--border-color);
}
.vote-btn.selected .shortcut-key {
background-color: rgba(255, 255, 255, 0.2);
color: white;
border-color: transparent;
}
.random-btn {
background-color: var(--light-gray);
color: var(--text-color);
border-color: var(--border-color);
}
.random-btn:hover {
background-color: rgba(255, 255, 255, 0.1);
}
.vote-recorded {
background-color: var(--light-gray);
border-color: var(--border-color);
}
/* Ensure border-radius is maintained during loading state */
.vote-btn.loading {
border-radius: var(--radius);
}
/* Dark mode keyboard hint */
.keyboard-hint {
color: #aaa;
}
.keyboard-hint kbd {
color: #ddd;
background-color: #333;
border-color: #555;
box-shadow: 0 1px 0 rgba(255,255,255,0.1);
}
}
/* Podcast UI styles */
.podcast-container {
width: 100%;
}
.podcast-controls {
display: flex;
gap: 12px;
margin-bottom: 24px;
}
.random-script-btn {
display: flex;
align-items: center;
gap: 8px;
padding: 0 16px;
height: 40px;
background-color: white;
border: 1px solid var(--border-color);
border-radius: var(--radius);
cursor: pointer;
transition: background-color 0.2s;
}
.random-script-btn:hover {
background-color: var(--light-gray);
}
.podcast-synth-btn {
padding: 0 24px;
height: 40px;
background-color: var(--primary-color);
color: white;
border: none;
border-radius: var(--radius);
font-weight: 500;
cursor: pointer;
transition: background-color 0.2s;
}
.podcast-synth-btn:hover {
background-color: #4038c7;
}
.podcast-script-container {
border: 1px solid var(--border-color);
border-radius: var(--radius);
overflow: hidden;
margin-bottom: 24px;
}
.podcast-lines {
max-height: 500px;
overflow-y: auto;
}
.podcast-line {
display: flex;
border-bottom: 1px solid var(--border-color);
}
.speaker-label {
width: 120px;
padding: 12px;
display: flex;
align-items: center;
justify-content: center;
font-weight: 500;
border-right: 1px solid var(--border-color);
background-color: var(--light-gray);
white-space: nowrap;
}
.speaker-1 {
color: #3b82f6;
}
.speaker-2 {
color: #ef4444;
}
.line-input {
flex: 1;
padding: 12px;
border: none;
outline: none;
font-size: 1em;
}
.line-input:focus {
background-color: rgba(80, 70, 229, 0.03);
}
.remove-line-btn {
width: 40px;
display: flex;
align-items: center;
justify-content: center;
background: none;
border: none;
border-left: 1px solid var(--border-color);
cursor: pointer;
color: #888;
transition: color 0.2s, background-color 0.2s;
}
.remove-line-btn:hover {
color: #ef4444;
background-color: rgba(239, 68, 68, 0.1);
}
.add-line-btn {
width: 100%;
padding: 12px;
border: none;
background-color: var(--light-gray);
cursor: pointer;
font-weight: 500;
transition: background-color 0.2s;
margin-bottom: 0;
border-bottom: 1px solid var(--border-color);
}
.add-line-btn:hover {
background-color: rgba(80, 70, 229, 0.1);
}
.podcast-keyboard-hint {
padding: 10px;
text-align: center;
background-color: var(--light-gray);
border-top: 1px solid var(--border-color);
margin-top: 0;
font-size: 13px;
}
.podcast-player {
border: 1px solid var(--border-color);
border-radius: var(--radius);
padding: 20px;
margin-bottom: 24px;
}
.podcast-wave-player {
margin: 20px 0;
}
.podcast-transcript-container {
margin-top: 20px;
padding-top: 20px;
border-top: 1px solid var(--border-color);
}
.podcast-transcript {
margin-top: 12px;
line-height: 1.6;
}
.transcript-line {
margin-bottom: 12px;
}
.transcript-speaker {
font-weight: 600;
margin-right: 8px;
}
.transcript-speaker.speaker-1 {
color: #3b82f6;
}
.transcript-speaker.speaker-2 {
color: #ef4444;
}
/* Responsive styles for podcast UI */
@media (max-width: 768px) {
.podcast-controls {
flex-direction: column;
}
.random-script-btn,
.podcast-synth-btn {
width: 100%;
height: 48px;
}
/* Stack podcast players vertically on mobile */
.podcast-player-container .players-row {
flex-direction: column;
gap: 16px;
}
.podcast-line {
flex-direction: column;
padding-bottom: 0;
margin-bottom: 0;
}
.speaker-label {
width: 100%;
border-right: none;
border-bottom: 1px solid var(--border-color);
padding: 8px 10px;
justify-content: flex-start;
}
.line-input {
width: 100%;
padding: 8px 10px;
}
.remove-line-btn {
position: absolute;
top: 6px;
right: 10px;
border-left: none;
background-color: rgba(255, 255, 255, 0.5);
border-radius: 4px;
width: 30px;
height: 30px;
}
.podcast-line {
position: relative;
}
/* Dark mode adjustments for mobile */
@media (prefers-color-scheme: dark) {
.remove-line-btn {
background-color: rgba(50, 50, 60, 0.7);
}
}
}
/* Dark mode styles for podcast UI */
@media (prefers-color-scheme: dark) {
.random-script-btn {
background-color: var(--light-gray);
color: var(--text-color);
border-color: var(--border-color);
}
.add-line-btn {
background-color: var(--light-gray);
color: var(--text-color);
border-color: var(--border-color);
}
.line-input {
background-color: var(--light-gray);
color: var(--text-color);
}
.line-input:focus {
background-color: rgba(108, 99, 255, 0.1);
}
}
.podcast-loading-container {
display: flex;
justify-content: center;
align-items: center;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100vh;
background-color: rgba(255, 255, 255, 0.9);
z-index: 1000;
}
@media (prefers-color-scheme: dark) {
.podcast-loading-container {
background-color: rgba(18, 18, 24, 0.9);
}
}
.podcast-vote-results {
background-color: #f0f4ff;
border: 1px solid #d0d7f7;
border-radius: var(--radius);
padding: 16px;
margin: 24px 0;
}
.podcast-next-round-container {
margin-top: 24px;
text-align: center;
}
.podcast-next-round-btn {
padding: 12px 24px;
background-color: var(--primary-color);
color: white;
border: none;
border-radius: var(--radius);
font-weight: 500;
cursor: pointer;
position: relative;
width: 100%;
font-size: 1rem;
transition: background-color 0.2s;
}
.podcast-next-round-btn:hover {
background-color: #4038c7;
}
/* Dark mode adjustments */
@media (prefers-color-scheme: dark) {
.podcast-vote-results {
background-color: var(--light-gray);
border-color: var(--border-color);
}
}
</style>
{% endblock %}
{% block extra_scripts %}
<script src="{{ url_for('static', filename='js/waveplayer.js') }}"></script>
<script>
document.addEventListener('DOMContentLoaded', function() {
const synthForm = document.querySelector('.input-container');
const synthBtn = document.querySelector('.synth-btn');
const mobileSynthBtn = document.querySelector('.mobile-synth-btn');
const loadingContainer = document.querySelector('.loading-container');
const playersContainer = document.querySelector('.players-container');
const voteButtons = document.querySelectorAll('.vote-btn');
const textInput = document.querySelector('.text-input');
const nextRoundBtn = document.querySelector('.next-round-btn');
const nextRoundContainer = document.querySelector('.next-round-container');
const randomBtn = document.querySelector('.random-btn');
const tabs = document.querySelectorAll('.tab');
const tabContents = document.querySelectorAll('.tab-content');
const voteResultsContainer = document.querySelector('.vote-results');
const chosenModelNameElement = document.querySelector('.chosen-model-name');
const rejectedModelNameElement = document.querySelector('.rejected-model-name');
const modelNameDisplays = document.querySelectorAll('.model-name-display');
const wavePlayerContainers = document.querySelectorAll('.wave-player-container');
// Get references to the keyboard hint elements
const initialKeyboardHint = document.getElementById('initial-keyboard-hint');
const playbackKeyboardHint = document.getElementById('playback-keyboard-hint');
let bothSamplesPlayed = false;
let currentSessionId = null;
let modelNames = { a: '', b: '' };
let wavePlayers = { a: null, b: null };
let cachedSentences = []; // To store sentences available in cache
// Initialize WavePlayers with mobile settings
wavePlayerContainers.forEach(container => {
const model = container.dataset.model;
wavePlayers[model] = new WavePlayer(container, {
// Add mobile-friendly options but hide native controls
backend: 'MediaElement',
mediaControls: false // Hide native audio controls
});
});
// Load fallback sentences directly from Flask variable (JSON string)
// Assign to a variable first to help linters
// eslint-disable-next-line
const fallbackSentencesJson = {{ harvard_sentences | tojson | safe }};
const fallbackRandomTexts = JSON.parse(fallbackSentencesJson);
// Fetch cached sentences on load
function fetchCachedSentences() {
fetch('/api/tts/cached-sentences')
.then(response => response.ok ? response.json() : Promise.reject('Failed to fetch cached sentences'))
.then(data => {
cachedSentences = data;
console.log(`Fetched ${cachedSentences.length} cached sentences.`);
})
.catch(error => {
console.error('Error fetching cached sentences:', error);
// Keep cachedSentences as empty array, fallback will be used
});
}
// Check URL hash for direct tab access
function checkHashAndSetTab() {
const hash = window.location.hash.toLowerCase();
if (hash === '#conversational') {
// Switch to conversational tab
tabs.forEach(t => t.classList.remove('active'));
tabContents.forEach(c => c.classList.remove('active'));
document.querySelector('.tab[data-tab="conversational"]').classList.add('active');
document.getElementById('conversational-tab').classList.add('active');
} else if (hash === '#tts') {
// Switch to TTS tab (explicit)
tabs.forEach(t => t.classList.remove('active'));
tabContents.forEach(c => c.classList.remove('active'));
document.querySelector('.tab[data-tab="tts"]').classList.add('active');
document.getElementById('tts-tab').classList.add('active');
}
}
// Check hash on page load
checkHashAndSetTab();
// Listen for hash changes
window.addEventListener('hashchange', checkHashAndSetTab);
// Tab switching functionality
tabs.forEach(tab => {
tab.addEventListener('click', function() {
const tabId = this.dataset.tab;
// Update URL hash without page reload
history.replaceState(null, null, `#${tabId}`);
// Remove active class from all tabs and contents
tabs.forEach(t => t.classList.remove('active'));
tabContents.forEach(c => c.classList.remove('active'));
// Add active class to clicked tab and corresponding content
this.classList.add('active');
document.getElementById(`${tabId}-tab`).classList.add('active');
// Reset TTS tab state if switching away from it
if (tabId !== 'tts') {
resetToInitialState();
}
});
});
function handleSynthesize(e) {
if (e) {
e.preventDefault();
}
const text = textInput.value.trim();
if (!text) {
openToast("Please enter some text to synthesize", "warning");
return;
}
if (text.length > 1000) {
openToast("Text is too long. Please keep it under 1000 characters.", "warning");
return;
}
textInput.blur();
// Show loading animation and hide hints
loadingContainer.style.display = 'flex';
playersContainer.style.display = 'none';
voteResultsContainer.style.display = 'none';
nextRoundContainer.style.display = 'none';
initialKeyboardHint.style.display = 'none';
playbackKeyboardHint.style.display = 'none';
// Reset vote buttons
voteButtons.forEach(btn => {
btn.disabled = true;
btn.classList.remove('selected');
btn.querySelector('.vote-loader').style.display = 'none';
});
// Clear model name displays
modelNameDisplays.forEach(display => {
display.textContent = '';
});
// Reset the flag for both samples played
bothSamplesPlayed = false;
// Call the API to generate TTS
fetch('/api/tts/generate', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ text: text }),
})
.then(response => {
if (!response.ok) {
return response.json().then(err => {
throw new Error(err.error || 'Failed to generate TTS');
});
}
return response.json();
})
.then(data => {
currentSessionId = data.session_id;
// Load audio in waveplayers
wavePlayers.a.loadAudio(data.audio_a);
wavePlayers.b.loadAudio(data.audio_b);
// Show players and playback hint, hide initial hint
loadingContainer.style.display = 'none';
playersContainer.style.display = 'flex';
initialKeyboardHint.style.display = 'none';
playbackKeyboardHint.style.display = 'block';
// Setup automatic sequential playback
wavePlayers.a.wavesurfer.once('ready', function() {
wavePlayers.a.play();
// When audio A ends, play audio B
wavePlayers.a.wavesurfer.once('finish', function() {
// Wait a short moment before playing B
setTimeout(() => {
wavePlayers.b.play();
// When audio B ends, enable voting
wavePlayers.b.wavesurfer.once('finish', function() {
bothSamplesPlayed = true;
voteButtons.forEach(btn => {
btn.disabled = false;
});
});
}, 500);
});
});
// Fetch cached sentences again to update the list
fetchCachedSentences();
})
.catch(error => {
loadingContainer.style.display = 'none';
openToast(error.message, "error");
console.error('Error:', error);
});
}
function handleVote(model) {
// Disable both vote buttons
voteButtons.forEach(btn => {
btn.disabled = true;
if (btn.dataset.model === model) {
btn.querySelector('.vote-loader').style.display = 'flex';
}
});
// Send vote to server
fetch('/api/tts/vote', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
session_id: currentSessionId,
chosen_model: model
}),
})
.then(response => {
if (!response.ok) {
return response.json().then(err => {
throw new Error(err.error || 'Failed to submit vote');
});
}
return response.json();
})
.then(data => {
// Hide loaders
voteButtons.forEach(btn => {
btn.querySelector('.vote-loader').style.display = 'none';
// Highlight the selected button
if (btn.dataset.model === model) {
btn.classList.add('selected');
}
});
// Store model names from vote response
if (data.chosen_model && data.chosen_model.name) {
modelNames.a = data.names.a;
modelNames.b = data.names.b;
}
// Now display model names after voting
modelNameDisplays[0].textContent = modelNames.a ? `(${modelNames.a})` : '';
modelNameDisplays[1].textContent = modelNames.b ? `(${modelNames.b})` : '';
// Show vote results
chosenModelNameElement.textContent = data.chosen_model.name;
rejectedModelNameElement.textContent = data.rejected_model.name;
voteResultsContainer.style.display = 'block';
// Show next round button
nextRoundContainer.style.display = 'block';
// Show success toast
openToast("Vote recorded successfully!", "success");
})
.catch(error => {
// Re-enable vote buttons
voteButtons.forEach(btn => {
btn.disabled = false;
btn.querySelector('.vote-loader').style.display = 'none';
});
openToast(error.message, "error");
console.error('Error:', error);
});
}
function resetToInitialState() {
// Hide players, results, and next round button
playersContainer.style.display = 'none';
voteResultsContainer.style.display = 'none';
nextRoundContainer.style.display = 'none';
// Reset vote buttons
voteButtons.forEach(btn => {
btn.disabled = true;
btn.classList.remove('selected');
btn.querySelector('.vote-loader').style.display = 'none';
});
// Clear model name displays
modelNameDisplays.forEach(display => {
display.textContent = '';
});
// Reset model names
modelNames = { a: '', b: '' };
// Clear text input
textInput.value = '';
// Stop any playing audio and destroy wavesurfers
for (const model in wavePlayers) {
if (wavePlayers[model]) {
wavePlayers[model].stop();
}
}
// Reset session
currentSessionId = null;
// Reset the flag for both samples played
bothSamplesPlayed = false;
// Show initial hint, hide playback hint
initialKeyboardHint.style.display = 'block';
playbackKeyboardHint.style.display = 'none';
}
function handleRandom() {
let selectedText = '';
if (cachedSentences && cachedSentences.length > 0) {
// Select a random text from the cache
selectedText = cachedSentences[Math.floor(Math.random() * cachedSentences.length)];
console.log("Using random sentence from cache.");
} else {
// Fallback to the initial list if cache is empty or failed to load
console.log("Cache empty or unavailable, using random sentence from fallback list.");
if (fallbackRandomTexts && fallbackRandomTexts.length > 0) {
selectedText = fallbackRandomTexts[Math.floor(Math.random() * fallbackRandomTexts.length)];
} else {
// If fallback list is also empty, do nothing. Log an error.
console.error("Both cached sentences and fallback sentences are unavailable.");
return;
}
}
textInput.value = selectedText;
textInput.focus();
}
function showListenToastMessage() {
openToast("Please listen to both audio samples before voting", "info");
}
// New function for N shortcut: Random + Synthesize
function handleNextRandomRound() {
console.log("Handling Next Random Round (N shortcut)");
handleRandom(); // Selects random text and puts it in input
// Use setTimeout to ensure the input value is updated before synthesizing
// Especially important if handleRandom involves async operations (though it doesn't currently)
setTimeout(() => {
handleSynthesize(); // Triggers synthesis with the text now in the input
}, 0);
}
// Add submit event listener to form
synthForm.addEventListener('submit', handleSynthesize);
// Add click event listeners to vote buttons
voteButtons.forEach(btn => {
btn.addEventListener('click', function() {
if (bothSamplesPlayed) {
const model = this.dataset.model;
handleVote(model);
} else {
showListenToastMessage();
}
});
});
// Add keyboard shortcut listeners
document.addEventListener('keydown', function(e) {
// Check if TTS tab is active
const ttsTab = document.getElementById('tts-tab');
if (!ttsTab.classList.contains('active')) return;
// Only process keyboard shortcuts if text input is not focused
if (document.activeElement === textInput) {
// Allow Enter key to submit form from text input
if (e.key === 'Enter') {
// Check if Shift, Ctrl, Alt, or Meta keys are pressed
if (!e.shiftKey && !e.ctrlKey && !e.altKey && !e.metaKey) {
e.preventDefault(); // Prevent default form submission if needed
handleSynthesize(); // Trigger synthesis
}
}
return; // Don't process other keys if input is focused
}
// Allow Enter key to submit form when button is focused maybe?
// Or just generally allow Enter if not focused on input
if (e.key === 'Enter' && !e.ctrlKey && !e.metaKey && !e.altKey) {
// Check if the initial form is visible (or loading is not happening)
if (playersContainer.style.display === 'none' && loadingContainer.style.display === 'none') {
e.preventDefault();
handleSynthesize();
}
// Do nothing if players are visible (don't want Enter to re-submit)
} else if (e.key.toLowerCase() === 'a') {
if (bothSamplesPlayed && !voteButtons[0].disabled) {
handleVote('a');
} else if (playersContainer.style.display !== 'none' && !bothSamplesPlayed) {
showListenToastMessage();
}
} else if (e.key.toLowerCase() === 'b') {
if (bothSamplesPlayed && !voteButtons[1].disabled) {
handleVote('b');
} else if (playersContainer.style.display !== 'none' && !bothSamplesPlayed) {
showListenToastMessage();
}
} else if (e.key.toLowerCase() === 'n') {
// N for Next Random Round (works anytime except when input focused)
if (!e.ctrlKey && !e.metaKey && !e.altKey) { // Ensure Alt isn't pressed either
e.preventDefault();
handleNextRandomRound(); // New function for random + synthesize
}
} else if (e.key.toLowerCase() === 'r') {
// R for Random Text (works anytime except when input focused)
if (!e.ctrlKey && !e.metaKey && !e.altKey) { // Ensure Alt isn't pressed either
e.preventDefault();
handleRandom();
}
} else if (e.key === ' ') {
// Space to play/pause current audio
if (playersContainer.style.display !== 'none') {
e.preventDefault();
// If A is playing, toggle A, else if B is playing, toggle B, else play A
if (wavePlayers.a.isPlaying) {
wavePlayers.a.togglePlayPause();
} else if (wavePlayers.b.isPlaying) {
wavePlayers.b.togglePlayPause();
} else {
wavePlayers.a.play();
}
}
}
});
// Add event listener for random button
randomBtn.addEventListener('click', handleRandom);
// Add event listener for next round button
nextRoundBtn.addEventListener('click', resetToInitialState);
// Fetch cached sentences when the DOM is ready
fetchCachedSentences();
});
</script>
<script>
document.addEventListener('DOMContentLoaded', function() {
// Variables for podcast UI
const podcastContainer = document.querySelector('.podcast-container');
const podcastLinesContainer = document.querySelector('.podcast-lines');
const addLineBtn = document.querySelector('.add-line-btn');
const randomScriptBtn = document.querySelector('.random-script-btn');
const podcastSynthBtn = document.querySelector('.podcast-synth-btn');
const podcastLoadingContainer = document.querySelector('.podcast-loading-container');
const podcastPlayerContainer = document.querySelector('.podcast-player-container');
const podcastWavePlayerA = document.querySelector('.podcast-wave-player-a');
const podcastWavePlayerB = document.querySelector('.podcast-wave-player-b');
const podcastVoteButtons = podcastPlayerContainer.querySelectorAll('.vote-btn');
const podcastVoteResults = podcastPlayerContainer.querySelector('.vote-results');
const podcastNextRoundContainer = podcastPlayerContainer.querySelector('.next-round-container');
const podcastNextRoundBtn = podcastPlayerContainer.querySelector('.next-round-btn');
const chosenModelNameElement = podcastVoteResults.querySelector('.chosen-model-name');
const rejectedModelNameElement = podcastVoteResults.querySelector('.rejected-model-name');
let podcastWavePlayers = { a: null, b: null };
let bothPodcastSamplesPlayed = false;
let currentPodcastSessionId = null;
let podcastModelNames = { a: 'Model A', b: 'Model B' };
// Sample random scripts for the podcast
const randomScripts = [
[
{ speaker: 1, text: "Welcome to our podcast about artificial intelligence. Today we're discussing the latest advances in text-to-speech technology." },
{ speaker: 2, text: "That's right! Text-to-speech has come a long way in recent years. The voices sound increasingly natural." },
{ speaker: 1, text: "What do you think are the most impressive recent developments?" },
{ speaker: 2, text: "I'd say the emotion and inflection that modern TTS systems can convey is truly remarkable." }
],
[
{ speaker: 1, text: "So today we're talking about climate change and its effects on our planet." },
{ speaker: 2, text: "It's such an important topic. We're seeing more extreme weather events every year." },
{ speaker: 1, text: "Absolutely. And the science is clear that human activity is the primary driver." },
{ speaker: 2, text: "What can individuals do to help address this global challenge?" }
],
[
{ speaker: 1, text: "In today's episode, we're exploring the world of modern cinema." },
{ speaker: 2, text: "Film has evolved so much since its early days. What's your favorite era of movies?" },
{ speaker: 1, text: "I'm particularly fond of the 1970s New Hollywood movement. Films like The Godfather and Taxi Driver really pushed boundaries." },
{ speaker: 2, text: "Interesting choice! I'm more drawn to contemporary international cinema, especially from directors like Bong Joon-ho and Park Chan-wook." }
],
[
{ speaker: 1, text: "Today we're discussing the future of remote work. How do you think it's changed the workplace?" },
{ speaker: 2, text: "I believe it's revolutionized how we think about productivity and work-life balance." },
{ speaker: 1, text: "Do you think companies will continue to offer remote options post-pandemic?" },
{ speaker: 2, text: "Absolutely. Companies that don't embrace flexibility will struggle to attract top talent." }
],
[
{ speaker: 1, text: "Let's talk about the latest developments in renewable energy." },
{ speaker: 2, text: "Solar and wind have become increasingly cost-effective in recent years." },
{ speaker: 1, text: "What about emerging technologies like green hydrogen?" },
{ speaker: 2, text: "That's a fascinating area with huge potential, especially for industries that are difficult to electrify." }
],
[
{ speaker: 1, text: "The world of cryptocurrency has seen massive changes lately. What's your take?" },
{ speaker: 2, text: "It's certainly volatile, but I think blockchain technology has applications beyond just digital currency." },
{ speaker: 1, text: "Do you see it becoming mainstream in the financial sector?" },
{ speaker: 2, text: "Parts of it already are. Central banks are exploring digital currencies, and major companies are investing in blockchain." }
],
[
{ speaker: 1, text: "Mental health awareness has grown significantly in recent years." },
{ speaker: 2, text: "Yes, and it's about time. The stigma around seeking help is finally starting to diminish." },
{ speaker: 1, text: "What do you think has driven this change?" },
{ speaker: 2, text: "I think social media has played a role, with more people openly sharing their experiences." }
],
[
{ speaker: 1, text: "Space exploration is entering an exciting new era with private companies leading the charge." },
{ speaker: 2, text: "The commercialization of space has definitely accelerated innovation in the field." },
{ speaker: 1, text: "Do you think we'll see humans on Mars in our lifetime?" },
{ speaker: 2, text: "I'm optimistic. The technology is advancing rapidly, and there's strong motivation from both public and private sectors." }
],
[
{ speaker: 1, text: "Today's topic is sustainable fashion. How can consumers make more ethical choices?" },
{ speaker: 2, text: "It starts with buying less and choosing quality items that last longer." },
{ speaker: 1, text: "What about the responsibility of fashion brands themselves?" },
{ speaker: 2, text: "They need to be transparent about their supply chains and commit to reducing their environmental impact." }
],
[
{ speaker: 1, text: "Let's discuss the evolution of social media and its impact on society." },
{ speaker: 2, text: "It's transformed how we connect, but also created new challenges like misinformation and privacy concerns." },
{ speaker: 1, text: "Do you think regulation is the answer?" },
{ speaker: 2, text: "Partly, but digital literacy education is equally important so people can navigate these platforms responsibly." }
],
[
{ speaker: 1, text: "The field of genomics has seen remarkable progress. What excites you most about it?" },
{ speaker: 2, text: "Personalized medicine is fascinating - the idea that treatments can be tailored to an individual's genetic makeup." },
{ speaker: 1, text: "What about the ethical considerations?" },
{ speaker: 2, text: "Those are crucial. We need robust frameworks to ensure these technologies are used responsibly." }
],
[
{ speaker: 1, text: "Urban planning is facing new challenges in the 21st century. What trends are you seeing?" },
{ speaker: 2, text: "There's a growing focus on creating walkable, mixed-use neighborhoods that reduce car dependency." },
{ speaker: 1, text: "How are cities adapting to climate change?" },
{ speaker: 2, text: "Many are implementing green infrastructure like parks and permeable surfaces to manage flooding and reduce heat islands." }
],
[
{ speaker: 1, text: "The gaming industry has grown enormously in recent years. What's driving this expansion?" },
{ speaker: 2, text: "Gaming has become much more accessible across different platforms, and the pandemic certainly accelerated adoption." },
{ speaker: 1, text: "What do you think about the rise of esports?" },
{ speaker: 2, text: "It's fascinating to see competitive gaming achieve mainstream recognition and create new career opportunities." }
],
[
{ speaker: 1, text: "Let's talk about the future of transportation. How will we get around in 20 years?" },
{ speaker: 2, text: "Electric vehicles will be dominant, and autonomous driving technology will be much more widespread." },
{ speaker: 1, text: "What about public transit and alternative modes?" },
{ speaker: 2, text: "I think we'll see more integrated systems where bikes, scooters, and public transit work seamlessly together." }
]
];
// Initialize with 2 empty lines
function initializePodcastLines() {
podcastLinesContainer.innerHTML = '';
addPodcastLine(1);
addPodcastLine(2);
}
// Add a new podcast line
function addPodcastLine(speakerNum = null) {
const lineCount = podcastLinesContainer.querySelectorAll('.podcast-line').length;
// If speaker number isn't specified, alternate between 1 and 2
if (speakerNum === null) {
speakerNum = (lineCount % 2) + 1;
}
const lineElement = document.createElement('div');
lineElement.className = 'podcast-line';
lineElement.innerHTML = `
<div class="speaker-label speaker-${speakerNum}">Speaker ${speakerNum}</div>
<input type="text" class="line-input" placeholder="Enter dialog...">
<button type="button" class="remove-line-btn" tabindex="-1">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none"
stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<line x1="18" y1="6" x2="6" y2="18"></line>
<line x1="6" y1="6" x2="18" y2="18"></line>
</svg>
</button>
`;
podcastLinesContainer.appendChild(lineElement);
// Add event listener to remove button
const removeBtn = lineElement.querySelector('.remove-line-btn');
removeBtn.addEventListener('click', function() {
// Don't allow removing if there are only 2 lines
if (podcastLinesContainer.querySelectorAll('.podcast-line').length > 2) {
lineElement.remove();
} else {
openToast("At least 2 lines are required", "warning");
}
});
// Add event listener for keyboard navigation in the input field
const inputField = lineElement.querySelector('.line-input');
inputField.addEventListener('keydown', function(e) {
// Alt+Enter or Ctrl+Enter to add new line
if (e.key === 'Enter' && (e.altKey || e.ctrlKey)) {
e.preventDefault();
addPodcastLine();
// Focus the new line's input field
setTimeout(() => {
const inputs = podcastLinesContainer.querySelectorAll('.line-input');
inputs[inputs.length - 1].focus();
}, 10);
}
});
return lineElement;
}
// Load a random script
function loadRandomScript() {
// Clear existing lines
podcastLinesContainer.innerHTML = '';
// Select a random script
const randomScript = randomScripts[Math.floor(Math.random() * randomScripts.length)];
// Add each line from the script
randomScript.forEach(line => {
const lineElement = addPodcastLine(line.speaker);
lineElement.querySelector('.line-input').value = line.text;
});
}
// Generate podcast (mock functionality)
function generatePodcast() {
// Get all lines
const lines = [];
podcastLinesContainer.querySelectorAll('.podcast-line').forEach(line => {
const speaker_id = line.querySelector('.speaker-label').textContent.includes('1') ? 0 : 1;
const text = line.querySelector('.line-input').value.trim();
if (text) {
lines.push({ speaker_id, text });
}
});
// Validate that we have at least 2 lines with content
if (lines.length < 2) {
openToast("Please enter at least 2 lines of dialog", "warning");
return;
}
// Reset vote buttons and hide results
podcastVoteButtons.forEach(btn => {
btn.disabled = true;
btn.classList.remove('selected');
btn.querySelector('.vote-loader').style.display = 'none';
});
// Clear model name displays
const modelNameDisplays = podcastPlayerContainer.querySelectorAll('.model-name-display');
modelNameDisplays.forEach(display => {
display.textContent = '';
});
podcastVoteResults.style.display = 'none';
podcastNextRoundContainer.style.display = 'none';
// Reset the flag for both samples played
bothPodcastSamplesPlayed = false;
// Show loading animation
podcastLoadingContainer.style.display = 'flex';
podcastPlayerContainer.style.display = 'none';
// Call API to generate podcast
fetch('/api/conversational/generate', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ script: lines }),
})
.then(response => {
if (!response.ok) {
return response.json().then(err => {
throw new Error(err.error || 'Failed to generate podcast');
});
}
return response.json();
})
.then(data => {
currentPodcastSessionId = data.session_id;
// Hide loading
podcastLoadingContainer.style.display = 'none';
// Show player
podcastPlayerContainer.style.display = 'block';
// Initialize WavePlayers if not already done
if (!podcastWavePlayers.a) {
podcastWavePlayers.a = new WavePlayer(podcastWavePlayerA, {
// Add mobile-friendly options but hide native controls
backend: 'MediaElement',
mediaControls: false // Hide native audio controls
});
podcastWavePlayers.b = new WavePlayer(podcastWavePlayerB, {
// Add mobile-friendly options but hide native controls
backend: 'MediaElement',
mediaControls: false // Hide native audio controls
});
// Load audio in waveplayers
podcastWavePlayers.a.loadAudio(data.audio_a);
podcastWavePlayers.b.loadAudio(data.audio_b);
// Force hide loading indicators after 5 seconds as a fallback
setTimeout(() => {
if (podcastWavePlayers.a && podcastWavePlayers.a.hideLoading) {
podcastWavePlayers.a.hideLoading();
}
if (podcastWavePlayers.b && podcastWavePlayers.b.hideLoading) {
podcastWavePlayers.b.hideLoading();
}
console.log('Forced hiding of podcast loading indicators (safety timeout - existing players)');
}, 5000);
} else {
// Reset and reload for existing players
try {
podcastWavePlayers.a.wavesurfer.empty();
podcastWavePlayers.b.wavesurfer.empty();
// Make sure loading indicators are reset
podcastWavePlayers.a.hideLoading();
podcastWavePlayers.b.hideLoading();
podcastWavePlayers.a.loadAudio(data.audio_a);
podcastWavePlayers.b.loadAudio(data.audio_b);
// Force hide loading indicators after 5 seconds as a fallback
setTimeout(() => {
if (podcastWavePlayers.a && podcastWavePlayers.a.hideLoading) {
podcastWavePlayers.a.hideLoading();
}
if (podcastWavePlayers.b && podcastWavePlayers.b.hideLoading) {
podcastWavePlayers.b.hideLoading();
}
console.log('Forced hiding of podcast loading indicators (safety timeout - existing players)');
}, 5000);
} catch (err) {
console.error('Error resetting podcast waveplayers:', err);
// Recreate the players if there was an error
podcastWavePlayers.a = new WavePlayer(podcastWavePlayerA, {
backend: 'MediaElement',
mediaControls: false
});
podcastWavePlayers.b = new WavePlayer(podcastWavePlayerB, {
backend: 'MediaElement',
mediaControls: false
});
podcastWavePlayers.a.loadAudio(data.audio_a);
podcastWavePlayers.b.loadAudio(data.audio_b);
// Force hide loading indicators after 5 seconds as a fallback
setTimeout(() => {
if (podcastWavePlayers.a && podcastWavePlayers.a.hideLoading) {
podcastWavePlayers.a.hideLoading();
}
if (podcastWavePlayers.b && podcastWavePlayers.b.hideLoading) {
podcastWavePlayers.b.hideLoading();
}
console.log('Forced hiding of podcast loading indicators (fallback case)');
}, 5000);
}
}
// Setup automatic sequential playback
podcastWavePlayers.a.wavesurfer.once('ready', function() {
podcastWavePlayers.a.play();
// When audio A ends, play audio B
podcastWavePlayers.a.wavesurfer.once('finish', function() {
// Wait a short moment before playing B
setTimeout(() => {
podcastWavePlayers.b.play();
// When audio B ends, enable voting
podcastWavePlayers.b.wavesurfer.once('finish', function() {
bothPodcastSamplesPlayed = true;
podcastVoteButtons.forEach(btn => {
btn.disabled = false;
});
});
}, 500);
});
});
})
.catch(error => {
podcastLoadingContainer.style.display = 'none';
openToast(error.message, "error");
console.error('Error:', error);
});
}
// Handle vote for a podcast model
function handlePodcastVote(model) {
// Disable both vote buttons
podcastVoteButtons.forEach(btn => {
btn.disabled = true;
if (btn.dataset.model === model) {
btn.querySelector('.vote-loader').style.display = 'flex';
}
});
// Send vote to server
fetch('/api/conversational/vote', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
session_id: currentPodcastSessionId,
chosen_model: model
}),
})
.then(response => {
if (!response.ok) {
return response.json().then(err => {
throw new Error(err.error || 'Failed to submit vote');
});
}
return response.json();
})
.then(data => {
// Hide loaders
podcastVoteButtons.forEach(btn => {
btn.querySelector('.vote-loader').style.display = 'none';
// Highlight the selected button
if (btn.dataset.model === model) {
btn.classList.add('selected');
}
});
// Store model names from vote response
podcastModelNames.a = data.names.a;
podcastModelNames.b = data.names.b;
// Show model names after voting
const modelNameDisplays = podcastPlayerContainer.querySelectorAll('.model-name-display');
modelNameDisplays[0].textContent = data.names.a ? `(${data.names.a})` : '';
modelNameDisplays[1].textContent = data.names.b ? `(${data.names.b})` : '';
// Show vote results
chosenModelNameElement.textContent = data.chosen_model.name;
rejectedModelNameElement.textContent = data.rejected_model.name;
podcastVoteResults.style.display = 'block';
// Show next round button
podcastNextRoundContainer.style.display = 'block';
// Show success toast
openToast("Vote recorded successfully!", "success");
})
.catch(error => {
// Re-enable vote buttons
podcastVoteButtons.forEach(btn => {
btn.disabled = false;
btn.querySelector('.vote-loader').style.display = 'none';
});
openToast(error.message, "error");
console.error('Error:', error);
});
}
// Reset podcast UI to initial state
function resetPodcastState() {
// Hide players, results, and next round button
podcastPlayerContainer.style.display = 'none';
podcastVoteResults.style.display = 'none';
podcastNextRoundContainer.style.display = 'none';
// Reset vote buttons
podcastVoteButtons.forEach(btn => {
btn.disabled = true;
btn.classList.remove('selected');
btn.querySelector('.vote-loader').style.display = 'none';
});
// Clear model name displays
const modelNameDisplays = podcastPlayerContainer.querySelectorAll('.model-name-display');
modelNameDisplays.forEach(display => {
display.textContent = '';
});
// Stop any playing audio
if (podcastWavePlayers.a) podcastWavePlayers.a.stop();
if (podcastWavePlayers.b) podcastWavePlayers.b.stop();
// Reset session
currentPodcastSessionId = null;
// Reset the flag for both samples played
bothPodcastSamplesPlayed = false;
}
// Add keyboard shortcut listeners for podcast voting
document.addEventListener('keydown', function(e) {
// Check if we're in the podcast tab and it's active
const podcastTab = document.getElementById('conversational-tab');
if (!podcastTab.classList.contains('active')) return;
// Only process if input fields are not focused
if (document.activeElement.tagName === 'INPUT' ||
document.activeElement.tagName === 'TEXTAREA') {
return;
}
if (e.key.toLowerCase() === 'a') {
if (bothPodcastSamplesPlayed && !podcastVoteButtons[0].disabled) {
handlePodcastVote('a');
} else if (podcastPlayerContainer.style.display !== 'none' && !bothPodcastSamplesPlayed) {
openToast("Please listen to both audio samples before voting", "info");
}
} else if (e.key.toLowerCase() === 'b') {
if (bothPodcastSamplesPlayed && !podcastVoteButtons[1].disabled) {
handlePodcastVote('b');
} else if (podcastPlayerContainer.style.display !== 'none' && !bothPodcastSamplesPlayed) {
openToast("Please listen to both audio samples before voting", "info");
}
} else if (e.key.toLowerCase() === 'n') {
if (podcastNextRoundContainer.style.display === 'block') {
if (!e.ctrlKey && !e.metaKey) {
e.preventDefault();
}
resetPodcastState();
}
} else if (e.key === ' ') {
// Space to play/pause current audio
if (podcastPlayerContainer.style.display !== 'none') {
e.preventDefault();
// If A is playing, toggle A, else if B is playing, toggle B, else play A
if (podcastWavePlayers.a && podcastWavePlayers.a.isPlaying) {
podcastWavePlayers.a.togglePlayPause();
} else if (podcastWavePlayers.b && podcastWavePlayers.b.isPlaying) {
podcastWavePlayers.b.togglePlayPause();
} else if (podcastWavePlayers.a) {
podcastWavePlayers.a.play();
}
}
}
});
// Event listeners
addLineBtn.addEventListener('click', function() {
addPodcastLine();
});
randomScriptBtn.addEventListener('click', function() {
loadRandomScript();
});
podcastSynthBtn.addEventListener('click', function() {
generatePodcast();
});
// Add event listeners to vote buttons
podcastVoteButtons.forEach(btn => {
btn.addEventListener('click', function() {
if (bothPodcastSamplesPlayed) {
const model = this.dataset.model;
handlePodcastVote(model);
} else {
openToast("Please listen to both audio samples before voting", "info");
}
});
});
// Add event listener for next round button
podcastNextRoundBtn.addEventListener('click', resetPodcastState);
// Initialize with 2 empty lines
initializePodcastLines();
});
</script>
{% endblock %} |