1- // chat-part2.js
2-
31document . addEventListener ( "DOMContentLoaded" , ( ) => {
42 const {
53 recognition,
@@ -11,7 +9,6 @@ document.addEventListener("DOMContentLoaded", () => {
119 let isRecording = false ;
1210 let slideshowInterval = null ;
1311
14- // ========== VOICE CHAT MODAL SETUP ==========
1512 function createVoiceChatModal ( ) {
1613 const modalHTML = `
1714 <div id="voice-chat-modal" class="modal-backdrop hidden">
@@ -42,12 +39,10 @@ document.addEventListener("DOMContentLoaded", () => {
4239 modalContainer . innerHTML = modalHTML ;
4340 document . body . appendChild ( modalContainer . firstElementChild ) ;
4441
45- // Modal close button
4642 document . getElementById ( "voice-chat-close" ) . addEventListener ( "click" , ( ) => {
4743 closeVoiceChatModal ( ) ;
4844 } ) ;
4945
50- // Start & Stop listening buttons
5146 document . getElementById ( "start-voice-chat" ) . addEventListener ( "click" , ( ) => {
5247 startVoiceChat ( ) ;
5348 startSlideshow ( ) ;
@@ -59,7 +54,6 @@ document.addEventListener("DOMContentLoaded", () => {
5954 }
6055
6156 function openVoiceChatModal ( ) {
62- // If the modal doesn't exist in the DOM yet, create it
6357 if ( ! document . getElementById ( "voice-chat-modal" ) ) {
6458 createVoiceChatModal ( ) ;
6559 }
@@ -75,22 +69,18 @@ document.addEventListener("DOMContentLoaded", () => {
7569 }
7670 }
7771
78- // ========== HOOK UP THE NEW BUTTON IN INDEX.HTML ==========
7972 const openVoiceChatModalBtn = document . getElementById ( "open-voice-chat-modal" ) ;
8073 if ( openVoiceChatModalBtn ) {
8174 openVoiceChatModalBtn . addEventListener ( "click" , ( ) => {
8275 openVoiceChatModal ( ) ;
8376 } ) ;
8477 }
8578
86- // ========== START / STOP VOICE CHAT ==========
8779 function startVoiceChat ( ) {
8880 const { synth, selectedVoice } = window . _chatInternals ;
89- // Force auto-speak ON during voice chat
9081 window . _chatInternals . autoSpeakEnabled = true ;
9182 localStorage . setItem ( "autoSpeakEnabled" , "true" ) ;
9283
93- // If we never inited recognition, do it now
9484 if ( ! recognition ) {
9585 window . _chatInternals . recognition = new ( window . SpeechRecognition || window . webkitSpeechRecognition ) ( ) ;
9686 window . _chatInternals . recognition . continuous = true ;
@@ -114,7 +104,6 @@ document.addEventListener("DOMContentLoaded", () => {
114104 }
115105 }
116106 if ( finalTranscript . trim ( ) ) {
117- // Show the transcript
118107 document . getElementById ( "voice-transcript" ) . textContent = finalTranscript ;
119108 sendVoiceMessage ( finalTranscript ) ;
120109 }
@@ -161,10 +150,7 @@ document.addEventListener("DOMContentLoaded", () => {
161150 if ( voiceStatus ) voiceStatus . textContent = "Voice chat stopped" ;
162151 }
163152
164- // ========== SENDING VOICE MESSAGE ==========
165153 function sendVoiceMessage ( text ) {
166- // We'll rely on chat-part3's window.addNewMessage() and sendToPollinations()
167- // to handle user -> AI flow
168154 window . addNewMessage ( { role : "user" , content : text } ) ;
169155 window . sendToPollinations ( ( ) => {
170156 const { currentSession, autoSpeakEnabled } = window . _chatInternals ;
@@ -176,13 +162,7 @@ document.addEventListener("DOMContentLoaded", () => {
176162 } ) ;
177163 }
178164
179- // ========== SLIDESHOW: REFRESH IMAGES EVERY 30s ==========
180- /**
181- * Build and set the correct Pollinations image URL based on the AI's response.
182- */
183165 function updateSlideshow ( aiResponse ) {
184- // example approach: "Generate an image: {aiResponse}"
185- // then set width/height/seed so the URL is correct.
186166 const baseUrl = "https://image.pollinations.ai/prompt/" ;
187167 const prompt = `Generate an image based on this conversation: ${ aiResponse } ` ;
188168 const width = 512 ;
@@ -214,7 +194,7 @@ document.addEventListener("DOMContentLoaded", () => {
214194 }
215195
216196 function startSlideshow ( ) {
217- stopSlideshow ( ) ; // Clear existing
197+ stopSlideshow ( ) ;
218198 slideshowInterval = setInterval ( ( ) => {
219199 const { currentSession } = window . _chatInternals ;
220200 const lastMsg = currentSession . messages [ currentSession . messages . length - 1 ] ;
@@ -228,7 +208,6 @@ document.addEventListener("DOMContentLoaded", () => {
228208 clearInterval ( slideshowInterval ) ;
229209 }
230210
231- // Expose the methods globally (for convenience)
232211 window . openVoiceChatModal = openVoiceChatModal ;
233212 window . closeVoiceChatModal = closeVoiceChatModal ;
234213 window . startVoiceChat = startVoiceChat ;
0 commit comments