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.
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)
Clone this repository to your local machine:
git clone https://github.com/EvolutionAPI/evolution-audio-converter.git
cd evolution-audio-converter
Install the project dependencies:
go mod tidy
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
.
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.
To run the service locally, use the following command:
go run main.go -dev
The server will be available at http://localhost:4040
.
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-service
This will start the container on the port specified in the
.env
file.
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)
All requests must include the apikey
header with the value of the API_KEY
configured in the .env
file.
format
: You can specify the format for conversion by passing theformat
parameter in the request. Supported values:mp3
ogg
(default)
curl -X POST -F "file=@path/to/audio.mp3" http://localhost:4040/process-audio \
-F "format=ogg" \
-H "apikey: your_secret_api_key_here"
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"
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"
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 (mp3
orogg
).
This project is licensed under the MIT license.