我似乎无法获得Azure认知服务访问令牌的授权。我使用的是azure团队发布到github的示例代码(修改后取我的密钥)。在
我已经看过文件,据我所知,我做的一切都是对的。我也用过“统一语音服务免费试用”,但那也不管用。在
class TextToSpeech(object):
def __init__(self, subscription_key):
self.subscription_key = subscription_key
self.tts = "testing the TTS abilities of Azure using python"
#self.tts = input("What would you like to convert to speech: ")
self.timestr = time.strftime("%Y%m%d-%H%M")
self.access_token = None
'''
The TTS endpoint requires an access token. This method exchanges your
subscription key for an access token that is valid for ten minutes.
'''
def get_token(self):
fetch_token_url = "https://eastus.api.cognitive.microsoft.com/sts/v1.0/issuetoken"
headers = {
'Ocp-Apim-Subscription-Key': self.subscription_key
}
response = requests.post(fetch_token_url, headers=headers)
self.access_token = str(response.text)
if __name__ == "__main__":
app = TextToSpeech(subscription_key)
app.get_token()
下面是访问令牌的输出
^{pr2}$我应该得到的是临时访问令牌,但由于某种原因,我得到了上面的错误,我不知道为什么。在
此错误是由于您调用了错误的终结点。请尝试下面的代码开始在main方法中使用您自己的订阅参数:
您可以在Azure门户网站上找到您的区域和订阅密钥值:
我已经在我这边测试过了,它对我有用。一旦你检查代码,就会创建一个wav文件,这是你需要的:
相关问题 更多 >
编程相关推荐