我正在尝试在Windows上设置Google Cloud API。我花了很多时间来解决这个问题,阅读所有相关问题没有任何帮助! 首先我设置变量
set GOOGLE_APPLICATION_CREDENTIALS="C:UsersDesktopdirectoryfilename.json"
curl -H "Authorization: Bearer "$(gcloud auth application-default print-access-token)
-H "Content-Type: application/json; charset=utf-8"
--data "{
'input':{
'text':'Android is a mobile operating system developed by Google,
based on the Linux kernel and designed primarily for
touchscreen mobile devices such as smartphones and tablets.'
},
'voice':{
'languageCode':'en-gb',
'name':'en-GB-Standard-A',
'ssmlGender':'FEMALE'
},
'audioConfig':{
'audioEncoding':'MP3'
}
}" "https://texttospeech.googleapis.com/v1/text:synthesize" > synthesize-text.txt
如谷歌文档中所述。但在命令行中
卷曲:(6( 云未解析主机:身份验证 curl:(6( 云未解析主机:应用程序默认值 curl:(6( 云未解析主机:打印访问令牌
显示此错误。在合成文本中.txt说错误代码 401。
我该如何解决这个问题。任何帮助赞赏。
编辑: 当我原谅
gcloud auth 应用程序默认的打印访问令牌命令返回环境变量不存在时!但是 ı 执行设置命令。我做错了什么?
这是由于Windows不接受$(gcloud auth application-default print-access-token)
使用。
您可以尝试将打印访问令牌的命令输出写入文件。例如:
gcloud auth application-default print-access-token > token.txt
然后,您可以将其分配给环境变量:
set /p token=<token.txt
并尝试像这样运行文本到语音转换 API 请求:
curl -H "Authorization: Bearer "%token%
-H "Content-Type: application/json; charset=utf-8"
--data "{
'input':{
'text':'Android is a mobile operating system developed by Google,
based on the Linux kernel and designed primarily for
touchscreen mobile devices such as smartphones and tablets.'
},
'voice':{
'languageCode':'en-gb',
'name':'en-GB-Standard-A',
'ssmlGender':'FEMALE'
},
'audioConfig':{
'audioEncoding':'MP3'
}
}" "https://texttospeech.googleapis.com/v1/text:synthesize" > synthesize-text.txt
或者,您可以尝试对请求使用 API 密钥。例如:
curl -H "Content-Type: application/json; charset=utf-8"
--data "{
'input':{
'text':'Android is a mobile operating system developed by Google,
based on the Linux kernel and designed primarily for
touchscreen mobile devices such as smartphones and tablets.'
},
'voice':{
'languageCode':'en-gb',
'name':'en-GB-Standard-A',
'ssmlGender':'FEMALE'
},
'audioConfig':{
'audioEncoding':'MP3'
}
}" "https://texttospeech.googleapis.com/v1/text:synthesize?key=YOUR_API_KEY" > synthesize-text.txt