GitHub Actions commited on
Commit ·
afeed38
1
Parent(s): d730de6
Sync from GitHub repo
Browse files27 unmodified lines2829303132333435363739 unmodified lines7778798081828335 unmodified lines11912012112212312412512612712812941 unmodified lines171172173174175176177833 unmodified lines1011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310343 unmodified lines1038103910401041104210431044104510461047104810491050105110521053105410552 unmodified lines105810591060106110621063106410651066106710681069107010711072107310741075107610771078107918 unmodified lines109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112212 unmodified lines11351136113711381139114011411142114311441145114611471148114911501151115211534 unmodified lines1158115911601161116211631 unmodified line116511661167116811691170117111721173117411751 unmodified line11771178117911801181118213 unmodified lines11961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512265 unmodified lines1232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512766 unmodified lines128312841285128612871288128912905 unmodified lines129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313849 unmodified lines139413951396139713981399140095 unmodified lines14961497149814991500150115021503150415 unmodified lines152015211522152315241525152615271 unmodified line1529153015311532153315341535153615371538153915404 unmodified lines1545154615471548154915501551155215531554155515561557155815591560156115624 unmodified lines156715681569157015711572157315741575157615771578157915801581158215832 unmodified lines158615871588158915901591159215931594159515961597159812 unmodified lines161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216334 unmodified lines16381639164016411642164316441645164616471648164916501651165216536 unmodified lines1660166116621663166416656 unmodified lines1672167316741675167616776 unmodified lines16841685168616871688168916901691169216931694169516969 unmodified lines170617071708170917101711171217131714171517161 unmodified line17181719172017211722172313 unmodified lines1737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517664 unmodified lines177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318746 unmodified lines1881188218831884188518865 unmodified lines1892189318941895189618971898189927 unmodified lines<button type="submit" class="mobile-synth-btn">Synthesize</button></form><div class="keyboard-hint" id="tts-input-hint">Press <kbd>R</kbd> for random text, <kbd>Enter</kbd> to synthesize, <kbd>N</kbd> for random + synthesize</div><div class="loading-container" style="display: none;"><div class="loader-wrapper"><div class="loader-animation">39 unmodified lines</div><div class="keyboard-hint">Press <kbd>Space</kbd> to play/pause audio, <kbd>A</kbd> or <kbd>B</kbd> to vote after listening, <kbd>R</kbd> for random text, <kbd>Enter</kbd> to synthesize, <kbd>N</kbd> for new random + synthesize</div></div>35 unmodified lines<!-- Script lines will be added here --></div><div class="keyboard-hint podcast-keyboard-hint" id="podcast-input-hint">Press <kbd>Ctrl</kbd>+<kbd>Enter</kbd> or <kbd>Alt</kbd>+<kbd>Enter</kbd> to add a new line, <kbd>R</kbd> for random script, <kbd>Enter</kbd> to generate, <kbd>N</kbd> for random + generate</div><button type="button" class="add-line-btn">+ Add Line</button></div><div class="podcast-loading-container" style="display: none;">41 unmodified lines</div><div class="keyboard-hint">Press <kbd>Space</kbd> to play/pause audio, <kbd>A</kbd> or <kbd>B</kbd> to vote after listening, <kbd>R</kbd> for random script, <kbd>Enter</kbd> to generate, <kbd>N</kbd> for new random + generate</div><div class="podcast-vote-results vote-results" style="display: none;">833 unmodified linesconst rejectedModelNameElement = document.querySelector('.rejected-model-name');const modelNameDisplays = document.querySelectorAll('.model-name-display');const wavePlayerContainers = document.querySelectorAll('.wave-player-container');const ttsInputHint = document.getElementById('tts-input-hint');let bothSamplesPlayed = false;let currentSessionId = null;let modelNames = { a: '', b: '' };let wavePlayers = { a: null, b: null };let cachedSentences = [];wavePlayerContainers.forEach(container => {const model = container.dataset.model;wavePlayers[model] = new WavePlayer(container, {backend: 'MediaElement',mediaControls: false});});const fallbackRandomTexts = JSON.parse({{ harvard_sentences | tojson | safe }});function fetchCachedSentences() {fetch('/api/tts/cached-sentences').then(response => response.ok ? response.json() : Promise.reject('Failed to fetch cached sentences'))3 unmodified lines}).catch(error => {console.error('Error fetching cached sentences:', error);});}function checkHashAndSetTab() {const hash = window.location.hash.toLowerCase();if (hash === '#conversational') {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') {tabs.forEach(t => t.classList.remove('active'));tabContents.forEach(c => c.classList.remove('active'));2 unmodified lines}}checkHashAndSetTab();window.addEventListener('hashchange', checkHashAndSetTab);tabs.forEach(tab => {tab.addEventListener('click', function() {const tabId = this.dataset.tab;history.replaceState(null, null, `#${tabId}`);tabs.forEach(t => t.classList.remove('active'));tabContents.forEach(c => c.classList.remove('active'));this.classList.add('active');document.getElementById(`${tabId}-tab`).classList.add('active');if (tabId !== 'tts') {resetToInitialState();}18 unmodified linestextInput.blur();if (ttsInputHint) ttsInputHint.style.display = 'none';loadingContainer.style.display = 'flex';playersContainer.style.display = 'none';voteResultsContainer.style.display = 'none';nextRoundContainer.style.display = 'none';voteButtons.forEach(btn => {btn.disabled = true;btn.classList.remove('selected');btn.querySelector('.vote-loader').style.display = 'none';});modelNameDisplays.forEach(display => {display.textContent = '';});bothSamplesPlayed = false;fetch('/api/tts/generate', {method: 'POST',headers: {12 unmodified lines.then(data => {currentSessionId = data.session_id;wavePlayers.a.loadAudio(data.audio_a);wavePlayers.b.loadAudio(data.audio_b);loadingContainer.style.display = 'none';playersContainer.style.display = 'flex';wavePlayers.a.wavesurfer.once('ready', function() {wavePlayers.a.play();wavePlayers.a.wavesurfer.once('finish', function() {setTimeout(() => {wavePlayers.b.play();wavePlayers.b.wavesurfer.once('finish', function() {bothSamplesPlayed = true;voteButtons.forEach(btn => {4 unmodified lines});});fetchCachedSentences();}).catch(error => {1 unmodified lineopenToast(error.message, "error");console.error('Error:', error);});if (ttsInputHint) ttsInputHint.style.display = 'block';}function handleVote(model) {voteButtons.forEach(btn => {btn.disabled = true;if (btn.dataset.model === model) {1 unmodified line}});fetch('/api/tts/vote', {method: 'POST',headers: {13 unmodified linesreturn response.json();}).then(data => {voteButtons.forEach(btn => {btn.querySelector('.vote-loader').style.display = 'none';if (btn.dataset.model === model) {btn.classList.add('selected');}});if (data.chosen_model && data.chosen_model.name) {modelNames.a = data.names.a;modelNames.b = data.names.b;}modelNameDisplays[0].textContent = modelNames.a ? `(${modelNames.a})` : '';modelNameDisplays[1].textContent = modelNames.b ? `(${modelNames.b})` : '';chosenModelNameElement.textContent = data.chosen_model.name;rejectedModelNameElement.textContent = data.rejected_model.name;voteResultsContainer.style.display = 'block';nextRoundContainer.style.display = 'block';openToast("Vote recorded successfully!", "success");}).catch(error => {voteButtons.forEach(btn => {btn.disabled = false;btn.querySelector('.vote-loader').style.display = 'none';5 unmodified lines}function resetToInitialState() {playersContainer.style.display = 'none';voteResultsContainer.style.display = 'none';nextRoundContainer.style.display = 'none';voteButtons.forEach(btn => {btn.disabled = true;btn.classList.remove('selected');btn.querySelector('.vote-loader').style.display = 'none';});modelNameDisplays.forEach(display => {display.textContent = '';});modelNames = { a: '', b: '' };textInput.value = '';for (const model in wavePlayers) {if (wavePlayers[model]) {wavePlayers[model].stop();}}currentSessionId = null;bothSamplesPlayed = false;}function handleRandom() {let selectedText = '';if (cachedSentences && cachedSentences.length > 0) {selectedText = cachedSentences[Math.floor(Math.random() * cachedSentences.length)];console.log("Using random sentence from cache.");} else {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 {console.error("Both cached sentences and fallback sentences are unavailable.");return;}6 unmodified linesopenToast("Please listen to both audio samples before voting", "info");}synthForm.addEventListener('submit', handleSynthesize);voteButtons.forEach(btn => {btn.addEventListener('click', function() {if (bothSamplesPlayed) {5 unmodified lines});});document.addEventListener('keydown', function(e) {const ttsTab = document.getElementById('tts-tab');if (!ttsTab.classList.contains('active')) return;const isInputVisible = playersContainer.style.display === 'none' && loadingContainer.style.display === 'none';const isPlaybackVisible = playersContainer.style.display !== 'none';const isNextRoundVisible = nextRoundContainer.style.display === 'block';if (document.activeElement === textInput) {if (e.key === 'Enter' && isInputVisible) {e.preventDefault();handleSynthesize();}return;}if (isInputVisible) {if (e.key.toLowerCase() === 'r') {if (!e.ctrlKey && !e.metaKey) {e.preventDefault();handleRandom();}} else if (e.key === 'Enter') {e.preventDefault();handleSynthesize();} else if (e.key.toLowerCase() === 'n') {if (!e.ctrlKey && !e.metaKey) {e.preventDefault();handleRandom();setTimeout(() => {handleSynthesize();}, 50);}}}else if (isPlaybackVisible) {if (e.key === ' ') {e.preventDefault();if (wavePlayers.a.isPlaying) {wavePlayers.a.togglePlayPause();} else if (wavePlayers.b.isPlaying) {wavePlayers.b.togglePlayPause();} else if (wavePlayers.a) {if (wavePlayers.a.wavesurfer.getCurrentTime() < wavePlayers.a.wavesurfer.getDuration()) {wavePlayers.a.play();} else if (wavePlayers.b) {wavePlayers.b.play();}}} else if (e.key.toLowerCase() === 'a') {if (bothSamplesPlayed && !voteButtons[0].disabled) {handleVote('a');} else if (!bothSamplesPlayed) {showListenToastMessage();}} else if (e.key.toLowerCase() === 'b') {if (bothSamplesPlayed && !voteButtons[1].disabled) {handleVote('b');} else if (!bothSamplesPlayed) {showListenToastMessage();}}}else if (isNextRoundVisible && e.key.toLowerCase() === 'n') {if (!e.ctrlKey && !e.metaKey) {e.preventDefault();}resetToInitialState();}});randomBtn.addEventListener('click', handleRandom);nextRoundBtn.addEventListener('click', resetToInitialState);fetchCachedSentences();});</script><script>document.addEventListener('DOMContentLoaded', function() {const podcastContainer = document.querySelector('.podcast-container');const podcastLinesContainer = document.querySelector('.podcast-lines');const addLineBtn = document.querySelector('.add-line-btn');9 unmodified linesconst podcastNextRoundBtn = podcastPlayerContainer.querySelector('.next-round-btn');const chosenModelNameElement = podcastVoteResults.querySelector('.chosen-model-name');const rejectedModelNameElement = podcastVoteResults.querySelector('.rejected-model-name');const podcastInputHint = document.getElementById('podcast-input-hint');let podcastWavePlayers = { a: null, b: null };let bothPodcastSamplesPlayed = false;95 unmodified linesaddPodcastLine(2);}function addPodcastLine(speakerNum = null) {const lineCount = podcastLinesContainer.querySelectorAll('.podcast-line').length;if (speakerNum === null) {speakerNum = (lineCount % 2) + 1;}15 unmodified linespodcastLinesContainer.appendChild(lineElement);const removeBtn = lineElement.querySelector('.remove-line-btn');removeBtn.addEventListener('click', function() {if (podcastLinesContainer.querySelectorAll('.podcast-line').length > 2) {lineElement.remove();} else {1 unmodified line}});const inputField = lineElement.querySelector('.line-input');inputField.addEventListener('keydown', function(e) {if (e.key === 'Enter' && (e.altKey || e.ctrlKey)) {e.preventDefault();addPodcastLine();setTimeout(() => {const inputs = podcastLinesContainer.querySelectorAll('.line-input');inputs[inputs.length - 1].focus();4 unmodified linesreturn lineElement;}function loadRandomScript() {podcastLinesContainer.innerHTML = '';const randomScript = randomScripts[Math.floor(Math.random() * randomScripts.length)];randomScript.forEach(line => {const lineElement = addPodcastLine(line.speaker);lineElement.querySelector('.line-input').value = line.text;});}function generatePodcast() {const lines = [];podcastLinesContainer.querySelectorAll('.podcast-line').forEach(line => {const speaker_id = line.querySelector('.speaker-label').textContent.includes('1') ? 0 : 1;4 unmodified lines}});if (lines.length < 2) {openToast("Please enter at least 2 lines of dialog", "warning");return;}podcastVoteButtons.forEach(btn => {btn.disabled = true;btn.classList.remove('selected');btn.querySelector('.vote-loader').style.display = 'none';});const modelNameDisplays = podcastPlayerContainer.querySelectorAll('.model-name-display');modelNameDisplays.forEach(display => {display.textContent = '';2 unmodified linespodcastVoteResults.style.display = 'none';podcastNextRoundContainer.style.display = 'none';bothPodcastSamplesPlayed = false;if (podcastInputHint) podcastInputHint.style.display = 'none';podcastLoadingContainer.style.display = 'flex';podcastPlayerContainer.style.display = 'none';fetch('/api/conversational/generate', {method: 'POST',headers: {12 unmodified lines.then(data => {currentPodcastSessionId = data.session_id;podcastLoadingContainer.style.display = 'none';podcastPlayerContainer.style.display = 'block';if (!podcastWavePlayers.a) {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);setTimeout(() => {if (podcastWavePlayers.a && podcastWavePlayers.a.hideLoading) {podcastWavePlayers.a.hideLoading();4 unmodified linesconsole.log('Forced hiding of podcast loading indicators (safety timeout - existing players)');}, 5000);} else {try {podcastWavePlayers.a.wavesurfer.empty();podcastWavePlayers.b.wavesurfer.empty();podcastWavePlayers.a.hideLoading();podcastWavePlayers.b.hideLoading();podcastWavePlayers.a.loadAudio(data.audio_a);podcastWavePlayers.b.loadAudio(data.audio_b);setTimeout(() => {if (podcastWavePlayers.a && podcastWavePlayers.a.hideLoading) {podcastWavePlayers.a.hideLoading();6 unmodified lines} catch (err) {console.error('Error resetting podcast waveplayers:', err);podcastWavePlayers.a = new WavePlayer(podcastWavePlayerA, {backend: 'MediaElement',mediaControls: false6 unmodified linespodcastWavePlayers.a.loadAudio(data.audio_a);podcastWavePlayers.b.loadAudio(data.audio_b);setTimeout(() => {if (podcastWavePlayers.a && podcastWavePlayers.a.hideLoading) {podcastWavePlayers.a.hideLoading();6 unmodified lines}}podcastWavePlayers.a.wavesurfer.once('ready', function() {podcastWavePlayers.a.play();podcastWavePlayers.a.wavesurfer.once('finish', function() {setTimeout(() => {podcastWavePlayers.b.play();podcastWavePlayers.b.wavesurfer.once('finish', function() {bothPodcastSamplesPlayed = true;podcastVoteButtons.forEach(btn => {9 unmodified linesopenToast(error.message, "error");console.error('Error:', error);});if (podcastInputHint) podcastInputHint.style.display = 'block';}function handlePodcastVote(model) {podcastVoteButtons.forEach(btn => {btn.disabled = true;if (btn.dataset.model === model) {1 unmodified line}});fetch('/api/conversational/vote', {method: 'POST',headers: {13 unmodified linesreturn response.json();}).then(data => {podcastVoteButtons.forEach(btn => {btn.querySelector('.vote-loader').style.display = 'none';if (btn.dataset.model === model) {btn.classList.add('selected');}});podcastModelNames.a = data.names.a;podcastModelNames.b = data.names.b;modelNameDisplays = podcastPlayerContainer.querySelectorAll('.model-name-display');modelNameDisplays[0].textContent = data.names.a ? `(${data.names.a})` : '';modelNameDisplays[1].textContent = data.names.b ? `(${data.names.b})` : '';chosenModelNameElement.textContent = data.chosen_model.name;rejectedModelNameElement.textContent = data.rejected_model.name;podcastVoteResults.style.display = 'block';podcastNextRoundContainer.style.display = 'block';openToast("Vote recorded successfully!", "success");}).catch(error => {podcastVoteButtons.forEach(btn => {btn.disabled = false;btn.querySelector('.vote-loader').style.display = 'none';4 unmodified lines});}function resetPodcastState() {podcastPlayerContainer.style.display = 'none';podcastVoteResults.style.display = 'none';podcastNextRoundContainer.style.display = 'none';podcastVoteButtons.forEach(btn => {btn.disabled = true;btn.classList.remove('selected');btn.querySelector('.vote-loader').style.display = 'none';});modelNameDisplays = podcastPlayerContainer.querySelectorAll('.model-name-display');modelNameDisplays.forEach(display => {display.textContent = '';});if (podcastWavePlayers.a) podcastWavePlayers.a.stop();if (podcastWavePlayers.b) podcastWavePlayers.b.stop();currentPodcastSessionId = null;bothPodcastSamplesPlayed = false;}document.addEventListener('keydown', function(e) {const podcastTab = document.getElementById('conversational-tab');if (!podcastTab.classList.contains('active')) return;const isScriptEditorVisible = podcastPlayerContainer.style.display === 'none' && podcastLoadingContainer.style.display === 'none';const isPodcastPlaybackVisible = podcastPlayerContainer.style.display !== 'none';const isPodcastNextRoundVisible = podcastNextRoundContainer.style.display === 'block';const activeElementTag = document.activeElement.tagName;const isInputFocused = activeElementTag === 'INPUT' || activeElementTag === 'TEXTAREA';if (isInputFocused && e.key === 'Enter' && (e.altKey || e.ctrlKey)) {return;}if (isInputFocused) {return;}if (e.key.toLowerCase() === 'r' && isScriptEditorVisible) {if (!e.ctrlKey && !e.metaKey) {e.preventDefault();loadRandomScript();}} else if (e.key === 'Enter' && isScriptEditorVisible) {e.preventDefault();generatePodcast();} else if (e.key.toLowerCase() === 'n' && isScriptEditorVisible) {if (!e.ctrlKey && !e.metaKey) {e.preventDefault();loadRandomScript();setTimeout(() => {generatePodcast();}, 50);}}else if (isPodcastPlaybackVisible) {if (e.key === ' ') {e.preventDefault();if (podcastWavePlayers.a && podcastWavePlayers.a.isPlaying) {podcastWavePlayers.a.togglePlayPause();} else if (podcastWavePlayers.b && podcastWavePlayers.b.isPlaying) {podcastWavePlayers.b.togglePlayPause();} else if (podcastWavePlayers.a) {if (podcastWavePlayers.a.wavesurfer.getCurrentTime() < podcastWavePlayers.a.wavesurfer.getDuration()) {podcastWavePlayers.a.play();} else if (podcastWavePlayers.b) {podcastWavePlayers.b.play();}}} else if (e.key.toLowerCase() === 'a') {if (bothPodcastSamplesPlayed && !podcastVoteButtons[0].disabled) {handlePodcastVote('a');} else if (!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 (!bothPodcastSamplesPlayed) {openToast("Please listen to both audio samples before voting", "info");}}}else if (isPodcastNextRoundVisible && e.key.toLowerCase() === 'n') {if (!e.ctrlKey && !e.metaKey) {e.preventDefault();}resetPodcastState();}});addLineBtn.addEventListener('click', function() {addPodcastLine();});6 unmodified linesgeneratePodcast();});podcastVoteButtons.forEach(btn => {btn.addEventListener('click', function() {if (bothPodcastSamplesPlayed) {5 unmodified lines});});podcastNextRoundBtn.addEventListener('click', resetPodcastState);initializePodcastLines();});</script>27 unmodified lines28293031323339 unmodified lines7374757677787935 unmodified lines11511611711811912012112212312412541 unmodified lines167168169170171172173833 unmodified lines10071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310343 unmodified lines10381039104010411042104310441045104610471048104910501051105210531054105510561057105810592 unmodified lines1062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109018 unmodified lines110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113612 unmodified lines11491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211734 unmodified lines11781179118011811182118311841 unmodified line11861187118811891190119111921193119411951 unmodified line119711981199120012011202120313 unmodified lines12171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512565 unmodified lines126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613176 unmodified lines13241325132613271328132913301331133213335 unmodified lines1339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914109 unmodified lines14201421142214231424142595 unmodified lines1521152215231524152515261527152815291530153115 unmodified lines15471548154915501551155215531554155515561 unmodified line1558155915601561156215631564156515661567156815691570157115724 unmodified lines1577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916004 unmodified lines160516061607160816091610161116121613161416151616161716181619162016211622162316242 unmodified lines1627162816291630163116321633163416351636163716381639164012 unmodified lines1653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116824 unmodified lines16871688168916901691169216931694169516961697169816991700170117021703170417056 unmodified lines17121713171417151716171717186 unmodified lines17251726172717281729173017316 unmodified lines173817391740174117421743174417451746174717481749175017511752175317549 unmodified lines176417651766176717681769177017711772177317741 unmodified line177617771778177917801781178213 unmodified lines179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218334 unmodified lines18381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119226 unmodified lines19291930193119321933193419355 unmodified lines194119421943194419451946194719481949195027 unmodified lines<button type="submit" class="mobile-synth-btn">Synthesize</button></form><div class="loading-container" style="display: none;"><div class="loader-wrapper"><div class="loader-animation">39 unmodified lines</div><div class="keyboard-hint">Press <kbd>Space</kbd> to play/pause audio, <kbd>A</kbd> or <kbd>B</kbd> to vote after listening, <kbd>R</kbd> for random audio, <kbd>Enter</kbd> to generate</div></div>35 unmodified 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;">41 unmodified lines</div><div class="keyboard-hint">Press <kbd>Space</kbd> to play/pause audio, <kbd>A</kbd> or <kbd>B</kbd> to vote after listening, <kbd>R</kbd> for random audio, <kbd>Enter</kbd> to generate</div><div class="podcast-vote-results vote-results" style="display: none;">833 unmodified linesconst rejectedModelNameElement = document.querySelector('.rejected-model-name');const modelNameDisplays = document.querySelectorAll('.model-name-display');const wavePlayerContainers = document.querySelectorAll('.wave-player-container');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 settingswavePlayerContainers.forEach(container => {const model = container.dataset.model;wavePlayers[model] = new WavePlayer(container, {// Add mobile-friendly options but hide native controlsbackend: 'MediaElement',mediaControls: false // Hide native audio controls});});// Load fallback sentences directly from Flask variable (JSON string)// Note: This might cause linter errors, but JSON is JS-compatible.const fallbackRandomTexts = JSON.parse({{ harvard_sentences | tojson | safe }});// Fetch cached sentences on loadfunction fetchCachedSentences() {fetch('/api/tts/cached-sentences').then(response => response.ok ? response.json() : Promise.reject('Failed to fetch cached sentences'))3 unmodified lines}).catch(error => {console.error('Error fetching cached sentences:', error);// Keep cachedSentences as empty array, fallback will be used});}// Check URL hash for direct tab accessfunction checkHashAndSetTab() {const hash = window.location.hash.toLowerCase();if (hash === '#conversational') {// Switch to conversational tabtabs.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'));2 unmodified lines}}// Check hash on page loadcheckHashAndSetTab();// Listen for hash changeswindow.addEventListener('hashchange', checkHashAndSetTab);// Tab switching functionalitytabs.forEach(tab => {tab.addEventListener('click', function() {const tabId = this.dataset.tab;// Update URL hash without page reloadhistory.replaceState(null, null, `#${tabId}`);// Remove active class from all tabs and contentstabs.forEach(t => t.classList.remove('active'));tabContents.forEach(c => c.classList.remove('active'));// Add active class to clicked tab and corresponding contentthis.classList.add('active');document.getElementById(`${tabId}-tab`).classList.add('active');// Reset TTS tab state if switching away from itif (tabId !== 'tts') {resetToInitialState();}18 unmodified linestextInput.blur();// Show loading animationloadingContainer.style.display = 'flex';playersContainer.style.display = 'none';voteResultsContainer.style.display = 'none';nextRoundContainer.style.display = 'none';// Reset vote buttonsvoteButtons.forEach(btn => {btn.disabled = true;btn.classList.remove('selected');btn.querySelector('.vote-loader').style.display = 'none';});// Clear model name displaysmodelNameDisplays.forEach(display => {display.textContent = '';});// Reset the flag for both samples playedbothSamplesPlayed = false;// Call the API to generate TTSfetch('/api/tts/generate', {method: 'POST',headers: {12 unmodified lines.then(data => {currentSessionId = data.session_id;// Load audio in waveplayerswavePlayers.a.loadAudio(data.audio_a);wavePlayers.b.loadAudio(data.audio_b);// Show playersloadingContainer.style.display = 'none';playersContainer.style.display = 'flex';// Setup automatic sequential playbackwavePlayers.a.wavesurfer.once('ready', function() {wavePlayers.a.play();// When audio A ends, play audio BwavePlayers.a.wavesurfer.once('finish', function() {// Wait a short moment before playing BsetTimeout(() => {wavePlayers.b.play();// When audio B ends, enable votingwavePlayers.b.wavesurfer.once('finish', function() {bothSamplesPlayed = true;voteButtons.forEach(btn => {4 unmodified lines});});// Fetch cached sentences again to update the listfetchCachedSentences();}).catch(error => {1 unmodified lineopenToast(error.message, "error");console.error('Error:', error);});}function handleVote(model) {// Disable both vote buttonsvoteButtons.forEach(btn => {btn.disabled = true;if (btn.dataset.model === model) {1 unmodified line}});// Send vote to serverfetch('/api/tts/vote', {method: 'POST',headers: {13 unmodified linesreturn response.json();}).then(data => {// Hide loadersvoteButtons.forEach(btn => {btn.querySelector('.vote-loader').style.display = 'none';// Highlight the selected buttonif (btn.dataset.model === model) {btn.classList.add('selected');}});// Store model names from vote responseif (data.chosen_model && data.chosen_model.name) {modelNames.a = data.names.a;modelNames.b = data.names.b;}// Now display model names after votingmodelNameDisplays[0].textContent = modelNames.a ? `(${modelNames.a})` : '';modelNameDisplays[1].textContent = modelNames.b ? `(${modelNames.b})` : '';// Show vote resultschosenModelNameElement.textContent = data.chosen_model.name;rejectedModelNameElement.textContent = data.rejected_model.name;voteResultsContainer.style.display = 'block';// Show next round buttonnextRoundContainer.style.display = 'block';// Show success toastopenToast("Vote recorded successfully!", "success");}).catch(error => {// Re-enable vote buttonsvoteButtons.forEach(btn => {btn.disabled = false;btn.querySelector('.vote-loader').style.display = 'none';5 unmodified lines}function resetToInitialState() {// Hide players, results, and next round buttonplayersContainer.style.display = 'none';voteResultsContainer.style.display = 'none';nextRoundContainer.style.display = 'none';// Reset vote buttonsvoteButtons.forEach(btn => {btn.disabled = true;btn.classList.remove('selected');btn.querySelector('.vote-loader').style.display = 'none';});// Clear model name displaysmodelNameDisplays.forEach(display => {display.textContent = '';});// Reset model namesmodelNames = { a: '', b: '' };// Clear text inputtextInput.value = '';// Stop any playing audio and destroy wavesurfersfor (const model in wavePlayers) {if (wavePlayers[model]) {wavePlayers[model].stop();}}// Reset sessioncurrentSessionId = null;// Reset the flag for both samples playedbothSamplesPlayed = false;}function handleRandom() {let selectedText = '';if (cachedSentences && cachedSentences.length > 0) {// Select a random text from the cacheselectedText = 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 loadconsole.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;}6 unmodified linesopenToast("Please listen to both audio samples before voting", "info");}// Add submit event listener to formsynthForm.addEventListener('submit', handleSynthesize);// Add click event listeners to vote buttonsvoteButtons.forEach(btn => {btn.addEventListener('click', function() {if (bothSamplesPlayed) {5 unmodified lines});});// Add keyboard shortcut listenersdocument.addEventListener('keydown', function(e) {// Check if TTS tab is activeconst ttsTab = document.getElementById('tts-tab');if (!ttsTab.classList.contains('active')) return;// Only process keyboard shortcuts if text input is not focusedif (document.activeElement === textInput) {return;}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') {if (nextRoundContainer.style.display === 'block') {if (!e.ctrlKey && !e.metaKey) {e.preventDefault();}resetToInitialState();}} else if (e.key.toLowerCase() === 'r') {// Only trigger random if not trying to reload (Ctrl+R or Cmd+R)if (!e.ctrlKey && !e.metaKey) {e.preventDefault();handleRandom();}} else if (e.key === ' ') {// Space to play/pause current audioif (playersContainer.style.display !== 'none') {e.preventDefault();// If A is playing, toggle A, else if B is playing, toggle B, else play Aif (wavePlayers.a.isPlaying) {wavePlayers.a.togglePlayPause();} else if (wavePlayers.b.isPlaying) {wavePlayers.b.togglePlayPause();} else {wavePlayers.a.play();}}}});// Add event listener for random buttonrandomBtn.addEventListener('click', handleRandom);// Add event listener for next round buttonnextRoundBtn.addEventListener('click', resetToInitialState);// Fetch cached sentences when the DOM is readyfetchCachedSentences();});</script><script>document.addEventListener('DOMContentLoaded', function() {// Variables for podcast UIconst podcastContainer = document.querySelector('.podcast-container');const podcastLinesContainer = document.querySelector('.podcast-lines');const addLineBtn = document.querySelector('.add-line-btn');9 unmodified linesconst 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;95 unmodified linesaddPodcastLine(2);}// Add a new podcast linefunction addPodcastLine(speakerNum = null) {const lineCount = podcastLinesContainer.querySelectorAll('.podcast-line').length;// If speaker number isn't specified, alternate between 1 and 2if (speakerNum === null) {speakerNum = (lineCount % 2) + 1;}15 unmodified linespodcastLinesContainer.appendChild(lineElement);// Add event listener to remove buttonconst removeBtn = lineElement.querySelector('.remove-line-btn');removeBtn.addEventListener('click', function() {// Don't allow removing if there are only 2 linesif (podcastLinesContainer.querySelectorAll('.podcast-line').length > 2) {lineElement.remove();} else {1 unmodified line}});// Add event listener for keyboard navigation in the input fieldconst inputField = lineElement.querySelector('.line-input');inputField.addEventListener('keydown', function(e) {// Alt+Enter or Ctrl+Enter to add new lineif (e.key === 'Enter' && (e.altKey || e.ctrlKey)) {e.preventDefault();addPodcastLine();// Focus the new line's input fieldsetTimeout(() => {const inputs = podcastLinesContainer.querySelectorAll('.line-input');inputs[inputs.length - 1].focus();4 unmodified linesreturn lineElement;}// Load a random scriptfunction loadRandomScript() {// Clear existing linespodcastLinesContainer.innerHTML = '';// Select a random scriptconst randomScript = randomScripts[Math.floor(Math.random() * randomScripts.length)];// Add each line from the scriptrandomScript.forEach(line => {const lineElement = addPodcastLine(line.speaker);lineElement.querySelector('.line-input').value = line.text;});}// Generate podcast (mock functionality)function generatePodcast() {// Get all linesconst lines = [];podcastLinesContainer.querySelectorAll('.podcast-line').forEach(line => {const speaker_id = line.querySelector('.speaker-label').textContent.includes('1') ? 0 : 1;4 unmodified lines}});// Validate that we have at least 2 lines with contentif (lines.length < 2) {openToast("Please enter at least 2 lines of dialog", "warning");return;}// Reset vote buttons and hide resultspodcastVoteButtons.forEach(btn => {btn.disabled = true;btn.classList.remove('selected');btn.querySelector('.vote-loader').style.display = 'none';});// Clear model name displaysconst modelNameDisplays = podcastPlayerContainer.querySelectorAll('.model-name-display');modelNameDisplays.forEach(display => {display.textContent = '';2 unmodified linespodcastVoteResults.style.display = 'none';podcastNextRoundContainer.style.display = 'none';// Reset the flag for both samples playedbothPodcastSamplesPlayed = false;// Show loading animationpodcastLoadingContainer.style.display = 'flex';podcastPlayerContainer.style.display = 'none';// Call API to generate podcastfetch('/api/conversational/generate', {method: 'POST',headers: {12 unmodified lines.then(data => {currentPodcastSessionId = data.session_id;// Hide loadingpodcastLoadingContainer.style.display = 'none';// Show playerpodcastPlayerContainer.style.display = 'block';// Initialize WavePlayers if not already doneif (!podcastWavePlayers.a) {podcastWavePlayers.a = new WavePlayer(podcastWavePlayerA, {// Add mobile-friendly options but hide native controlsbackend: 'MediaElement',mediaControls: false // Hide native audio controls});podcastWavePlayers.b = new WavePlayer(podcastWavePlayerB, {// Add mobile-friendly options but hide native controlsbackend: 'MediaElement',mediaControls: false // Hide native audio controls});// Load audio in waveplayerspodcastWavePlayers.a.loadAudio(data.audio_a);podcastWavePlayers.b.loadAudio(data.audio_b);// Force hide loading indicators after 5 seconds as a fallbacksetTimeout(() => {if (podcastWavePlayers.a && podcastWavePlayers.a.hideLoading) {podcastWavePlayers.a.hideLoading();4 unmodified linesconsole.log('Forced hiding of podcast loading indicators (safety timeout - existing players)');}, 5000);} else {// Reset and reload for existing playerstry {podcastWavePlayers.a.wavesurfer.empty();podcastWavePlayers.b.wavesurfer.empty();// Make sure loading indicators are resetpodcastWavePlayers.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 fallbacksetTimeout(() => {if (podcastWavePlayers.a && podcastWavePlayers.a.hideLoading) {podcastWavePlayers.a.hideLoading();6 unmodified lines} catch (err) {console.error('Error resetting podcast waveplayers:', err);// Recreate the players if there was an errorpodcastWavePlayers.a = new WavePlayer(podcastWavePlayerA, {backend: 'MediaElement',mediaControls: false6 unmodified linespodcastWavePlayers.a.loadAudio(data.audio_a);podcastWavePlayers.b.loadAudio(data.audio_b);// Force hide loading indicators after 5 seconds as a fallbacksetTimeout(() => {if (podcastWavePlayers.a && podcastWavePlayers.a.hideLoading) {podcastWavePlayers.a.hideLoading();6 unmodified lines}}// Setup automatic sequential playbackpodcastWavePlayers.a.wavesurfer.once('ready', function() {podcastWavePlayers.a.play();// When audio A ends, play audio BpodcastWavePlayers.a.wavesurfer.once('finish', function() {// Wait a short moment before playing BsetTimeout(() => {podcastWavePlayers.b.play();// When audio B ends, enable votingpodcastWavePlayers.b.wavesurfer.once('finish', function() {bothPodcastSamplesPlayed = true;podcastVoteButtons.forEach(btn => {9 unmodified linesopenToast(error.message, "error");console.error('Error:', error);});}// Handle vote for a podcast modelfunction handlePodcastVote(model) {// Disable both vote buttonspodcastVoteButtons.forEach(btn => {btn.disabled = true;if (btn.dataset.model === model) {1 unmodified line}});// Send vote to serverfetch('/api/conversational/vote', {method: 'POST',headers: {13 unmodified linesreturn response.json();}).then(data => {// Hide loaderspodcastVoteButtons.forEach(btn => {btn.querySelector('.vote-loader').style.display = 'none';// Highlight the selected buttonif (btn.dataset.model === model) {btn.classList.add('selected');}});// Store model names from vote responsepodcastModelNames.a = data.names.a;podcastModelNames.b = data.names.b;// Show model names after votingconst 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 resultschosenModelNameElement.textContent = data.chosen_model.name;rejectedModelNameElement.textContent = data.rejected_model.name;podcastVoteResults.style.display = 'block';// Show next round buttonpodcastNextRoundContainer.style.display = 'block';// Show success toastopenToast("Vote recorded successfully!", "success");}).catch(error => {// Re-enable vote buttonspodcastVoteButtons.forEach(btn => {btn.disabled = false;btn.querySelector('.vote-loader').style.display = 'none';4 unmodified lines});}// Reset podcast UI to initial statefunction resetPodcastState() {// Hide players, results, and next round buttonpodcastPlayerContainer.style.display = 'none';podcastVoteResults.style.display = 'none';podcastNextRoundContainer.style.display = 'none';// Reset vote buttonspodcastVoteButtons.forEach(btn => {btn.disabled = true;btn.classList.remove('selected');btn.querySelector('.vote-loader').style.display = 'none';});// Clear model name displaysconst modelNameDisplays = podcastPlayerContainer.querySelectorAll('.model-name-display');modelNameDisplays.forEach(display => {display.textContent = '';});// Stop any playing audioif (podcastWavePlayers.a) podcastWavePlayers.a.stop();if (podcastWavePlayers.b) podcastWavePlayers.b.stop();// Reset sessioncurrentPodcastSessionId = null;// Reset the flag for both samples playedbothPodcastSamplesPlayed = false;}// Add keyboard shortcut listeners for podcast votingdocument.addEventListener('keydown', function(e) {// Check if we're in the podcast tab and it's activeconst podcastTab = document.getElementById('conversational-tab');if (!podcastTab.classList.contains('active')) return;// Only process if input fields are not focusedif (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 audioif (podcastPlayerContainer.style.display !== 'none') {e.preventDefault();// If A is playing, toggle A, else if B is playing, toggle B, else play Aif (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 listenersaddLineBtn.addEventListener('click', function() {addPodcastLine();});6 unmodified linesgeneratePodcast();});// Add event listeners to vote buttonspodcastVoteButtons.forEach(btn => {btn.addEventListener('click', function() {if (bothPodcastSamplesPlayed) {5 unmodified lines});});// Add event listener for next round buttonpodcastNextRoundBtn.addEventListener('click', resetPodcastState);// Initialize with 2 empty linesinitializePodcastLines();});</script>
templates/arena.html+185-134