Adipta commited on
Commit
c5c8c21
·
verified ·
1 Parent(s): b8c0af1

Update tts.py

Browse files
Files changed (1) hide show
  1. tts.py +18 -0
tts.py CHANGED
@@ -1,8 +1,26 @@
1
  import time
 
 
 
2
 
3
  import google.cloud.texttospeech as tts
4
  import simpleaudio as sa
5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
  class TextToSpeech:
7
  def __init__(self):
8
  self.voice_params = tts.VoiceSelectionParams(
 
1
  import time
2
+ import os
3
+ import json
4
+ import tempfile
5
 
6
  import google.cloud.texttospeech as tts
7
  import simpleaudio as sa
8
 
9
+ # process of getting credentials
10
+ def get_credentials():
11
+ creds_json_str = os.getenv("GOOGLE")
12
+ if creds_json_str is None:
13
+ raise ValueError("GOOGLE_APPLICATION_CREDENTIALS_JSON not found in environment")
14
+
15
+ # create a temporary file
16
+ with tempfile.NamedTemporaryFile(mode="w+", delete=False, suffix=".json") as temp:
17
+ temp.write(creds_json_str) # write in json format
18
+ temp_filename = temp.name
19
+
20
+ return temp_filename
21
+
22
+ os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = get_credentials()
23
+
24
  class TextToSpeech:
25
  def __init__(self):
26
  self.voice_params = tts.VoiceSelectionParams(