Beginners: Generate your First Audio
Let's produce your first AudioStack audio asset using the Python SDK.
Step 1 - Activate your Virtual Environment
Get started by opening your IDE (if you followed the set up tutorial, you'll be working in Visual Studio Code) and activating your virtual environment. To do this, enter the following command into your terminal window (in Visual Studio) and press enter.
Mac/ Linux: source myFirstAudioStackProject/bin/activate
Windows: myFirstAudioStackProject\Scripts\activate
Unsure what this means?
If you haven't set up your development environment yet, be sure to complete the set up tutorial first. Don't worry, it only takes a few minutes to complete and is aimed at people totally new to software development. You'll be back here in no time! π
Step 2 - Create a Python File
Create a new python file by going to File/ New File, and saving your file in your Documents with a sensible name. For this tutorial we recommend using myFirstAudio.py.
Step 3 - Enter the Code into your Python File
Copy and paste the following code into your newly created file, then save the file.
import audiostack
import os
# First, paste your API key inside the quotation marks below:
audiostack.api_key = "APIKEY"
# This code example demonstrates functionality from the Content, Speech, Production and Delivery parts of the AudioStack API.
# Using the API, you can create production-ready audio assets in minutes.
# In Content, you can create scripts and manage your production assets.
script = """
<as:section name="main" soundsegment="main">
With AudioStack, you can create compelling, synthetic audio adverts in minutes. Add your copy here to get started. </as:section>
"""
names = ["Cosmo"] # Add names to the list to generate multiple audio files using different voices
presets = ["musicenhanced"]
templates = ["sound_affects"]
print("Creating the script...")
script = audiostack.Content.Script.create(
scriptText=script, scriptName="test", projectName="mastering_test"
)
for name in names:
# In Speech, you can access top quality AI voice models, or use your own cloned voice.
print(f"Synthesizing speech for {name}")
speech = audiostack.Speech.TTS.create(scriptItem=script, voice=name, speed=1)
for template in templates:
for preset in presets:
# In Production, you can dynamically mix content, apply sound designs and master your audio so that it sounds as professional as possible.
print(
f"Mixing the speech with template `{template}` using `{preset}` preset"
)
mix = audiostack.Production.Mix.create(
speechItem=speech,
soundTemplate=template,
masteringPreset=preset,
)
# Now you can download the wav file, or use the Delivery API to encode it to another format.
print("Downloading the wav file...")
file_name = f"V1_{name}_{template}_{preset}"
mix.download(fileName=file_name)
current_directory = os.path.dirname(os.path.abspath(__file__))
print(f"File downloaded to: {current_directory}/{file_name}.wav")
# In Delivery, you can encode your audio to a variety of formats, and host it on our server!
delivery = audiostack.Delivery.Encoder.encode_mix(
productionItem=mix,
preset="mp3_high",
public=True,
)
print("MP3 file URL:", delivery.url)
Step 4 - Connect with your API Key
Open your web browser, and log in to the AudioStack Platform (or register if youβre new to AudioStack π).
Then, copy your unique API key.
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 code repositories on platforms such as Github.
Paste your API key into your Python file, replacing the placeholder text APIKEY in line 6. Save your file.
Step 5 - Run your Python code!
Next, you'll need to navigate to your Python file in the terminal. If you saved the file in your Documents folder, you might already be in the right place.
You can navigate around your saved folders from within the Terminal
Type
cd
followed by the folder name to open a folder. To check which files are in the folder, typels
. This should return a list of files inside the current folder, printed in your terminal window. You can find out more about navigating around files and folders using the command line here.
Once you have the correct folder open in the terminal, you can run your Python code by typing python3 myFirstAudio.py
and pressing enter to run the command.
Congratulations, you just generated your first audio asset using AudioStack!
Your audio file can be found in the folder where your Python file is saved.
Updated 6 months ago
Try generating different versions of your asset with other names, presets and templates. You can easily generate multiple different versions of your audio in one go by adding names, presets and templates to the respective lists in Lines 19-21 of your Python file. For example:
names = ["Promo_Ramona"]
presets = ["voiceenhanced", "balanced"]
templates = ["spooky_strings"]