Spaces:
Running
Running
Update stt/stt_google.py
Browse files- stt/stt_google.py +14 -0
stt/stt_google.py
CHANGED
@@ -65,6 +65,20 @@ class GoogleCloudSTT(STTInterface):
|
|
65 |
self.total_audio_bytes = 0
|
66 |
self.total_chunks = 0
|
67 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
68 |
async def stream_audio(self, audio_chunk: bytes) -> AsyncIterator[TranscriptionResult]:
|
69 |
"""Stream audio chunk and get transcription results"""
|
70 |
if not self.is_streaming:
|
|
|
65 |
self.total_audio_bytes = 0
|
66 |
self.total_chunks = 0
|
67 |
|
68 |
+
def _get_encoding(self, encoding_str: str):
|
69 |
+
"""Convert encoding string to Google Speech enum"""
|
70 |
+
if not GOOGLE_SPEECH_AVAILABLE:
|
71 |
+
return None
|
72 |
+
|
73 |
+
encoding_map = {
|
74 |
+
"WEBM_OPUS": speech.RecognitionConfig.AudioEncoding.WEBM_OPUS,
|
75 |
+
"LINEAR16": speech.RecognitionConfig.AudioEncoding.LINEAR16,
|
76 |
+
"FLAC": speech.RecognitionConfig.AudioEncoding.FLAC,
|
77 |
+
"MP3": speech.RecognitionConfig.AudioEncoding.MP3,
|
78 |
+
"OGG_OPUS": speech.RecognitionConfig.AudioEncoding.OGG_OPUS,
|
79 |
+
}
|
80 |
+
return encoding_map.get(encoding_str, speech.RecognitionConfig.AudioEncoding.WEBM_OPUS)
|
81 |
+
|
82 |
async def stream_audio(self, audio_chunk: bytes) -> AsyncIterator[TranscriptionResult]:
|
83 |
"""Stream audio chunk and get transcription results"""
|
84 |
if not self.is_streaming:
|