Skip to content

sethtbacon/text-to-speech

Repository files navigation

OpenAI & Azure TTS Demo in GitHub Codespaces

This project demonstrates how to convert text to speech using the TTS APIs from OpenAI and Azure. It has been reworked to provide a streamlined development experience in GitHub Codespaces with a modern file structure and improved diagnostics.

Project Structure

  • tts_demo.py: Main Python script that reads text from text_to_convert.txt and generates speech audio.
    • For OpenAI TTS, the script outputs output.mp3.
    • For Azure TTS, the script outputs output_azure.mp3.
  • text_to_convert.txt: Contains the text to convert into speech.
  • .env: Environment file (should contain your API keys and region) that is loaded via Codespaces secrets.
  • requirements.txt: Lists the Python dependencies.
  • .devcontainer/: Contains the devcontainer.json for setting up your Codespace.
  • diagnostics/: Contains scripts for verifying environment variable injection and Azure configuration (validate_env.py and validate_azure.py).
  • .gitignore: Ensures that generated audio files, environment files, and cache directories are not committed.

Features

  • Dual TTS Endpoints: Easily switch between OpenAI and Azure TTS using command-line options.
  • Customizable Voices: Select voices using the command-line arguments (--voice for Azure, --voice-oai for OpenAI).
  • Diagnostics Tools: Validate your environment setup with the scripts in the diagnostics folder.
  • GitHub Codespaces Ready: Preconfigured with a devcontainer for a seamless VSCode experience in Codespaces.

Available Voices

OpenAI TTS Voices

  • nova
  • shimmer
  • echo
  • onyx
  • fable
  • alloy
  • ash
  • sage
  • coral

Azure TTS Voices (Examples)

Prerequisites

Setup

  1. Clone the Repository in GitHub Codespaces

    • Open your repository in GitHub, click the Code button, and select the Codespaces tab to create a new Codespace.
  2. Configure API Keys

    • In the root directory, create a file named .env (or use Codespaces secrets) with the following content:
      OPENAI_API_KEY=your-openai-api-key
      AZURE_API_KEY=your-azure-api-key
      AZURE_REGION=your-azure-region
  3. Install Dependencies

    • Open a terminal in the project root and run:
      pip install -r requirements.txt
  4. Run Diagnostics (Optional)

    • Validate that your environment variables are correctly injected:
      python diagnostics/validate_env.py
      python diagnostics/validate_azure.py
  5. Running the TTS Demo

    • For OpenAI TTS:
      python tts_demo.py --endpoint openai --voice-oai nova
    • For Azure TTS:
      python tts_demo.py --endpoint azure --voice en-US-AriaNeural

After running the script, check the output audio file (either output.mp3 or output_azure.mp3) using your preferred media player.

Additional Resources

License

This project is provided for educational purposes only. Please adhere to the usage policies of OpenAI and Azure when using their services.

Acknowledgments

  • Thanks to OpenAI and Azure for their TTS services.
  • Special thanks to the GitHub Codespaces team for providing an excellent development environment.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages