{"id":17528914,"url":"https://github.com/travisvn/openai-edge-tts","last_synced_at":"2025-04-09T07:10:17.994Z","repository":{"id":258741713,"uuid":"870374636","full_name":"travisvn/openai-edge-tts","owner":"travisvn","description":"Text-to-speech API endpoint compatible with OpenAI's TTS API endpoint, using Microsoft Edge TTS to generate speech for free locally","archived":false,"fork":false,"pushed_at":"2024-10-23T21:33:46.000Z","size":75,"stargazers_count":80,"open_issues_count":0,"forks_count":14,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-10-24T09:58:42.566Z","etag":null,"topics":["ai","chatgpt","edge-tts","llm","llm-webui","llms","ollama","ollama-webui","open-webui","openai","self-hosted","speech","text-to-speech","tts"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/travisvn.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-10-09T23:31:11.000Z","updated_at":"2024-10-23T21:33:50.000Z","dependencies_parsed_at":"2024-10-26T08:30:23.639Z","dependency_job_id":null,"html_url":"https://github.com/travisvn/openai-edge-tts","commit_stats":null,"previous_names":["travisvn/openai-edge-tts"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/travisvn%2Fopenai-edge-tts","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/travisvn%2Fopenai-edge-tts/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/travisvn%2Fopenai-edge-tts/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/travisvn%2Fopenai-edge-tts/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/travisvn","download_url":"https://codeload.github.com/travisvn/openai-edge-tts/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247994122,"owners_count":21030050,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ai","chatgpt","edge-tts","llm","llm-webui","llms","ollama","ollama-webui","open-webui","openai","self-hosted","speech","text-to-speech","tts"],"created_at":"2024-10-20T16:00:37.488Z","updated_at":"2025-04-09T07:10:17.971Z","avatar_url":"https://github.com/travisvn.png","language":"Python","funding_links":[],"categories":["Python","SDK, Libraries, Frameworks","NLP"],"sub_categories":["Python library, sdk or frameworks"],"readme":"# OpenAI-Compatible Edge-TTS API 🗣️\n\n![GitHub stars](https://img.shields.io/github/stars/travisvn/openai-edge-tts?style=social)\n![GitHub forks](https://img.shields.io/github/forks/travisvn/openai-edge-tts?style=social)\n![GitHub repo size](https://img.shields.io/github/repo-size/travisvn/openai-edge-tts)\n![GitHub top language](https://img.shields.io/github/languages/top/travisvn/openai-edge-tts)\n![GitHub last commit](https://img.shields.io/github/last-commit/travisvn/openai-edge-tts?color=red)\n[![Discord](https://img.shields.io/badge/Discord-Voice_AI_%26_TTS_Tools-blue?logo=discord\u0026logoColor=white)](https://discord.gg/GkFbBCBqJ6)\n[![LinkedIn](https://img.shields.io/badge/Connect_on_LinkedIn-%230077B5.svg?logo=linkedin\u0026logoColor=white)](https://linkedin.com/in/travisvannimwegen)\n\n\nThis project provides a local, OpenAI-compatible text-to-speech (TTS) API using `edge-tts`. It emulates the OpenAI TTS endpoint (`/v1/audio/speech`), enabling users to generate speech from text with various voice options and playback speeds, just like the OpenAI API.\n\n`edge-tts` uses Microsoft Edge's online text-to-speech service, so it is completely free.\n\n[View this project on Docker Hub](https://hub.docker.com/r/travisvn/openai-edge-tts)\n\n# Please ⭐️ star this repo if you find it helpful\n\n## Features\n\n- **OpenAI-Compatible Endpoint**: `/v1/audio/speech` with similar request structure and behavior.\n- **Supported Voices**: Maps OpenAI voices (alloy, echo, fable, onyx, nova, shimmer) to `edge-tts` equivalents.\n- **Flexible Formats**: Supports multiple audio formats (mp3, opus, aac, flac, wav, pcm).\n- **Adjustable Speed**: Option to modify playback speed (0.25x to 4.0x).\n- **Optional Direct Edge-TTS Voice Selection**: Use either OpenAI voice mappings or specify any edge-tts voice directly.\n\n## Getting Started\n\n### Prerequisites\n\n- **Docker** (recommended): Docker and Docker Compose for containerized setup.\n- **Python** (optional): For local development, install dependencies in `requirements.txt`.\n- **ffmpeg** (optional): Required for audio format conversion. Optional if sticking to mp3.\n\n### Installation\n\n1. **Clone the Repository**:\n```bash\ngit clone https://github.com/travisvn/openai-edge-tts.git\ncd openai-edge-tts\n```\n\n2. **Environment Variables**: Create a `.env` file in the root directory with the following variables:\n```\nAPI_KEY=your_api_key_here\nPORT=5050\n\nDEFAULT_VOICE=en-US-AvaNeural\nDEFAULT_RESPONSE_FORMAT=mp3\nDEFAULT_SPEED=1.0\n\nDEFAULT_LANGUAGE=en-US\n\nREQUIRE_API_KEY=True\nREMOVE_FILTER=False\nEXPAND_API=True\n```\n\nOr, copy the default `.env.example` with the following:\n```bash\ncp .env.example .env\n```\n\n3. **Run with Docker Compose** (recommended):\n\n```bash\ndocker compose up --build\n```\n_(Note: docker-compose is not the same as docker compose)_\n\nRun with `-d` to run docker compose in \"detached mode\", meaning it will run in the background and free up your terminal.\n\n```bash\ndocker compose up -d\n```\n\nAlternatively, **run directly with Docker**:\n```bash\ndocker build -t openai-edge-tts .\ndocker run -p 5050:5050 --env-file .env openai-edge-tts\n```\n\nTo run the container in the background, add `-d` after the `docker run` command:\n\n```bash\ndocker run -d -p 5050:5050 --env-file .env openai-edge-tts\n```\n\n4. **Access the API**: Your server will be accessible at `http://localhost:5050`.\n\n## Running with Python\n\nIf you prefer to run this project directly with Python, follow these steps to set up a virtual environment, install dependencies, and start the server.\n\n### 1. Clone the Repository\n\n```bash\ngit clone https://github.com/travisvn/openai-edge-tts.git\ncd openai-edge-tts\n```\n\n### 2. Set Up a Virtual Environment\n\nCreate and activate a virtual environment to isolate dependencies:\n\n```bash\n# For macOS/Linux\npython3 -m venv venv\nsource venv/bin/activate\n\n# For Windows\npython -m venv venv\nvenv\\Scripts\\activate\n```\n\n### 3. Install Dependencies\n\nUse `pip` to install the required packages listed in `requirements.txt`:\n\n```bash\npip install -r requirements.txt\n```\n\n### 4. Configure Environment Variables\n\nCreate a `.env` file in the root directory and set the following variables:\n\n```plaintext\nAPI_KEY=your_api_key_here\nPORT=5050\n\nDEFAULT_VOICE=en-US-AvaNeural\nDEFAULT_RESPONSE_FORMAT=mp3\nDEFAULT_SPEED=1.0\n\nDEFAULT_LANGUAGE=en-US\n\nREQUIRE_API_KEY=True\nREMOVE_FILTER=False\nEXPAND_API=True\n```\n\n### 5. Run the Server\n\nOnce configured, start the server with:\n\n```bash\npython app/server.py\n```\n\nThe server will start running at `http://localhost:5050`.\n\n### 6. Test the API\n\nYou can now interact with the API at `http://localhost:5050/v1/audio/speech` and other available endpoints. See the [Usage](#usage) section for request examples.\n    \n\n### Usage\n\n#### Endpoint: `/v1/audio/speech`\n\nGenerates audio from the input text. Available parameters:\n\n**Required Parameter:**\n\n- **input** (string): The text to be converted to audio (up to 4096 characters).\n\n**Optional Parameters:**\n\n- **model** (string): Set to \"tts-1\" or \"tts-1-hd\" (default: `\"tts-1\"`).\n- **voice** (string): One of the OpenAI-compatible voices (alloy, echo, fable, onyx, nova, shimmer) or any valid `edge-tts` voice (default: `\"en-US-AvaNeural\"`).\n- **response_format** (string): Audio format. Options: `mp3`, `opus`, `aac`, `flac`, `wav`, `pcm` (default: `mp3`).\n- **speed** (number): Playback speed (0.25 to 4.0). Default is `1.0`.\n\nExample request with `curl` and saving the output to an mp3 file:\n\n```bash\ncurl -X POST http://localhost:5050/v1/audio/speech \\\n  -H \"Content-Type: application/json\" \\\n  -H \"Authorization: Bearer your_api_key_here\" \\\n  -d '{\n    \"input\": \"Hello, I am your AI assistant! Just let me know how I can help bring your ideas to life.\",\n    \"voice\": \"echo\",\n    \"response_format\": \"mp3\",\n    \"speed\": 1.1\n  }' \\\n  --output speech.mp3\n```\n\nOr, to be in line with the OpenAI API endpoint parameters:\n\n```bash\ncurl -X POST http://localhost:5050/v1/audio/speech \\\n  -H \"Content-Type: application/json\" \\\n  -H \"Authorization: Bearer your_api_key_here\" \\\n  -d '{\n    \"model\": \"tts-1\",\n    \"input\": \"Hello, I am your AI assistant! Just let me know how I can help bring your ideas to life.\",\n    \"voice\": \"alloy\"\n  }' \\\n  --output speech.mp3\n```\n\nAnd an example of a language other than English:\n\n```bash\ncurl -X POST http://localhost:5050/v1/audio/speech \\\n  -H \"Content-Type: application/json\" \\\n  -H \"Authorization: Bearer your_api_key_here\" \\\n  -d '{\n    \"model\": \"tts-1\",\n    \"input\": \"じゃあ、行く。電車の時間、調べておくよ。\",\n    \"voice\": \"ja-JP-KeitaNeural\"\n  }' \\\n  --output speech.mp3\n```\n\n### Additional Endpoints\n\n- **POST/GET /v1/models**: Lists available TTS models.\n- **POST/GET /v1/voices**: Lists `edge-tts` voices for a given language / locale.\n- **POST/GET /v1/voices/all**: Lists all `edge-tts` voices, with language support information.\n\n### Contributing\n\nContributions are welcome! Please fork the repository and create a pull request for any improvements.\n\n### License\n\nThis project is licensed under GNU General Public License v3.0 (GPL-3.0), and the acceptable use-case is intended to be personal use. For enterprise or non-personal use of `openai-edge-tts`, contact me at tts@travisvn.com\n\n___\n\n## Example Use Case \n\n\u003e [!TIP]\n\u003e Swap `localhost` to your local IP (ex. `192.168.0.1`) if you have issues\n\u003e \n\u003e _It may be the case that, when accessing this endpoint on a different server / computer or when the call is made from another source (like Open WebUI), you need to change the URL from `localhost` to your local IP (something like `192.168.0.1` or similar)_\n\n# Open WebUI\n\nOpen up the Admin Panel and go to Settings -\u003e Audio\n\nBelow, you can see a screenshot of the correct configuration for using this project to substitute the OpenAI endpoint\n\n![Screenshot of Open WebUI Admin Settings for Audio adding the correct endpoints for this project](https://utfs.io/f/MMMHiQ1TQaBo9GgL4WcUbjSRlqi86sV3TXh47KYBJCkdQ20M)\n\nIf you're running both Open WebUI and this project in Docker, the API endpoint URL is probably `http://host.docker.internal:5050/v1`\n\n\u003e [!NOTE]\n\u003e View the official docs for [Open WebUI integration with OpenAI Edge TTS](https://docs.openwebui.com/tutorials/text-to-speech/openai-edge-tts-integration)\n\n# AnythingLLM\n\nIn version 1.6.8, AnythingLLM added support for \"generic OpenAI TTS providers\" — meaning we can use this project as the TTS provider in AnythingLLM\n\nOpen up settings and go to Voice \u0026 Speech (Under AI Providers)\n\nBelow, you can see a screenshot of the correct configuration for using this project to substitute the OpenAI endpoint\n\n![Screenshot of AnythingLLM settings for Voice adding the correct endpoints for this project](https://utfs.io/f/MMMHiQ1TQaBoGx6WUTRDJUWPLqoMsXiNkajAdVOwgcxH6uv7)\n\n___\n\n\n## Quick Info\n\n- `your_api_key_here` never needs to be replaced — No \"real\" API key is required. Use whichever string you'd like.\n- The quickest way to get this up and running is to install docker and run the command below:\n```bash\ndocker run -d -p 5050:5050 -e API_KEY=your_api_key_here -e PORT=5050 travisvn/openai-edge-tts:latest\n```\n\n___\n\n# Voice Samples 🎙️\n[Play voice samples and see all available Edge TTS voices](https://tts.travisvn.com/)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftravisvn%2Fopenai-edge-tts","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftravisvn%2Fopenai-edge-tts","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftravisvn%2Fopenai-edge-tts/lists"}