问题描述
概述 启用以将 IBM Watson API 与 Python 结合使用。无论我使用哪个 URL,我都会收到 403 错误(禁止) 我尝试了以下网址:
- https://stream.watsonplatform.net/text-to-speech/api
- https://api.us-south.speech-to-text.watson.cloud.ibm.com/v1/synthesize
- https://api.us-south.speech-to-text.watson.cloud.ibm.com/text-to-speech/api
- https://api.us-south.speech-to-text.watson.cloud.ibm.com
但它们都不起作用。
代码示例import json
from os.path import join,dirname
from ibm_watson import TextToSpeechV1
from ibm_watson.websocket import SynthesizeCallback
from ibm_cloud_sdk_core.authenticators import IAMAuthenticator
from ibm_watson import ApiException
apikey = 'XXXXXXXXXXXXXX'
url = 'https://stream.watsonplatform.net/text-to-speech/api'
try:
authenticator = IAMAuthenticator(apikey)
service = TextToSpeechV1(authenticator=authenticator)
service.set_service_url(url)
voices = service.list_voices().get_result()
print(json.dumps(voices,indent=2))
except ApiException as ex:
print("Method Failed with status code " + str(ex.code) + ": " + ex.message)
我可以通过 CURL 使用 API。
预期行为 从 API 获得成功响应
屏幕截图
SDK 版本 最新
其他信息:
- 操作系统:Windows 10
- Python 3.9.1
解决方法
根据 API 文档 (https://cloud.ibm.com/apidocs/text-to-speech?code=python#authentication),它应该是:
url = 'https://api.us-east.text-to-speech.watson.cloud.ibm.com'