Oviya commited on
Commit
38efa1b
·
1 Parent(s): 12a78dd

add listen

Browse files
Files changed (1) hide show
  1. listen.py +15 -2
listen.py CHANGED
@@ -11,6 +11,7 @@ from pydub import AudioSegment
11
  import ffmpeg
12
  import re
13
  import io # for streaming S3 bytes in HF/AWS mode
 
14
 
15
  # Optional (only used in AWS mode)
16
  try:
@@ -86,8 +87,20 @@ COHERE_API_KEY = os.getenv("COHERE_API_KEY", "")
86
  COHERE_API_URL = 'https://api.cohere.com/v2/chat'
87
  # ---------------------------------------------------------------------------
88
 
89
- # Google Cloud Speech-to-Text Configuration
90
- speech_client = speech.SpeechClient()
 
 
 
 
 
 
 
 
 
 
 
 
91
 
92
  # ------------- Cohere v2 helper (extract text from chat response) -------------
93
  def _extract_text_v2(resp_json: dict) -> str:
 
11
  import ffmpeg
12
  import re
13
  import io # for streaming S3 bytes in HF/AWS mode
14
+ import json # <-- added for JSON creds parsing
15
 
16
  # Optional (only used in AWS mode)
17
  try:
 
87
  COHERE_API_URL = 'https://api.cohere.com/v2/chat'
88
  # ---------------------------------------------------------------------------
89
 
90
+ # --- Google Cloud Speech-to-Text client init (prefers HF secret JSON) ---
91
+ def _make_speech_client():
92
+ sa_json = os.getenv("GOOGLE_APPLICATION_CREDENTIALS_JSON")
93
+ if sa_json:
94
+ try:
95
+ info = json.loads(sa_json)
96
+ return speech.SpeechClient.from_service_account_info(info)
97
+ except Exception as e:
98
+ print(f"Failed to parse GOOGLE_APPLICATION_CREDENTIALS_JSON: {e}")
99
+ # fall through to default ADC
100
+ return speech.SpeechClient()
101
+
102
+ speech_client = _make_speech_client()
103
+ # -------------------------------------------------------------------------
104
 
105
  # ------------- Cohere v2 helper (extract text from chat response) -------------
106
  def _extract_text_v2(resp_json: dict) -> str: