Skip to content

Project: The Essential Feature Set for User Engagement. Created at https://spectra.codes, which is owned by @Drix10

Notifications You must be signed in to change notification settings

coslynx/deno-deepgram-text-to-speech-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

12 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

deno-deepgram-text-to-speech-api

A Deno API for converting text to speech using Deepgram's advanced speech models.

Developed with the software and tools below.

Language-Deno Framework-FastAPI Database-PostgreSQL API-Deepgram Rate Limiting-Upstash
git-last-commit GitHub commit activity GitHub top language

πŸ“‘ Table of Contents

  • πŸ“ Overview
  • πŸ“¦ Features
  • πŸ“‚ Structure
  • πŸ’» Installation
  • πŸ—οΈ Usage
  • 🌐 Hosting
  • πŸ“„ License
  • πŸ‘ Authors

πŸ“ Overview

This repository houses a Minimum Viable Product (MVP) for a Deno API built to convert text to speech using Deepgram's powerful voice models. The API simplifies the integration of speech capabilities into applications, addressing the growing need for on-demand speech generation across diverse platforms like chatbots, interactive voice assistants, accessibility tools, and educational resources. The MVP utilizes a robust tech stack including Deno, FastAPI, PostgreSQL, Deepgram, and Upstash for rate limiting, ensuring efficient and secure operation.

πŸ“¦ Features

Feature Description
βš™οΈ Architecture The API is designed with a modular architecture, separating functionalities into distinct files and directories for enhanced maintainability and scalability.
πŸ“„ Documentation This README provides a detailed overview of the API, its features, installation instructions, usage examples, and deployment guidelines.
πŸ”— Dependencies The API leverages external libraries and packages including FastAPI, SQLAlchemy, Deepgram, Upstash, and other essential dependencies for core functionality and integration.
🧩 Modularity The modular code structure promotes reusability and eases maintenance. Specific functionalities, like authentication, rate limiting, and speech generation, are encapsulated in dedicated modules.
πŸ§ͺ Testing Thorough unit tests and integration tests are implemented to guarantee the reliability and correctness of the API's functionality.
⚑️ Performance The API is optimized for performance, incorporating caching strategies and efficient data management to handle high volumes of requests.
πŸ” Security Robust security measures, including input validation, authentication, and data encryption, are implemented to protect user data and prevent unauthorized access.
πŸ”€ Version Control The project utilizes Git for version control with continuous integration and continuous delivery (CI/CD) implemented using GitHub Actions for automated builds and releases.
πŸ”Œ Integrations The API seamlessly integrates with external services through HTTP requests, including the Deepgram API for speech synthesis and Upstash for rate limiting and caching.
πŸ“Ά Scalability The architecture is designed for scalability to handle increasing user demand. The API can be easily scaled horizontally and vertically based on traffic patterns.

πŸ“‚ Structure

deno-deepgram-text-to-speech-api/
β”œβ”€β”€ app
β”‚   β”œβ”€β”€ main.py
β”‚   β”œβ”€β”€ models
β”‚   β”‚   └── user.py
β”‚   β”œβ”€β”€ routers
β”‚   β”‚   └── speech.py
β”‚   β”œβ”€β”€ services
β”‚   β”‚   └── speech_service.py
β”‚   β”œβ”€β”€ utils
β”‚   β”‚   β”œβ”€β”€ auth.py
β”‚   β”‚   └── rate_limiter.py
β”‚   β”œβ”€β”€ config
β”‚   β”‚   └── database.py
β”‚   └── database.py
β”œβ”€β”€ tests
β”‚   └── test_speech.py
β”œβ”€β”€ requirements.txt
└── .env

πŸ’» Installation

πŸ”§ Prerequisites

  • Python 3.9+
  • pip
  • Docker
  • Docker Compose

πŸš€ Setup Instructions

  1. Clone the repository:
    • git clone https://github.com/spectra-ai-codegen/deno-deepgram-text-to-speech-api.git
  2. Navigate to the project directory:
    • cd deno-deepgram-text-to-speech-api
  3. Install dependencies:
    • pip install -r requirements.txt

πŸ—οΈ Usage

πŸƒβ€β™‚οΈ Running the API

  1. Set up environment variables:
    • Create a .env file in the project root.
    • Add the following environment variables:
      • DEEPGRAM_API_KEY: Your Deepgram API key.
      • UPSTASH_REDIS_URL: Your Upstash Redis connection URL.
      • DATABASE_URL: Your PostgreSQL database connection URL.
  2. Start the API:
    • uvicorn app.main:app --reload

βš™οΈ Configuration

  • Database configuration is in app/config/database.py.
  • Authentication and authorization are managed in app/utils/auth.py.
  • Rate limiting is configured in app/utils/rate_limiter.py.

πŸ“š Examples

  • Example 1: Generate speech from text
    curl -X POST "http://localhost:8000/speech" \
      -H "Content-Type: application/json" \
      -d '{
        "text": "Hello, world!",
        "model_id": "deepgram_model_id" 
      }'

🌐 Hosting

πŸš€ Deployment Instructions

  1. Build Docker image:
    • docker build -t deno-deepgram-text-to-speech-api .
  2. Start a Docker container:
    • docker run -d -p 8000:8000 deno-deepgram-text-to-speech-api
  3. Access the API:
    • The API is accessible at http://localhost:8000.

πŸ”‘ Environment Variables

  • DEEPGRAM_API_KEY: Your Deepgram API key.
  • UPSTASH_REDIS_URL: Your Upstash Redis connection URL.
  • DATABASE_URL: Your PostgreSQL database connection URL.

πŸ“œ API Documentation

πŸ” Endpoints

  • POST /speech: Converts text to speech.
    • Request body:
      {
        "text": "The text to convert to speech.",
        "model_id": "The Deepgram voice model ID."
      }
    • Response body:
      {
        "audio_url": "The URL of the generated audio file."
      }

πŸ”’ Authentication

  • The API uses JWT authentication to secure endpoints.

πŸ“ Examples

  • Generate speech using the API:
    curl -X POST "http://localhost:8000/speech" \
      -H "Content-Type: application/json" \
      -d '{
        "text": "This is a test.",
        "model_id": "deepgram_model_id" 
      }'

πŸ“œ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ‘₯ Authors

🌐 Spectra.Codes

Why only generate Code? When you can generate the whole Repository!