Spaces:
Building
Building
Update stt_google.py
Browse files- stt_google.py +33 -5
stt_google.py
CHANGED
@@ -62,7 +62,33 @@ class GoogleCloudSTT(STTInterface):
|
|
62 |
|
63 |
# Session tracking
|
64 |
self.session_id = 0
|
|
|
|
|
65 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
66 |
def _create_fresh_queues(self):
|
67 |
"""Create fresh queue instances"""
|
68 |
# Eski queue'ları temizle
|
@@ -88,23 +114,25 @@ class GoogleCloudSTT(STTInterface):
|
|
88 |
async def start_streaming(self, config: dict) -> None:
|
89 |
"""Initialize streaming session with clean state"""
|
90 |
try:
|
91 |
-
self.session_id += 1
|
92 |
-
log_info(f"🎤 Starting Google STT streaming session #{self.session_id} with config: {config}")
|
93 |
-
|
94 |
# Önce mevcut stream'i temizle
|
95 |
if self.is_streaming or self.stream_thread:
|
96 |
log_warning("⚠️ Previous stream still active, stopping it first")
|
97 |
await self.stop_streaming()
|
98 |
-
# Temizlik için
|
99 |
await asyncio.sleep(0.5)
|
100 |
|
|
|
|
|
|
|
|
|
|
|
101 |
# Fresh queue'lar oluştur
|
102 |
self._create_fresh_queues()
|
103 |
|
104 |
# Stop event'i temizle
|
105 |
self.stop_event.clear()
|
106 |
|
107 |
-
#
|
108 |
self.client = speech.SpeechClient()
|
109 |
log_info("✅ Created new Google Speech client")
|
110 |
|
|
|
62 |
|
63 |
# Session tracking
|
64 |
self.session_id = 0
|
65 |
+
self.total_audio_bytes = 0
|
66 |
+
self.total_chunks = 0
|
67 |
|
68 |
+
def _reset_session_data(self):
|
69 |
+
"""Reset all session-specific data"""
|
70 |
+
# Queue'ları temizle
|
71 |
+
while not self.audio_queue.empty():
|
72 |
+
try:
|
73 |
+
self.audio_queue.get_nowait()
|
74 |
+
except:
|
75 |
+
pass
|
76 |
+
|
77 |
+
while not self.responses_queue.empty():
|
78 |
+
try:
|
79 |
+
self.responses_queue.get_nowait()
|
80 |
+
except:
|
81 |
+
pass
|
82 |
+
|
83 |
+
# Counters'ı sıfırla
|
84 |
+
self.total_audio_bytes = 0
|
85 |
+
self.total_chunks = 0
|
86 |
+
|
87 |
+
# Yeni session ID
|
88 |
+
self.session_id += 1
|
89 |
+
|
90 |
+
log_info(f"🔄 Google STT session data reset. New session ID: {self.session_id}")
|
91 |
+
|
92 |
def _create_fresh_queues(self):
|
93 |
"""Create fresh queue instances"""
|
94 |
# Eski queue'ları temizle
|
|
|
114 |
async def start_streaming(self, config: dict) -> None:
|
115 |
"""Initialize streaming session with clean state"""
|
116 |
try:
|
|
|
|
|
|
|
117 |
# Önce mevcut stream'i temizle
|
118 |
if self.is_streaming or self.stream_thread:
|
119 |
log_warning("⚠️ Previous stream still active, stopping it first")
|
120 |
await self.stop_streaming()
|
121 |
+
# Temizlik için bekle
|
122 |
await asyncio.sleep(0.5)
|
123 |
|
124 |
+
# Session verilerini resetle ve ID'yi artır
|
125 |
+
self._reset_session_data()
|
126 |
+
|
127 |
+
log_info(f"🎤 Starting Google STT streaming session #{self.session_id} with config: {config}")
|
128 |
+
|
129 |
# Fresh queue'lar oluştur
|
130 |
self._create_fresh_queues()
|
131 |
|
132 |
# Stop event'i temizle
|
133 |
self.stop_event.clear()
|
134 |
|
135 |
+
# Yeni client oluştur (TEK SEFER)
|
136 |
self.client = speech.SpeechClient()
|
137 |
log_info("✅ Created new Google Speech client")
|
138 |
|