For the Chinese version of this document, please refer to 简体中文.
This project provides a RESTful API for converting text to speech using Microsoft's Azure Cognitive Services. The service is built using Flask and can be containerized using Docker.
- Convert text to speech using Microsoft Azure Cognitive Services.
- Specify voice model, speech style, and speech rate.
- Containerized using Docker for easy deployment.
- Configurable using environment variables.
- Logs are available for monitoring and debugging.
- Python 3.10
- Docker
- Azure Cognitive Services subscription key and region
-
Clone the repository:
git clone https://github.com/zhufengme/azure-tts-service.git cd azure-tts-service
-
Install dependencies (for local development):
pip install Flask requests
Set the following environment variables:
AZURE_SUBSCRIPTION_KEY
: Your Azure subscription key.AZURE_REGION
: Your Azure region.
-
Set environment variables:
export AZURE_SUBSCRIPTION_KEY=your_azure_subscription_key export AZURE_REGION=your_azure_region
-
Run the Flask application:
python app.py
-
Build the Docker image:
docker build -t azure-tts-service .
-
Run the Docker container:
docker run -d -p 5000:5000 --name azure-tts-service -e AZURE_SUBSCRIPTION_KEY=your_azure_subscription_key -e AZURE_REGION=your_azure_region azure-tts-service
You can pull the Docker image from DockerHub and run it directly.
-
Pull the Docker image:
docker pull andiezhu/azure-tts-service
-
Run the Docker container:
docker run -d -p 5000:5000 --name azure-tts-service -e AZURE_SUBSCRIPTION_KEY=your_azure_subscription_key -e AZURE_REGION=your_azure_region andiezhu/azure-tts-service
POST /tts
text
(string, required): The text to be converted to speech.voice_name
(string, optional): The voice model to be used. Default isen-US-AriaNeural
.style
(string, optional): The speech style to be used. Default isgeneral
.rate
(string, optional): The speech rate. Default is0%
.
curl -X POST http://localhost:5000/tts \
-H "Content-Type: application/json" \
-d '{
"text": "Hello, this is a test of Microsoft Text to Speech service.",
"voice_name": "en-US-AriaNeural",
"style": "cheerful",
"rate": "10%"
}' --output output.wav
The service provides a health check endpoint:
GET /health
curl http://localhost:5000/health
Logs are available for monitoring and debugging. By default, logs are written to both the console and a file named app.log
.
To view logs, you can use the docker logs
command:
docker logs -f azure-tts-service
If you configured logging to a file, you can view the logs using:
tail -f app.log
This project is licensed under the MIT License - see the LICENSE file for details.