Evolution Audio Converter
This project is a microservice in Go that processes audio files, converts them to opus or mp3 format, and returns both the duration of the audio and the converted file in base64. The service accepts audio files sent as form-data, base64, or URL.
Requirements
Before starting, you'll need to have the following installed:
- Go (version 1.21 or higher)
- Docker (to run the project in a container)
- FFmpeg (for audio processing)
Installation
Clone the Repository
Clone this repository to your local machine:
git clone https://github.com/EvolutionAPI/evolution-audio-converter.git
cd evolution-audio-converter
Install Dependencies
Install the project dependencies:
go mod tidy
Install FFmpeg
The service depends on FFmpeg to convert the audio. Make sure FFmpeg is installed on your system.
-
On Ubuntu:
sudo apt update sudo apt install ffmpeg -
On macOS (via Homebrew):
brew install ffmpeg -
On Windows, download FFmpeg here and add it to your system
PATH.
Configuration
Create a .env file in the project's root directory with the following configuration:
PORT=4040
API_KEY=your_secret_api_key_here
This defines the port where the service will run.
Running the Project
Locally
To run the service locally, use the following command:
go run main.go -dev
The server will be available at http://localhost:4040.
Using Docker
If you prefer to run the service in a Docker container, follow the steps below:
-
Build the Docker image:
docker build -t audio-service . -
Run the container:
docker run -p 4040:4040 --env-file=.env audio-serviceThis will start the container on the port specified in the
.envfile.
How to Use
You can send POST requests to the /process-audio endpoint with an audio file in the following formats:
- Form-data (to upload files)
- Base64 (to send the audio encoded in base64)
- URL (to send the link to the audio file)
Authentication
All requests must include the apikey header with the value of the API_KEY configured in the .env file.
Optional Parameters
format: You can specify the format for conversion by passing theformatparameter in the request. Supported values:mp3ogg(default)
Example Requests Using cURL
Sending as Form-data
curl -X POST -F "file=@path/to/audio.mp3" http://localhost:4040/process-audio \
-F "format=ogg" \
-H "apikey: your_secret_api_key_here"
Sending as Base64
curl -X POST -d "base64=$(base64 path/to/audio.mp3)" http://localhost:4040/process-audio \
-d "format=ogg" \
-H "apikey: your_secret_api_key_here"
Sending as URL
curl -X POST -d "url=https://example.com/path/to/audio.mp3" http://localhost:4040/process-audio \
-d "format=ogg" \
-H "apikey: your_secret_api_key_here"
Response
The response will be a JSON object containing the audio duration and the converted audio file in base64:
{
"duration": 120,
"audio": "UklGR... (base64 of the file)",
"format": "ogg"
}
duration: The audio duration in seconds.audio: The converted audio file encoded in base64.format: The format of the converted file (mp3orogg).
License
This project is licensed under the MIT license.