【问题标题】:Authentication error (401) Azure Speech to text身份验证错误 (401) Azure Speech to text
【发布时间】:2021-02-23 00:42:13
【问题描述】:

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

我创建了一个完整的 Microsoft azure,并按照语音服务的文档进行操作。当我创建一个资源时,我得到了两个键和一个位置。

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

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

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

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

【问题讨论】:

    标签: azure speech-recognition


    【解决方案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)
    

    【讨论】:

    • 我有相同的代码,但我没有使用音频文件。您使用的是免费试用版吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-03-13
    • 2019-02-22
    • 2017-03-11
    • 1970-01-01
    • 2022-01-06
    • 2012-07-30
    • 1970-01-01
    相关资源
    最近更新 更多