How to Install and Use the AudioStack Javascript SDK
Get started and generate your first audio π
This guide is aimed at developers who want to get up and running with AudioStack as quickly as possible. By the end of this Quick Start, you will have generated your first audio using our Javascript SDK, and know how to change voices, sound templates and mastering presets.
Step 1 - Make sure you have Node installed
For Mac:
- If you don't have homebrew installed already, you might need to do this too.
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
- Note: If you have issues doing this in the Terminal, you can download the installer here.
brew install node
For Linux:
# installs nvm (Node Version Manager)
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
# download and install Node.js (you may need to restart the terminal)
nvm install 20
# verifies the right Node.js version is in the environment
node -v # should print `v20.15.0`
# verifies the right NPM version is in the environment
npm -v # should print `10.7.0`
For Windows:
- Download the installer here
Step 2 - Install AudioStack Javascript SDK
npm install @aflr/audiostack
Step 4 - Create your Javascript File
touch MyFirstAudio.js
Step 5 - Copy and Paste the Quick Start Code
Copy and paste this example code into your Javascript file, replacing the API key with your personal API key. You can access your API key from our Platform.
/**
* Audiostack Hello World Example
*
* Add your API key on line 12 and run
* node example.js
*/
// Import the library
const { Audiostack } = require('@aflr/audiostack');
// Provide your api key from the Audiostack Platform
const apiKey = 'APIKEY';
/**
* This example demonstrates how to produce and download a file using the Audiostack API.
*/
const example = async () => {
// Create a new instance of Audiostack
const AS = new Audiostack(apiKey);
// Create a script asset with our hello text
const script = await AS.Content.Script.create({
scriptText:
'Congratulations on creating your first ever generated audio file with the AudioStack Javascript SDK.',
});
// Create a speech asset using our script and the voice "sara"
const tts = await AS.Speech.Tts.create({
scriptId: script.scriptId,
voice: 'sara',
});
// Create a mix with our speech asset
const mix = await AS.Production.Mix.create({
speechId: tts.speechId,
});
// Encode the file to high quality mp3
const encode = await AS.Delivery.Encoder.encodeMix({
productionId: mix.productionId,
preset: 'mp3_high',
});
// Download the file to the project directory
const path = await encode.download();
// Print the path to the file
console.log(`File downloaded to: ${path}`);
};
// Run the example
example();
Want to try a low cost voice to test out how the API works?
We keep one of our Retro voices available for this purpose - try using "Rollingthunder" to reduce the number of credits you use up for this test.
Keep your API key safe
Remember, your API key is like a password, so you should keep it safe and avoid sharing it with anyone, including in shared or public repositories.
Step 6 - Run your code
node myFirstAudio.js
Congratulations!
You just generated your first audio asset using AudioStack.
Updated 6 months ago