ciyidogan commited on
Commit
24a34cf
Β·
verified Β·
1 Parent(s): b0a5e07

Delete realtime_session_manager.py

Browse files
Files changed (1) hide show
  1. realtime_session_manager.py +0 -66
realtime_session_manager.py DELETED
@@ -1,66 +0,0 @@
1
- """
2
- Helper functions for realtime session management
3
- """
4
- import base64
5
- from typing import Optional
6
- from datetime import datetime
7
- import sys
8
- import traceback
9
-
10
- from logger import log_info, log_error, log_debug, log_warning
11
-
12
- def log(message: str):
13
- """Log helper with timestamp"""
14
- timestamp = datetime.now().strftime("%H:%M:%S.%f")[:-3]
15
- print(f"[{timestamp}] {message}")
16
- sys.stdout.flush()
17
-
18
- async def send_tts_welcome_message(websocket, session_id: str, tts_provider, text: str):
19
- """Send welcome message TTS audio"""
20
- try:
21
- log_info(f"πŸŽ™οΈ Generating welcome TTS for: '{text[:50]}...'", session_id=session_id)
22
-
23
- # Generate TTS
24
- audio_data = await tts_provider.synthesize(text)
25
- log_info(f"βœ… Welcome TTS generated: {len(audio_data)} bytes", session_id=session_id)
26
-
27
- # Convert to base64
28
- log_debug(f"πŸ“¦ Converting welcome audio to base64...")
29
- audio_base64 = base64.b64encode(audio_data).decode('utf-8')
30
- log_info(f"πŸ“Š Welcome base64 ready: {len(audio_base64)} chars", session_id=session_id)
31
-
32
- # Log preview
33
- log_debug(f"πŸ” Welcome base64 preview: {audio_base64[:100]}...")
34
-
35
- # Send in chunks
36
- chunk_size = 16384
37
- total_length = len(audio_base64)
38
- total_chunks = (total_length + chunk_size - 1) // chunk_size
39
-
40
- log_info(f"πŸ“€ Sending welcome TTS in {total_chunks} chunks", session_id=session_id)
41
-
42
- for i in range(0, total_length, chunk_size):
43
- chunk = audio_base64[i:i + chunk_size]
44
- chunk_index = i // chunk_size
45
- is_last = chunk_index == total_chunks - 1
46
-
47
- log_debug(f"πŸ“¨ Welcome chunk {chunk_index}/{total_chunks}, size: {len(chunk)}")
48
-
49
- await websocket.send_json({
50
- "type": "tts_audio",
51
- "data": chunk,
52
- "chunk_index": chunk_index,
53
- "total_chunks": total_chunks,
54
- "is_last": is_last,
55
- "mime_type": "audio/mpeg"
56
- })
57
-
58
- log_info(f"βœ… Welcome message TTS sent successfully", session_id=session_id, chunks=total_chunks)
59
-
60
- except Exception as e:
61
- log_error(
62
- f"❌ Failed to send welcome TTS",
63
- error=str(e),
64
- traceback=traceback.format_exc(),
65
- session_id=session_id
66
- )