Spaces:
Building
Building
Update stt_google.py
Browse files- stt_google.py +27 -3
stt_google.py
CHANGED
@@ -31,8 +31,20 @@ class GoogleCloudSTT(STTInterface):
|
|
31 |
if credentials_path and os.path.exists(credentials_path):
|
32 |
os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = credentials_path
|
33 |
log_info(f"✅ Google credentials set from: {credentials_path}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
34 |
else:
|
35 |
-
|
|
|
36 |
|
37 |
self.client = speech.SpeechClient()
|
38 |
self.streaming_config = None
|
@@ -100,22 +112,32 @@ class GoogleCloudSTT(STTInterface):
|
|
100 |
|
101 |
def request_generator():
|
102 |
"""Generate streaming requests"""
|
|
|
103 |
while not self.stop_event.is_set():
|
104 |
try:
|
105 |
# Get audio chunk with timeout
|
106 |
chunk = self.audio_queue.get(timeout=0.1)
|
107 |
if chunk is None: # Poison pill
|
108 |
break
|
|
|
|
|
109 |
yield speech.StreamingRecognizeRequest(audio_content=chunk)
|
110 |
except queue.Empty:
|
111 |
continue
|
112 |
|
113 |
# Create streaming client
|
114 |
requests = request_generator()
|
|
|
|
|
115 |
responses = self.client.streaming_recognize(self.streaming_config, requests)
|
|
|
116 |
|
117 |
# Process responses
|
|
|
118 |
for response in responses:
|
|
|
|
|
|
|
119 |
if self.stop_event.is_set():
|
120 |
break
|
121 |
|
@@ -136,14 +158,16 @@ class GoogleCloudSTT(STTInterface):
|
|
136 |
|
137 |
except Exception as e:
|
138 |
error_msg = str(e)
|
139 |
-
log_error(f"❌ Google STT stream error", error=error_msg)
|
140 |
|
141 |
# Send error to responses queue
|
142 |
if "Bad language code" in error_msg:
|
143 |
log_error(f"❌ Invalid language code in STT config. Check locale settings.")
|
144 |
elif "invalid_argument" in error_msg:
|
145 |
log_error(f"❌ Invalid STT configuration. Check encoding and sample rate.")
|
146 |
-
|
|
|
|
|
147 |
finally:
|
148 |
log_info("🎤 Google STT stream thread ended")
|
149 |
loop.close()
|
|
|
31 |
if credentials_path and os.path.exists(credentials_path):
|
32 |
os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = credentials_path
|
33 |
log_info(f"✅ Google credentials set from: {credentials_path}")
|
34 |
+
|
35 |
+
# Test credential'ları
|
36 |
+
try:
|
37 |
+
self.client = speech.SpeechClient()
|
38 |
+
# Basit bir test çağrısı
|
39 |
+
log_info("🔐 Testing Google credentials...")
|
40 |
+
# Bu sadece client'ın oluşturulabildiğini test eder
|
41 |
+
log_info("✅ Google credentials valid")
|
42 |
+
except Exception as e:
|
43 |
+
log_error(f"❌ Google credentials error", error=str(e))
|
44 |
+
raise
|
45 |
else:
|
46 |
+
log_error(f"❌ Google credentials path not found: {credentials_path}")
|
47 |
+
raise FileNotFoundError(f"Credentials file not found: {credentials_path}")
|
48 |
|
49 |
self.client = speech.SpeechClient()
|
50 |
self.streaming_config = None
|
|
|
112 |
|
113 |
def request_generator():
|
114 |
"""Generate streaming requests"""
|
115 |
+
chunk_count = 0
|
116 |
while not self.stop_event.is_set():
|
117 |
try:
|
118 |
# Get audio chunk with timeout
|
119 |
chunk = self.audio_queue.get(timeout=0.1)
|
120 |
if chunk is None: # Poison pill
|
121 |
break
|
122 |
+
chunk_count += 1
|
123 |
+
log_debug(f"📤 Sending chunk {chunk_count} to Google STT, size: {len(chunk)} bytes")
|
124 |
yield speech.StreamingRecognizeRequest(audio_content=chunk)
|
125 |
except queue.Empty:
|
126 |
continue
|
127 |
|
128 |
# Create streaming client
|
129 |
requests = request_generator()
|
130 |
+
|
131 |
+
log_info("🎤 Creating Google STT streaming client...")
|
132 |
responses = self.client.streaming_recognize(self.streaming_config, requests)
|
133 |
+
log_info("✅ Google STT streaming client created")
|
134 |
|
135 |
# Process responses
|
136 |
+
response_count = 0
|
137 |
for response in responses:
|
138 |
+
response_count += 1
|
139 |
+
log_debug(f"📥 Google STT response {response_count} received")
|
140 |
+
|
141 |
if self.stop_event.is_set():
|
142 |
break
|
143 |
|
|
|
158 |
|
159 |
except Exception as e:
|
160 |
error_msg = str(e)
|
161 |
+
log_error(f"❌ Google STT stream error", error=error_msg, traceback=traceback.format_exc())
|
162 |
|
163 |
# Send error to responses queue
|
164 |
if "Bad language code" in error_msg:
|
165 |
log_error(f"❌ Invalid language code in STT config. Check locale settings.")
|
166 |
elif "invalid_argument" in error_msg:
|
167 |
log_error(f"❌ Invalid STT configuration. Check encoding and sample rate.")
|
168 |
+
elif "Deadline Exceeded" in error_msg:
|
169 |
+
log_error(f"❌ Google STT timeout - possibly network issue or slow connection")
|
170 |
+
|
171 |
finally:
|
172 |
log_info("🎤 Google STT stream thread ended")
|
173 |
loop.close()
|