I am trying to use google clould api to use text to speech. For this it needs to access a json key which i saved to
C:\keys\*****.json
and set the path as
set GOOGLE_APPLICATION_CREDENTIALS="C:\keys\*****.json"
when I run the sample scrip I get the error that i its not able to find the file on that path.
C:\Users\dsandhu\Documents\linux\googlecloud\python-docs-samples\texttospeech\testing>python sampletest.py
Traceback (most recent call last):
File "sampletest.py", line 28, in <module>
synthesize_text("hello world")
File "sampletest.py", line 4, in synthesize_text
client = texttospeech.TextToSpeechClient()
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\lib\site-packages\google\cloud\texttospeech_v1\gapic\text_to_speech_client.py", line 84, in __init__
scopes=self._DEFAULT_SCOPES,
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\lib\site-packages\google\api_core\grpc_helpers.py", line 170, in create_channel
credentials, _ = google.auth.default(scopes=scopes)
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\lib\site-packages\google\auth\_default.py", line 294, in default
credentials, project_id = checker()
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\lib\site-packages\google\auth\_default.py", line 165, in _get_explicit_environ_credentials
os.environ[environment_vars.CREDENTIALS])
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Anaconda3_64\lib\site-packages\google\auth\_default.py", line 89, in _load_credentials_from_file
'File {} was not found.'.format(filename))
google.auth.exceptions.DefaultCredentialsError: File "C:\keys\*****.json" was not found.
I am using anaconda(as admin) with python to set the variable in anaconda terminal. I also tried to set it in windows cmd (set with same command) but no luck.
I am posting the scrip also in case you want to test it:
def synthesize_text(text):
"""Synthesizes speech from the input string of text."""
from google.cloud import texttospeech
client = texttospeech.TextToSpeechClient()
#text = "Hello world"
input_text = texttospeech.types.SynthesisInput(text=text)
#input_text = texttospeech.types.SynthesisInput(text="Hellow world")
# Note: the voice can also be specified by name.
# Names of voices can be retrieved with client.list_voices().
voice = texttospeech.types.VoiceSelectionParams(
language_code='en-US',
ssml_gender=texttospeech.enums.SsmlVoiceGender.FEMALE)
audio_config = texttospeech.types.AudioConfig(
audio_encoding=texttospeech.enums.AudioEncoding.MP3)
response = client.synthesize_speech(input_text, voice, audio_config)
# The response's audio_content is binary.
with open('output.mp3', 'wb') as out:
out.write(response.audio_content)
print('Audio content written to file "output.mp3"')
synthesize_text("hello world")
using from this link