How to Save your Audio as .ogg File Type

Creating a Basic Audio Program with AudioStack and saving as .ogg file type

πŸ“˜

Ogg file type

The OGG file type is a free, open-source container format designed for multimedia files, including audio, video, text, and metadata. Here are some key points about OGG files:

  • Purpose: Primarily used for storing and streaming high-quality audio.
  • Compression: Utilizes the Ogg Vorbis codec for audio compression, providing efficient storage without significant loss of quality.
  • Versatility: Can contain various types of media, making it a versatile format.
  • Open Source: Developed by the Xiph.Org Foundation, it's free to use without licensing fees.
  • Compatibility: Supported by many media players and devices, though less universally recognized than formats like MP3 or AAC.

OGG files are known for their high audio quality and efficient compression, making them a popular choice for streaming and archiving audio.

In this tutorial, we will create a basic audio program using the AudioStack API. We will take a simple text, convert it to speech, and create an audio mix. Finally, we'll encode the mix into a specific format and download it. This showcases the power of the API.

Prerequisites

  1. Python installed on your system.
  2. An API key from AudioStack. http://platform.audiostack.ai
  3. The audiostack library installed. You can install it using pip:
    pip install audiostack
    

Steps to Create the Audio Program

  1. Import Required Libraries: Start by importing the necessary libraries.

    import audiostack
    import os
    
  2. Set Up Your API Key: Assign your AudioStack API key to the api_key variable.

    audiostack.api_key = "YOUR_API_KEY"
    

    Replace "YOUR_API_KEY" with your actual API key.

  3. Define the Text: Create a string variable with the text you want to convert to speech.

    text = """Hello world"""
    
  4. Create the Script: Use the AudioStack API to create a script from your text.

    print(f"Creating your script...")
    script = audiostack.Content.Script.create(scriptText=text)
    print(script)
    
  5. Generate Speech: Convert the script to speech.

    print(f"Generating speech...")
    speech = audiostack.Speech.TTS.create(scriptItem=script, voice="wren")
    print(speech)
    
  6. Create the Mix: Combine the speech with a mastering preset to create an audio mix.

    print(f"Creating your mix...")
    mix = audiostack.Production.Mix.create(
            speechItem=speech,
            masteringPreset="podcast",
        )
    print(mix)
    
  7. Encode the Mix: Encode the mix into the desired format (e.g., OGG).

    encoder = audiostack.Delivery.Encoder.encode_mix(productionItem=mix, preset="ogg")
    encoder.download(file=".")
    

    This will download the encoded audio file to your current directory.

Full Code

Here is the complete code to create a basic audio program:

import audiostack
import os

# Set up your API key
audiostack.api_key = "YOUR_API_KEY"

# Define the text to convert to speech
text = """Hello world"""

# Create the script from the text
print(f"Creating your script...")
script = audiostack.Content.Script.create(scriptText=text)
print(script)

# Generate speech from the script
print(f"Generating speech...")
speech = audiostack.Speech.TTS.create(scriptItem=script)
print(speech)

# Create an audio mix from the speech
print(f"Creating your mix...")
mix = audiostack.Production.Mix.create(
        speechItem=speech,
        masteringPreset="podcast",
    )
print(mix)

# Encode the mix into the desired format and download it
encoder = audiostack.Delivery.Encoder.encode_mix(productionItem=mix, preset="ogg")
encoder.download(file=".")

Explanation

  • Creating the Script: We first create a script using the text provided. This script is then used as input for the text-to-speech (TTS) process.
  • Generating Speech: The script is converted to speech using the TTS API.
  • Creating the Mix: The speech is combined with a mastering preset to create a polished audio mix.
  • Encoding the Mix: The final mix is encoded into a specific format (OGG in this case) and downloaded.

This tutorial demonstrates the basic workflow for creating an audio program with AudioStack, from text to a downloadable audio file.