Hello World!

Install the package

pip install apiaudio -U
yarn add apiaudio

Import & Authenticate with api key

First, create a hello.py file. The library needs to be configured with your account's secret key which is available in your api.audio Console. Import the apiaudio package and set apiaudio.api_key with the api-key you got from the dashboard:

import apiaudio
apiaudio.api_key = "your-key"
import apiaudio from "apiaudio";

apiaudio.configure({ apiKey: "<<apiKey>>", debug: false });

Create Text to mastered audio in 4 steps

Let's create our first mastered audio from text.

✍️ First, create a new script:

script = apiaudio.Script.create(scriptText="Hello world", scriptName="hello")
print(script)
const script = await apiaudio.Script.create({ scriptText: "Hello world", scriptName: "hello", projectName: "hello", moduleName: "hello" });
console.log(script);

🎤 Second, Create a speech audio file from the script using Joanna's voice:

response = apiaudio.Speech.create(scriptId=script["scriptId"], voice="Joanna")
print(response)
const speech = await apiaudio.Speech.create({ scriptId: script["scriptId"], voice: "Joanna" });
console.log(speech);

🎧 Third, let's master the speech file so it sounds with high quality and a nice background track.

response = apiaudio.Mastering.create(
    scriptId=script["scriptId"],
    soundTemplate="heatwave"
    )
print(response)
const template = "parisianmorning";
const mastering = await apiaudio.Mastering.create({ scriptId: script["scriptId"], soundTemplate: template });
console.log(mastering);

🎉 Finally, get the urls of the audio files generated:

urls = apiaudio.Mastering.retrieve(scriptId=script["scriptId"])
print(urls)
const masteringResult = await apiaudio.Mastering.retrieve(script["scriptId"])
console.log(masteringResult);

Or download the files in your current folder, and don't forget to share them ;)

filepath = apiaudio.Mastering.download(scriptId=script["scriptId"], destination=".")
print(filepath)
const masteringResult = await apiaudio.Mastering.download(script["scriptId"], {});
console.log(masteringResult);

Easy right? 🔮 This is the hello.py final picture:

import apiaudio
apiaudio.api_key = "your-key"

# script creation
script = apiaudio.Script.create(scriptText="Hello world", scriptName="hello")

# speech creation
response = apiaudio.Speech.create(scriptId=script["scriptId"], voice="Joanna")
print(response)

# mastering process
response = apiaudio.Mastering.create(
    scriptId=script["scriptId"],
    backgroundTrackId="full__citynights.wav"
    )
print(response)

# get url of audio tracks generated
urls = apiaudio.Mastering.retrieve(scriptId=script["scriptId"])
print(urls)

# or download
filepath = apiaudio.Mastering.download(scriptId=script["scriptId"], destination=".")
print(filepath)
npm install apiaudio
const apiaudio = require("apiaudio").default;

async function helloWorld() {
  apiaudio.configure({ apiKey: "APIKEY" });
  
  try {
    const script = await apiaudio.Script.create({ scriptText: "Hello world", scriptName: "hello", projectName: "hello", moduleName: "hello" });
    console.log(script);

    const speech = await apiaudio.Speech.create({ scriptId: script["scriptId"], voice: "Joanna" });
    console.log(speech); 

    const template = "parisianmorning";
    const mastering = await apiaudio.Mastering.create({ scriptId: script["scriptId"], soundTemplate: template });
    console.log(mastering);

    const masteringResult = await apiaudio.Mastering.retrieve(script["scriptId"], {});
    console.log(masteringResult);
    
  } catch (e) {
    console.error(e);
  }
}

helloWorld();

Run the code!

Now let's run the code:

python hello.py

Did this page help you?