Carubbi Audio Converter API is a modular and secure API built with ASP.NET Core to convert audio files between popular formats such as MP3, WAV, and OGG. The API ensures file validation, efficient processing, and extensibility for future formats.
- Audio Format Conversion:
- Supported conversions:
- MP3 ↔ WAV
- WAV ↔ OGG
- MP3 ↔ OGG (via pipeline)
- Supported conversions:
- File Validation:
- Ensures valid file extensions (
.mp3
,.wav
,.ogg
). - Validates file size limits.
- Uses file signatures (magic numbers) to confirm file authenticity.
- Ensures valid file extensions (
- Extensibility:
- Easily add new audio formats by implementing the
IConverter
interface.
- Easily add new audio formats by implementing the
- Integration with External Tools:
- Utilizes
opusenc
andopusdec
for OGG encoding/decoding. - Leverages
NAudio
andNAudio.Lame
for MP3 and WAV processing.
- Utilizes
- .NET 7.0
opusenc.exe
andopusdec.exe
available in the environment's PATH (for OGG conversions).- NAudio and NAudio.Lame libraries installed.
-
Clone the repository:
git clone https://github.com/rcarubbi/Carubbi-AudioConverter-Api.git cd Carubbi-AudioConverter-Api
-
Install dependencies:
- Ensure that the
NAudio
andNAudio.Lame
packages are installed:dotnet add package NAudio dotnet add package NAudio.Lame
- Add the
opusenc.exe
andopusdec.exe
binaries to your PATH environment variable.
- Ensure that the
-
Run the API:
dotnet run
-
Access the Swagger UI:
- Navigate to
https://localhost:<port>/swagger
to test the API endpoints interactively.
- Navigate to
Converts an uploaded audio file to the desired format.
- Query Parameter:
to
: The desired output format (mp3
,wav
, orogg
).
- Form Data:
source
: The audio file to convert.
- Success: Returns the converted audio file as a binary stream.
- Error: Provides a detailed error message if validation or conversion fails.
curl -X POST "https://localhost:<port>/Conversion?to=ogg" \
-H "Content-Type: multipart/form-data" \
-F "source=@example.mp3" \
--output result.ogg
Each uploaded file goes through a validation process:
- File Size: Ensures the file does not exceed the configured size limit.
- Extension Check: Validates if the file extension is supported.
- File Signature: Confirms the authenticity of the file using magic numbers.
The API uses a modular pipeline approach for audio conversion. It determines the necessary converters based on input and output formats and chains them together when intermediate steps are needed (e.g., MP3 → WAV → OGG).
- Example: Conversion from MP3 to OGG:
- MP3 → WAV (using
NAudio.Wave
). - WAV → OGG (using
opusenc
).
- MP3 → WAV (using
- Opusenc/Opusdec: Handles OGG encoding/decoding using process execution.
- NAudio: Manages MP3 and WAV processing directly in memory.
To add a new format:
-
Implement the
IConverter
interface:public class NewFormatConverter : IConverter { public string From => "existingFormat"; public string To => "newFormat"; public async Task<byte[]> ConvertAsync(byte[] content) { // Conversion logic here } }
-
Register the converter in
Startup.cs
:services.AddTransient<IConverter, NewFormatConverter>();
- ASP.NET Core: For API implementation.
- NAudio: For MP3 and WAV processing.
- NAudio.Lame: For MP3 encoding.
- Opusenc/Opusdec: For OGG encoding and decoding.
Contributions are welcome! Please fork the repository, create a new branch, and submit a pull request.
This project is licensed under the MIT License. See the LICENSE file for more details.
Check out the repository: Carubbi Audio Converter API