Import and Usage
Import
After installing apiaudio, open a .py/.js file and import the apiaudio library as follows:
import apiaudio
import apiaudio from "apiaudio";
// CommonJS version:
const apiaudio = require("apiaudio").default
Authentication
API.audio uses API keys to authenticate requests. View and manage your API key in the dashboard. Set apiaudio.api_key
with the api-key you got from the dashboard:
apiaudio.api_key = "your-key"
import apiaudio from "apiaudio";
apiaudio.configure({ apiKey: "<<apiKey>>"});
Important Note
All of the calls made by NodeJS SDK are asynchronous. You can either use try-await-catch approach or then-catch approach.
Authentication with environment variable (recommended)
You can also authenticate using apiaudio_key
environment variable and the apiaudio SDK will automatically use it. To setup, open the terminal and type:
export apiaudio_key=<your-key>
export apiaudio_key=<your-key>
setx apiaudio_key <your-key>
What if I provide an environment variable AND aflr.api_key authentication?
If you provide both environment variable and apiaudio.api_key authentication, the
apiaudio.api_key
provided in the .py script will be used.
Resource Usage
There are two approaches to use the resources. First approach is to get the resource class first, then use resource methods. For example, to create a Script, we could do:
Script = apiaudio.Script
Script.create()
const { Script } = apiaudio
Script.create();
The second approach is to use it directly:
apiaudio.Script.create()
apiaudio.Script.create();
Same logic applies for other resources (speech, voice, sound...)
Updated almost 2 years ago