There are several ways to make an API call.
If you followed the first step: 'Get your free api key', you may already have done so, using our graphic interface.
If not, you can also watch this video to see how to do it:
Here, we will see how to do it programmatically.
Using Curl
As you can already see in the graphic interface in https://app.gladia.io, you can make transcription requests yourself using different languages. This is a curl request using audio-transcription:
curl -X 'POST' \
'https://api.gladia.io/audio/text/audio-transcription/' \
-H 'accept: application/json' \
-H 'x-gladia-key: <your_api_key>' \
-H 'Content-Type: multipart/form-data' \
-F "audio_url=http://files.gladia.io/example/audio-transcription/split_infinity.wav"
Be careful to replace '<your_api_key>' with your own api key obtained from the 'Get your free api key' tutorial.
You can now open a terminal and copy/paste the snippet containing your own API key.
Using other languages (Python, JavaScript, Php, ...)
You can make requests using any languages you want.
Here, we will see an example using audio-transcription in different languages and libraries:
import requests
headers = {
'accept': 'application/json',
'x-gladia-key': '<your_api_key>',
}
files = {
'audio_url': (None, 'http://files.gladia.io/example/audio-transcription/split_infinity.wav')
}
response = requests.post('https://api.gladia.io/audio/text/audio-transcription/', headers=headers, files=files)
import fetch, { FormData } from 'node-fetch';
const form = new FormData();
form.append('audio_url', 'http://files.gladia.io/example/audio-transcription/split_infinity.wav');
fetch('https://api.gladia.io/audio/text/audio-transcription/', {
method: 'POST',
headers: {
'accept': 'application/json',
'x-gladia-key': '<your_api_key>',
'Content-Type': 'multipart/form-data'
},
body: form
});
const axios = require('axios');
const FormData = require('form-data');
const form = new FormData();
form.append('audio_url', 'http://files.gladia.io/example/audio-transcription/split_infinity.wav');
const response = await axios.post(
'https://api.gladia.io/audio/text/audio-transcription/',
form,
{
headers: {
...form.getHeaders(),
'accept': 'application/json',
'x-gladia-key': '<your_api_key>',
'Content-Type': 'multipart/form-data'
}
}
);
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api.gladia.io/audio/text/audio-transcription/');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'accept' => 'application/json',
'x-gladia-key' => '<your_api_key>',
'Content-Type' => 'multipart/form-data',
]);
curl_setopt($ch, CURLOPT_POSTFIELDS, [
'audio_url' => 'http://files.gladia.io/example/audio-transcription/split_infinity.wav',
]);
$response = curl_exec($ch);
curl_close($ch);
As in the previous part, do not forget to replace '<your_api_key>'.
Using SDK (JavaScript/TypeScript)
To simplify this process even more, you can use Gladia's SDK. It's a simple way to use the APIs and explore them thanks to full auto-completion.
Let's see how to use it.
In your node project, install the package using the following:
npm i @gladiaio/sdk
Then, anywhere in your app, use the following:
import gladia from '@gladiaio/sdk';
const gladiaClient = gladia({ apiKey: '<your_api_key>' });
const result = await gladiaClient.audioTranscription({
audio_url: 'http://files.gladia.io/example/audio-transcription/split_infinity.wav',
});
import { gladia } from '@gladiaio/sdk';
const gladiaClient = gladia({ apiKey: '<your_api_key>' });
const result = await gladiaClient.audioTranscription({
audio_url: 'http://files.gladia.io/example/audio-transcription/split_infinity.wav',
});
const { gladia } = require('@gladiaio/sdk');
const gladiaClient = gladia({ apiKey: '<your_api_key>' });
const result = await gladiaClient.audioTranscription({
audio_url: 'http://files.gladia.io/example/audio-transcription/split_infinity.wav',
});
More information about the SDK on SDK Readme
Using CLI (Command-Line Interface)
Install the binary directly
linux
wget https://github.com/gladiaio/gladia-cli/raw/main/dist/linux_x64_gladia && \
mv linux_x64_gladia gladia && \
chmod +x gladia
macOS
wget https://github.com/gladiaio/gladia-cli/raw/main/dist/macos_arm64_gladia && \
mv macos_arm64_gladia gladia && \
chmod +x gladia
Build from source
At the time where this is being written, only audio-transcription is supported.
First, you need to download the following repository: https://github.com/gladiaio/gladia-cli
Make sure to install the required dependencies before launching.
pip install -r requirements.txt
Then, run the following command to build the cli:
./build.sh
CLI Usage
To authenticate, be sure to have an API key. If not, read the tutorial 'Get your free api key', then run the following if you want to save the key:
./gladia_cli --gladia-key MY_GLADIA_KEY --save-gladia-key
or use it inline for each request:
./gladia_cli --gladia-key MY_GLADIA_KEY --OTHER_OPTIONS ...
And this is the usage:
./gladia_cli --audio-url http://files.gladia.io/example/audio-transcription/split_infinity.wav
Transcribing audio file...
Transcript
time_begin time_end probability language speaker transcription
0.09 2.07 0.49 en not_activated Split infinity
2.13 5.19 0.65 en not_activated in a time when less is more
5.52 20.4 0.75 en not_activated Where too much is never enough, there is always hope for the future. The future can be read from the past. The past foreshadows the present, and the present hasn't been written yet
More information about CLI options and usage on https://github.com/gladiaio/gladia-cli