@@ -65,18 +65,12 @@ async def initiate_voice_session(
6565 rtc_token = str (uuid .uuid4 ())
6666 expires_at = now + TOKEN_EXPIRATION_SECONDS
6767 rtc_token_cache [rtc_token ] = {"user_id" : user_id , "expires_at" : expires_at }
68- logger .info (f"Generated RTC token { rtc_token } for user { user_id } , expires at { datetime .fromtimestamp (expires_at ).isoformat ()} " )
69-
68+ logger .info (f"Generated RTC token { rtc_token } for user { user_id } , expires at { datetime .fromtimestamp (expires_at ).isoformat ()} . Mode: { ENVIRONMENT } " )
69+
7070 if ENVIRONMENT in ["dev-local" , "selfhost" ]:
71- logger .info (f"Initiated voice session for user { user_id } in dev-local mode with token { rtc_token } " )
72- return {"rtc_token" : rtc_token , "ice_servers" : []} # No TURN server in dev-local mode
73-
71+ return {"rtc_token" : rtc_token , "ice_servers" : []}
7472 else :
75- logger .info (f"Initiated voice session for user { user_id } with token { rtc_token } using TURN server" )
76- # Get TURN credentials to send to the client
7773 ice_servers_config = await get_credentials ()
78-
79- logger .info (f"Initiated voice session for user { user_id } with token { rtc_token } " )
8074 return {"rtc_token" : rtc_token , "ice_servers" : ice_servers_config }
8175
8276
@@ -144,30 +138,10 @@ async def process_audio_chunk(self, audio: tuple[int, np.ndarray]):
144138 await self .send_message (json .dumps ({"type" : "status" , "message" : "transcribing" }))
145139 sample_rate , audio_array = audio
146140
147- # --- DEBUG: Save audio to file before STT ---
148- try :
149- debug_dir = "audio_debug_logs"
150- # Create the directory relative to the current file's location
151- server_root = os .path .abspath (os .path .join (os .path .dirname (__file__ ), '..' , '..' ))
152- full_debug_path = os .path .join (server_root , debug_dir )
153- os .makedirs (full_debug_path , exist_ok = True )
154- timestamp = datetime .now ().strftime ("%Y%m%d_%H%M%S_%f" )
155- filename = os .path .join (full_debug_path , f"stt_input_{ timestamp } .wav" )
156-
157- with wave .open (filename , 'wb' ) as wf :
158- wf .setnchannels (1 ) # Mono
159- wf .setsampwidth (audio_array .dtype .itemsize ) # Should be 2 for int16
160- wf .setframerate (sample_rate )
161- wf .writeframes (audio_array .tobytes ())
162- logger .info (f"[Handler:{ self .handler_id } ] DEBUG: Saved pre-STT audio to { filename } " )
163- except Exception as e :
164- logger .error (f"[Handler:{ self .handler_id } ] DEBUG: Failed to save debug audio: { e } " )
165- # --- END DEBUG ---
166-
167141 if audio_array .dtype != np .int16 :
168142 audio_array = (audio_array * 32767 ).astype (np .int16 )
169143
170- logger .debug (f"[Handler:{ self .handler_id } ] Transcribing audio for user { user_id } ..." )
144+ logger .info (f"[Handler:{ self .handler_id } ] Transcribing audio for user { user_id } ..." )
171145 transcription , detected_language = await stt_model_instance .transcribe (audio_array .tobytes (), sample_rate = sample_rate )
172146
173147 if not transcription or not transcription .strip ():
@@ -180,7 +154,6 @@ async def process_audio_chunk(self, audio: tuple[int, np.ndarray]):
180154
181155 async def send_status_update (status_update : Dict [str , Any ]):
182156 """Sends a status update message to the client."""
183- logger .info (f"[Handler:{ self .handler_id } ] Sending status update to client: { status_update } " )
184157 await self .send_message (json .dumps (status_update ))
185158
186159 # 2. Process command, which may return a background task for Stage 2
@@ -227,13 +200,9 @@ async def send_status_update(status_update: Dict[str, Any]):
227200 sentences = [s .strip () for s in sentences if s .strip ()]
228201 for i , sentence in enumerate (sentences ):
229202 if not sentence : continue
230- logger .info (f"[Handler:{ self .handler_id } ] Generating TTS for sentence { i + 1 } /{ len (sentences )} : '{ sentence } '" )
231203 audio_stream = tts_model_instance .stream_tts (sentence , language = detected_language )
232- chunk_count = 0
233204 async for audio_chunk in audio_stream :
234205 yield self ._format_audio_chunk (audio_chunk )
235- chunk_count += 1
236- logger .info (f"[Handler:{ self .handler_id } ] Streamed { chunk_count } TTS chunks for sentence." )
237206 except Exception as e :
238207 logger .error (f"[Handler:{ self .handler_id } ] Error in voice_chat for user { user_id } : { e } " , exc_info = True )
239208 await self .send_message (json .dumps ({"type" : "error" , "message" : str (e )}))
0 commit comments