Lightweight Docker image for generating waveform JSON from audio, intended for web applications.
1.2K
This Docker image integrates the BBC's audiowaveform tool with a Flask server for generating waveform JSON data from audio files (MP3, WAV, etc.) based on Alpine. It supports passing parameters like resolution and bit depth dynamically via an API, ideal for use with applications such as WordPress plugins.
-z) and bit depth (-b) through API requests.To run the Flask API for generating waveforms, execute the following command:
bash
docker run -p 5000:5000 d9media/audiowaveform-server:latest
This will expose the API on port 5000.
curl -X POST http://localhost:5000/generate_waveform \
-F "file=@/path/to/your/audiofile.mp3" \
-F "resolution=4096" \
-F "bit_depth=8"
Replace /path/to/your/audiofile.mp3 with the actual path to your audio file.
<?php
$url = 'http://localhost:5000/generate_waveform';
// Prepare the file and data to be sent
$file = '/path/to/your/audiofile.mp3';
$fields = array(
'resolution' => '4096',
'bit_depth' => '8',
'file' => new CURLFile($file)
);
// Initialize curl
$ch = curl_init($url);
// Set curl options
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
// Execute the request
$response = curl_exec($ch);
// Check for errors
if ($response === false) {
$error = curl_error($ch);
curl_close($ch);
die('Curl error: ' . $error);
}
// Close curl
curl_close($ch);
// Decode the JSON response
$responseData = json_decode($response, true);
if ($responseData['status'] == 'success') {
// Extract the waveform_data
$waveformData = $responseData['waveform_data'];
// Save the waveform_data to a JSON file
$outputFile = 'waveform_data.json';
file_put_contents($outputFile, json_encode($waveformData, JSON_PRETTY_PRINT));
echo "Waveform data saved to $outputFile\n";
} else {
// Handle the error in the response
echo "Error: " . $responseData['message'] . "\n";
}
?>
Make sure to replace /path/to/your/audiofile.mp3 with the actual file path.
new CURLFile($file).json_decode().waveform_data is extracted and saved to a file named waveform_data.json using file_put_contents().This script will create a file called waveform_data.json in the current working directory, containing the waveform data in a structured JSON format.
Content type
Image
Digest
sha256:16ed3ac1d…
Size
216.9 MB
Last updated
about 2 years ago
docker pull d9media/audiowaveform-server