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

Pie*_*TRE 5 speech-recognition azure

当我使用 Azure Whith 免费试用版中的语音转文本时,出现此错误:CANCELED CancellationDetails(reason=CancellationReason.Error, error_details="WebSocket 升级失败:身份验证错误 (401)。请检查订阅信息和区域名称。

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

在我的代码中我这样写:

speech_key, service_region = "<key>", "<location>"
speech_config = speechsdk.SpeechConfig(subscription=speech_key, region=service_region)
Run Code Online (Sandbox Code Playgroud)

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

你知道我是否忘记了什么或者我做了什么坏事吗?

Saj*_*ran 1

我刚刚测试了代码,它工作正常,

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)
Run Code Online (Sandbox Code Playgroud)