You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Deepgram API转录Twilio音频时遭遇401 Unauthorized错误求助

使用Deepgram API转录Twilio音频时遭遇401 Unauthorized错误求助

我尝试用Deepgram API转录来自Twilio的音频文件,但在转录时遇到了401 Unauthorized错误。

以下是我的代码:

async def transcribe_audio(audio_url: str) -> dict:
    try:
        print(f"Sending audio to Deepgram for transcription: {audio_url}")
        response = requests.get(audio_url, auth=HTTPBasicAuth(TWILIO_ACCOUNT_SID, TWILIO_AUTH_TOKEN))

        if response.status_code == 200:
            print("Successfully fetched the audio file from Twilio.")
            
            options = PrerecordedOptions(
                model="nova-2",
                smart_format=True,
                language="en",
                punctuate=True
            )

            response = await deepgram_client.listen.rest.v("1").transcribe_url(
                {"url": audio_url}, 
                options
            )

            print(f"Deepgram Response: {response}")

            if response and hasattr(response, 'results'):
                transcript = response.results.channels[0].alternatives[0].transcript
                return {
                    "transcription": transcript,
                    "confidence": response.results.channels[0].alternatives[0].confidence
                }
            else:
                raise ValueError("No transcription results found in the response")

        else:
            raise ValueError(f"Failed to fetch audio from Twilio. HTTP Status Code: {response.status_code}")
    
    except Exception as e:
        print(f"Error during transcription: {e}")
        return {"error": str(e)}

出现问题的具体流程:

  • 我能通过requests.get方法成功从Twilio获取音频文件。
  • 随后我通过deepgram_client.listen.rest.v("1").transcribe_url方法将音频URL发送给Deepgram进行转录。
  • 尽管Twilio的认证(HTTPBasicAuth(TWILIO_ACCOUNT_SID, TWILIO_AUTH_TOKEN))是正确的,但API调用还是返回了401 Unauthorized错误。

我收到的错误信息如下:

Error during transcription: DeepgramApiError: The remote server hosting the media returned a client error: 401 Unauthorized. (Status: 400)

我的环境:

  • Twilio API:用于从Twilio获取音频
  • Deepgram API:用于转录音频文件

我已经检查过我的API密钥,看起来没有问题,但还是遇到了这个问题。


备注:内容来源于stack exchange,提问作者D Batch

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.14 17:04:32