How to Encode your File as .wav File Type

Creating a Basic Audio Program with AudioStack and Saving as WAV File Type

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 the WAV 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

    🚧

    Don't forget to pass in a voice name!

  1. print(f"Generating speech...")
    speech = audiostack.Speech.TTS.create(scriptItem=script, voice="wren")
    print(speech)
    
  2. 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)
    
  3. Encode the Mix: Encode the mix into the desired format (WAV).

    encoder = audiostack.Delivery.Encoder.encode_mix(productionItem=mix, preset="wav")
    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, voice="wren")
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="wav")
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 (WAV 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.

πŸ“˜ WAV File Type

The WAV file type is a widely used audio format developed by Microsoft and IBM. Here are some key points about WAV files:

  • Purpose: Primarily used for storing high-quality, uncompressed audio.
  • Quality: Provides excellent sound quality, making it suitable for professional audio applications.
  • Compression: Typically uncompressed, though it can support compressed audio.
  • Compatibility: Supported by nearly all audio playback devices and software.
  • File Size: Generally larger than compressed formats like MP3 due to its uncompressed nature.

WAV files are known for their high audio fidelity and widespread compatibility, making them a popular choice for professional audio recording and editing.