import os
import requests
# Add your API token as an environmental variable or hard coded value.
api_token = os.getenv("PYANNOTEAI_API_TOKEN", "your_token_here")
url = "https://api.pyannote.ai/v1/media/input"
headers = {
"Authorization": "Bearer {0}".format(api_token),
"Content-Type": "application/json"
}
# Replace the url value with your temporary storage location that you want to create.
body = {
"url": "media://example/conversation.wav",
}
# Create a pre-signed URL.
response = requests.post(url, json=body, headers=headers)
response.raise_for_status()
data = response.json()
presigned_url = data["url"]
print("Uploading {0} to {1}".format(input_path, presigned_url))
with open(input_path, "rb") as input_file:
# Upload your media.
requests.put(presigned_url, data=input_file)