身份验证错误 (401) Azure 语音转文本

时间:2021-02-22 16:24:46

标签: azure speech-recognition

当我使用 Speech 从 azure 发短信到免费试用版时出现此错误:CANCELED CancellationDetails(reason=CancellationReason.Error, error_details="WebSocket upgrade failed: Authentication error (401)。请检查订阅信息和区域名称.

我创建了一个 acompt Microsoft azure,并遵循了语音服务的文档。当我创建一个资源时,我得到了两个密钥和一个位置。

在我的代码中我写了这个:

speech_key, service_region = "<key>", "<location>"
speech_config = speechsdk.SpeechConfig(subscription=speech_key, region=service_region)

当我运行此代码时,会显示此错误。我确定我输入了正确的密钥和位置。

你知道我是忘记了什么还是做错了什么吗?

1 个答案:

答案 0 :(得分:0)

我刚刚测试了代码,它运行良好,

import azure.cognitiveservices.speech as speechsdk
from azure.cognitiveservices.speech.audio import AudioOutputConfig


# Replace with your own subscription key and service region (e.g., "westus")
# Side note: some regions do not support text-to-speech
speech_key, service_region = "subscription_key", "service_region"

# Replace with input file name and format
input_file = open("input_file.txt", "r")
text = input_file.read()

# Replace desired output file name and format
output_file = "output_file.mp3"


# Creates an instance of a speech config with a specified subscription key and service region
speech_config = speechsdk.SpeechConfig(subscription=speech_key, region=service_region)