import requests
import time
def transcribe_with_speakers(audio_url):
headers = {
"x-api-key": "YOUR_API_KEY",
"Content-Type": "application/json"
}
# Submit transcription job
data = {
"audioUrl": audio_url,
"model": "Elevenlabs-STT",
"diarize": True,
"tagAudioEvents": True
}
response = requests.post(
"https://nano-gpt.com/api/transcribe",
headers=headers,
json=data
)
if response.status_code == 202:
job_data = response.json()
# Poll for results
status_data = {
"runId": job_data['runId'],
"cost": job_data.get('cost'),
"paymentSource": job_data.get('paymentSource'),
"isApiRequest": True
}
while True:
status_response = requests.post(
"https://nano-gpt.com/api/transcribe/status",
headers=headers,
json=status_data
)
result = status_response.json()
if result.get('status') == 'completed':
return result
elif result.get('status') == 'failed':
raise Exception(f"Transcription failed: {result.get('error')}")
time.sleep(5)
result = transcribe_with_speakers("https://example.com/meeting.mp3")
# Access speaker segments
for segment in result['diarization']['segments']:
print(f"{segment['speaker']}: {segment['text']}")