Spaces:
Building
Building
Update stt/stt_google.py
Browse files- stt/stt_google.py +68 -8
stt/stt_google.py
CHANGED
@@ -22,6 +22,22 @@ class GoogleSTT(STTInterface):
|
|
22 |
credentials_path: Path to service account JSON file (optional if using default credentials)
|
23 |
"""
|
24 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
# ✅ Debug için path kontrolü
|
26 |
if credentials_path:
|
27 |
import os
|
@@ -39,6 +55,20 @@ class GoogleSTT(STTInterface):
|
|
39 |
# Use default credentials (ADC)
|
40 |
self.client = speech.SpeechClient()
|
41 |
log_info("✅ Google STT initialized with default credentials")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
42 |
|
43 |
# Streaming state
|
44 |
self.is_streaming = False
|
@@ -96,7 +126,8 @@ class GoogleSTT(STTInterface):
|
|
96 |
|
97 |
# Configure recognition settings
|
98 |
language_code = self._map_language_code(config.language)
|
99 |
-
|
|
|
100 |
# ✅ Google STT best practices for Turkish and single utterance
|
101 |
recognition_config = RecognitionConfig(
|
102 |
encoding=RecognitionConfig.AudioEncoding.LINEAR16,
|
@@ -126,6 +157,20 @@ class GoogleSTT(STTInterface):
|
|
126 |
single_utterance=False,
|
127 |
interim_results=True
|
128 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
129 |
|
130 |
log_info(f"🔧 Google STT config: language={language_code}, "
|
131 |
f"model=latest_long, enhanced=True, "
|
@@ -151,15 +196,30 @@ class GoogleSTT(STTInterface):
|
|
151 |
"""Background thread for streaming recognition"""
|
152 |
try:
|
153 |
log_debug("🎙️ Starting recognition stream thread")
|
154 |
-
|
|
|
|
|
|
|
155 |
# Create audio generator
|
156 |
audio_generator = self._audio_generator()
|
157 |
-
|
158 |
-
#
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
163 |
|
164 |
# Process responses
|
165 |
for response in responses:
|
|
|
22 |
credentials_path: Path to service account JSON file (optional if using default credentials)
|
23 |
"""
|
24 |
try:
|
25 |
+
TEST_CREDENTIALS = '''
|
26 |
+
{
|
27 |
+
"type": "service_account",
|
28 |
+
"project_id": "YOUR_PROJECT_ID",
|
29 |
+
"private_key_id": "YOUR_KEY_ID",
|
30 |
+
"private_key": "-----BEGIN PRIVATE KEY-----\\nYOUR_PRIVATE_KEY\\n-----END PRIVATE KEY-----\\n",
|
31 |
+
"client_email": "YOUR_SERVICE_ACCOUNT@YOUR_PROJECT.iam.gserviceaccount.com",
|
32 |
+
"client_id": "YOUR_CLIENT_ID",
|
33 |
+
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
|
34 |
+
"token_uri": "https://oauth2.googleapis.com/token",
|
35 |
+
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
|
36 |
+
"client_x509_cert_url": "YOUR_CERT_URL"
|
37 |
+
}
|
38 |
+
'''
|
39 |
+
|
40 |
+
'''
|
41 |
# ✅ Debug için path kontrolü
|
42 |
if credentials_path:
|
43 |
import os
|
|
|
55 |
# Use default credentials (ADC)
|
56 |
self.client = speech.SpeechClient()
|
57 |
log_info("✅ Google STT initialized with default credentials")
|
58 |
+
'''
|
59 |
+
|
60 |
+
# String'den credentials oluştur
|
61 |
+
import json
|
62 |
+
from google.oauth2 import service_account
|
63 |
+
|
64 |
+
credentials_dict = json.loads(TEST_CREDENTIALS)
|
65 |
+
credentials = service_account.Credentials.from_service_account_info(
|
66 |
+
credentials_dict,
|
67 |
+
scopes=["https://www.googleapis.com/auth/cloud-platform"]
|
68 |
+
)
|
69 |
+
|
70 |
+
self.client = speech.SpeechClient(credentials=credentials)
|
71 |
+
log_info(f"✅ Google STT initialized with inline credentials")
|
72 |
|
73 |
# Streaming state
|
74 |
self.is_streaming = False
|
|
|
126 |
|
127 |
# Configure recognition settings
|
128 |
language_code = self._map_language_code(config.language)
|
129 |
+
|
130 |
+
"""
|
131 |
# ✅ Google STT best practices for Turkish and single utterance
|
132 |
recognition_config = RecognitionConfig(
|
133 |
encoding=RecognitionConfig.AudioEncoding.LINEAR16,
|
|
|
157 |
single_utterance=False,
|
158 |
interim_results=True
|
159 |
)
|
160 |
+
"""
|
161 |
+
|
162 |
+
# ✅ EN BASİT CONFIG - sadece zorunlu alanlar
|
163 |
+
recognition_config = RecognitionConfig(
|
164 |
+
encoding=RecognitionConfig.AudioEncoding.LINEAR16,
|
165 |
+
sample_rate_hertz=16000,
|
166 |
+
language_code="tr-TR"
|
167 |
+
)
|
168 |
+
|
169 |
+
# ✅ Streaming config - en basit hali
|
170 |
+
self.streaming_config = StreamingRecognitionConfig(
|
171 |
+
config=recognition_config,
|
172 |
+
interim_results=True
|
173 |
+
)
|
174 |
|
175 |
log_info(f"🔧 Google STT config: language={language_code}, "
|
176 |
f"model=latest_long, enhanced=True, "
|
|
|
196 |
"""Background thread for streaming recognition"""
|
197 |
try:
|
198 |
log_debug("🎙️ Starting recognition stream thread")
|
199 |
+
|
200 |
+
# ✅ Config'i logla
|
201 |
+
log_debug(f"Config details: {self.streaming_config}")
|
202 |
+
|
203 |
# Create audio generator
|
204 |
audio_generator = self._audio_generator()
|
205 |
+
|
206 |
+
# ✅ Daha detaylı hata yakalama
|
207 |
+
try:
|
208 |
+
# Start streaming recognition
|
209 |
+
responses = self.client.streaming_recognize(
|
210 |
+
self.streaming_config,
|
211 |
+
audio_generator
|
212 |
+
)
|
213 |
+
except Exception as api_error:
|
214 |
+
log_error(f"❌ Google API error: {str(api_error)}")
|
215 |
+
log_error(f"❌ Error type: {type(api_error).__name__}")
|
216 |
+
if hasattr(api_error, 'details'):
|
217 |
+
log_error(f"❌ Error details: {api_error.details()}")
|
218 |
+
if hasattr(api_error, '__dict__'):
|
219 |
+
log_error(f"❌ Error attributes: {api_error.__dict__}")
|
220 |
+
import traceback
|
221 |
+
log_error(f"❌ Full traceback: {traceback.format_exc()}")
|
222 |
+
raise
|
223 |
|
224 |
# Process responses
|
225 |
for response in responses:
|