First, you need to authenticate your API requests using an API key. You can generate your API key from the pyannoteAI dashboard.Here’s an example of how to authenticate using your API key:
To create a diarization job, you’ll send a POST request to the diarize endpoint with the URL of the audio file and a webhook URL where the results will be sent.Here’s an example:
Typically files are stored in a cloud storage service such as Amazon S3. If you have a file stored in a cloud storage service, you can generate a public (signed) URL to the file and use that URL in the API request. Make sure the URL is publicly accessible so our servers can access the file.If you want to manually expose a public file url, you can use the following code, which exposes a file named sample.mp3 with a python Flask server:
Copy
from flask import Flask, request, jsonifyapp = Flask(__name__)@app.route('/sample.mp3', methods=['GET'])def get_audio_file(): # Replace this with your actual file path file_path = '/path/to/sample.mp3' return send_file(file_path, mimetype='audio/mpeg')if __name__ == '__main__': app.run(port=5000)
Make sure your webhook server is set up to handle this JSON payload. For example, using Flask in Python:
Copy
from flask import Flask, request, jsonifyapp = Flask(__name__)@app.route('/your-webhook-url', methods=['POST'])def handle_webhook(): data = request.json print(data) # Process the data as needed return jsonify({'status': 'received'}), 200if __name__ == '__main__': app.run(port=5000)
You can also use a tool like ngrok to expose your local server to the internet and receive webhooks. Or use a site like webhook.site to test webhooks.
By following these steps, you can create a diarization job, receive the results via webhook, and process them as needed. Make sure to handle errors and edge cases appropriately in your actual implementation.For more details on how to create a diarization, check out the Diarization API reference.