Вот мой код:
Код: Выделить всё
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)}
- Я успешно получаю аудиофайл из Twilio с помощью Request.get.
- Затем я отправляю URL-адрес аудио в Deepgram для транскрипции с помощью метода deepgram_client.listen.rest.v("1").transcribe_url.
Вызов API завершается с ошибкой 401 Unauthorized, хотя проверка подлинности Twilio () верен.Код: Выделить всё
HTTPBasicAuth(TWILIO_ACCOUNT_SID, TWILIO_AUTH_TOKEN)
Код: Выделить всё
Error during transcription: DeepgramApiError: The remote server hosting the media returned a client error: 401 Unauthorized. (Status: 400)
- Twilio API: используется для получения аудио из Twilio.
- Deepgram API: используется для расшифровки аудиофайла.
Подробнее здесь: https://stackoverflow.com/questions/793 ... nding-audi