Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

An audio converter api

NotificationsYou must be signed in to change notification settings

rcarubbi/Carubbi-AudioConverter-Api

Repository files navigation

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.

Features

  • Audio Format Conversion:
    • Supported conversions:
      • MP3 ↔ WAV
      • WAV ↔ OGG
      • MP3 ↔ OGG (via pipeline)
  • File Validation:
    • Ensures valid file extensions (.mp3,.wav,.ogg).
    • Validates file size limits.
    • Uses file signatures (magic numbers) to confirm file authenticity.
  • Extensibility:
    • Easily add new audio formats by implementing theIConverter interface.
  • Integration with External Tools:
    • Utilizesopusenc andopusdec for OGG encoding/decoding.
    • LeveragesNAudio andNAudio.Lame for MP3 and WAV processing.

Requirements

  • .NET 7.0
  • opusenc.exe andopusdec.exe available in the environment's PATH (for OGG conversions).
  • NAudio and NAudio.Lame libraries installed.

Installation

  1. Clone the repository:

    git clone https://github.com/rcarubbi/Carubbi-AudioConverter-Api.gitcd Carubbi-AudioConverter-Api
  2. Install dependencies:

    • Ensure that theNAudio andNAudio.Lame packages are installed:
      dotnet add package NAudiodotnet add package NAudio.Lame
    • Add theopusenc.exe andopusdec.exe binaries to your PATH environment variable.
  3. Run the API:

    dotnet run
  4. Access the Swagger UI:

    • Navigate tohttps://localhost:<port>/swagger to test the API endpoints interactively.

API Endpoints

POST /Conversion

Converts an uploaded audio file to the desired format.

Request

  • Query Parameter:
    • to: The desired output format (mp3,wav, orogg).
  • Form Data:
    • source: The audio file to convert.

Response

  • Success: Returns the converted audio file as a binary stream.
  • Error: Provides a detailed error message if validation or conversion fails.

Example

curl -X POST"https://localhost:<port>/Conversion?to=ogg" \    -H"Content-Type: multipart/form-data" \    -F"source=@example.mp3" \    --output result.ogg

How It Works

File Validation

Each uploaded file goes through a validation process:

  1. File Size: Ensures the file does not exceed the configured size limit.
  2. Extension Check: Validates if the file extension is supported.
  3. File Signature: Confirms the authenticity of the file using magic numbers.

Conversion Pipeline

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:
    1. MP3 → WAV (usingNAudio.Wave).
    2. WAV → OGG (usingopusenc).

Integration with External Tools

  • Opusenc/Opusdec: Handles OGG encoding/decoding using process execution.
  • NAudio: Manages MP3 and WAV processing directly in memory.

Adding New Formats

To add a new format:

  1. Implement theIConverter interface:

    publicclassNewFormatConverter:IConverter{publicstringFrom=>"existingFormat";publicstringTo=>"newFormat";publicasyncTask<byte[]>ConvertAsync(byte[]content){// Conversion logic here}}
  2. Register the converter inStartup.cs:

    services.AddTransient<IConverter,NewFormatConverter>();

Tools and Libraries Used

  • ASP.NET Core: For API implementation.
  • NAudio: For MP3 and WAV processing.
  • NAudio.Lame: For MP3 encoding.
  • Opusenc/Opusdec: For OGG encoding and decoding.

Contributing

Contributions are welcome! Please fork the repository, create a new branch, and submit a pull request.


License

This project is licensed under the MIT License. See theLICENSE file for more details.


Project Link

Check out the repository:Carubbi Audio Converter API

About

An audio converter api

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp