Adipta commited on
Commit
b8c0af1
1 Parent(s): 5267b93

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -0
app.py CHANGED
@@ -1,9 +1,27 @@
 
 
 
 
1
  import gradio as gr
2
 
3
  from google.cloud import speech
4
  from microphone import MicrophoneStream
5
  from utils import listen_print_loop
6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
 
8
  # Audio recording parameters
9
  RATE = 16000
 
1
+ import os
2
+ import json
3
+ import tempfile
4
+
5
  import gradio as gr
6
 
7
  from google.cloud import speech
8
  from microphone import MicrophoneStream
9
  from utils import listen_print_loop
10
 
11
+ # process of getting credentials
12
+ def get_credentials():
13
+ creds_json_str = os.getenv("GOOGLE")
14
+ if creds_json_str is None:
15
+ raise ValueError("GOOGLE_APPLICATION_CREDENTIALS_JSON not found in environment")
16
+
17
+ # create a temporary file
18
+ with tempfile.NamedTemporaryFile(mode="w+", delete=False, suffix=".json") as temp:
19
+ temp.write(creds_json_str) # write in json format
20
+ temp_filename = temp.name
21
+
22
+ return temp_filename
23
+
24
+ os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = get_credentials()
25
 
26
  # Audio recording parameters
27
  RATE = 16000