Spaces:
Building
Building
Update stt_google.py
Browse files- stt_google.py +9 -13
stt_google.py
CHANGED
@@ -6,11 +6,7 @@ import asyncio
|
|
6 |
from typing import AsyncIterator, Optional, List
|
7 |
from datetime import datetime
|
8 |
import sys
|
9 |
-
|
10 |
-
def log(message: str):
|
11 |
-
timestamp = datetime.now().strftime("%H:%M:%S.%f")[:-3]
|
12 |
-
print(f"[{timestamp}] {message}")
|
13 |
-
sys.stdout.flush()
|
14 |
|
15 |
# Import Google Cloud Speech only if available
|
16 |
try:
|
@@ -19,7 +15,7 @@ try:
|
|
19 |
GOOGLE_SPEECH_AVAILABLE = True
|
20 |
except ImportError:
|
21 |
GOOGLE_SPEECH_AVAILABLE = False
|
22 |
-
|
23 |
|
24 |
from stt_interface import STTInterface, STTConfig, TranscriptionResult
|
25 |
|
@@ -32,9 +28,9 @@ class GoogleCloudSTT(STTInterface):
|
|
32 |
|
33 |
if credentials_path and os.path.exists(credentials_path):
|
34 |
os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = credentials_path
|
35 |
-
|
36 |
else:
|
37 |
-
|
38 |
|
39 |
self.client = speech.SpeechAsyncClient()
|
40 |
self.streaming_config = None
|
@@ -61,10 +57,10 @@ class GoogleCloudSTT(STTInterface):
|
|
61 |
)
|
62 |
|
63 |
self.is_streaming = True
|
64 |
-
|
65 |
|
66 |
except Exception as e:
|
67 |
-
|
68 |
raise
|
69 |
|
70 |
async def stream_audio(self, audio_chunk: bytes) -> AsyncIterator[TranscriptionResult]:
|
@@ -86,7 +82,7 @@ class GoogleCloudSTT(STTInterface):
|
|
86 |
yield # Make it a generator
|
87 |
|
88 |
except Exception as e:
|
89 |
-
|
90 |
raise
|
91 |
|
92 |
async def stop_streaming(self) -> Optional[TranscriptionResult]:
|
@@ -96,13 +92,13 @@ class GoogleCloudSTT(STTInterface):
|
|
96 |
|
97 |
try:
|
98 |
self.is_streaming = False
|
99 |
-
|
100 |
|
101 |
# Return final result if any
|
102 |
return None
|
103 |
|
104 |
except Exception as e:
|
105 |
-
|
106 |
raise
|
107 |
|
108 |
def supports_realtime(self) -> bool:
|
|
|
6 |
from typing import AsyncIterator, Optional, List
|
7 |
from datetime import datetime
|
8 |
import sys
|
9 |
+
from logger import log_info, log_error, log_debug, log_warning
|
|
|
|
|
|
|
|
|
10 |
|
11 |
# Import Google Cloud Speech only if available
|
12 |
try:
|
|
|
15 |
GOOGLE_SPEECH_AVAILABLE = True
|
16 |
except ImportError:
|
17 |
GOOGLE_SPEECH_AVAILABLE = False
|
18 |
+
log_info("β οΈ Google Cloud Speech library not installed")
|
19 |
|
20 |
from stt_interface import STTInterface, STTConfig, TranscriptionResult
|
21 |
|
|
|
28 |
|
29 |
if credentials_path and os.path.exists(credentials_path):
|
30 |
os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = credentials_path
|
31 |
+
log_info(f"β
Google credentials set from: {credentials_path}")
|
32 |
else:
|
33 |
+
log_info("β οΈ Google credentials path not found, using default credentials")
|
34 |
|
35 |
self.client = speech.SpeechAsyncClient()
|
36 |
self.streaming_config = None
|
|
|
57 |
)
|
58 |
|
59 |
self.is_streaming = True
|
60 |
+
log_info("β
Google STT streaming started")
|
61 |
|
62 |
except Exception as e:
|
63 |
+
log_error("β Failed to start Google STT streaming", e)
|
64 |
raise
|
65 |
|
66 |
async def stream_audio(self, audio_chunk: bytes) -> AsyncIterator[TranscriptionResult]:
|
|
|
82 |
yield # Make it a generator
|
83 |
|
84 |
except Exception as e:
|
85 |
+
log_error("β Google STT streaming error", e)
|
86 |
raise
|
87 |
|
88 |
async def stop_streaming(self) -> Optional[TranscriptionResult]:
|
|
|
92 |
|
93 |
try:
|
94 |
self.is_streaming = False
|
95 |
+
log_info("β
Google STT streaming stopped")
|
96 |
|
97 |
# Return final result if any
|
98 |
return None
|
99 |
|
100 |
except Exception as e:
|
101 |
+
log_error("β Failed to stop Google STT streaming", e)
|
102 |
raise
|
103 |
|
104 |
def supports_realtime(self) -> bool:
|