Cloudinary Blog
How to Generate Waveform Images From Audio Files

Nowadays, users can and often upload various media files to social networks, websites, and messaging apps. Most of those media are images and videos, with a significant number being audio files. Subsequently, to create a thumbnail to depict an image, a site or app would crop and then resize it to scale. To depict a video, they would convert, crop, and resize a single frame from it as a thumbnail.

But how do you portray audio? An ideal way is with a waveform image, aka soundwave image, which, as a visual representation of audio, is displayed as a graph of the sound amplitude against time.


Sign up for Cloudinary free today!


Creating Waveform Images

Cloudinary's media-management capabilities enable you to upload, transform, and manage media, including images, videos, and audio. You can create waveform thumbnails—on the fly—for audio just as easily as you can for images and videos, and then fine-tune the thumbnails to match the graphic design and responsive layouts of all devices and browsers. You do all that through Cloudinary’s dynamic URLs with no need for other software. In fact, Cloudinary is a superb waveform generator.

Creating a waveform image for an audio file you’ve uploaded to your Cloudinary account takes only two steps:

  1. Change the file extension (format) of the audio’s delivery URL on Cloudinary to an image-centric format, such as PNG.
  2. Enable the waveform flag by adding fl_waveform to the URL.

By default, Cloudinary delivers the generated waveform image with a high resolution, saving you the manual step of scaling it down.

Below is an example of a PNG waveform image of an audio file called bumblebee.mp3, which has been uploaded to Cloudinary's demo account, scaled to a height of 200 pixels and a width of 500 pixels:

Ruby:
Copy to clipboard
cl_image_tag("bumblebee.png", :height=>200, :width=>500, :flags=>"waveform", :resource_type=>"video")
PHP v1:
Copy to clipboard
cl_image_tag("bumblebee.png", array("height"=>200, "width"=>500, "flags"=>"waveform", "resource_type"=>"video"))
PHP v2:
Copy to clipboard
(new ImageTag('bumblebee.png'))
  ->resize(Resize::scale()->width(500)->height(200))
  ->addFlag(Flag::waveform())
  ->assetType(AssetType::VIDEO);
Python:
Copy to clipboard
CloudinaryVideo("bumblebee.png").image(height=200, width=500, flags="waveform")
Node.js:
Copy to clipboard
cloudinary.image("bumblebee.png", {height: 200, width: 500, flags: "waveform", resource_type: "video"})
Java:
Copy to clipboard
cloudinary.url().transformation(new Transformation().height(200).width(500).flags("waveform")).resourceType("video").imageTag("bumblebee.png");
JS:
Copy to clipboard
cloudinary.videoTag('bumblebee.png', {height: 200, width: 500, flags: "waveform"}).toHtml();
jQuery:
Copy to clipboard
$.cloudinary.image("bumblebee.png", {height: 200, width: 500, flags: "waveform", resource_type: "video"})
React:
Copy to clipboard
<Video publicId="bumblebee.png" resourceType="video">
  <Transformation height="200" width="500" flags="waveform" />
</Video>
Vue.js:
Copy to clipboard
<cld-video publicId="bumblebee.png" resourceType="video">
  <cld-transformation height="200" width="500" flags="waveform" />
</cld-video>
Angular:
Copy to clipboard
<cl-video public-id="bumblebee.png" resource-type="video">
  <cl-transformation height="200" width="500" flags="waveform">
  </cl-transformation>
</cl-video>
.NET:
Copy to clipboard
cloudinary.Api.UrlVideoUp.Transform(new Transformation().Height(200).Width(500).Flags("waveform")).BuildImageTag("bumblebee.png")
Android:
Copy to clipboard
MediaManager.get().url().transformation(new Transformation().height(200).width(500).flags("waveform")).resourceType("video").generate("bumblebee.png");
iOS:
Copy to clipboard
cloudinary.createUrl().setResourceType("video").setTransformation(CLDTransformation().setHeight(200).setWidth(500).setFlags("waveform")).generate("bumblebee.png")
Audio Waveform Image of 500x200

You can also create waveform images from a video’s audio track in the same way: simply change the file extension of the video’s Cloudinary URL to an image format like PNG and then add fl_waveform to the URL.

Customizing Waveform Images

You can tailor the characteristics of generated waveform images, too:

  • Colors. Add the co (color) parameter to the URL to set the waveform color, whose default is white (white). To change the default background color, which is black, add the b (background) parameter to the URL.

    Below is the same PNG waveform image with a waveform in black on a white background::

    Ruby:
    Copy to clipboard
    cl_image_tag("bumblebee.png", :height=>200, :width=>500, :flags=>"waveform", :color=>"black", :background=>"white", :resource_type=>"video")
    PHP v1:
    Copy to clipboard
    cl_image_tag("bumblebee.png", array("height"=>200, "width"=>500, "flags"=>"waveform", "color"=>"black", "background"=>"white", "resource_type"=>"video"))
    PHP v2:
    Copy to clipboard
    (new ImageTag('bumblebee.png'))
      ->resize(Resize::scale()->width(500)->height(200))
      ->backgroundColor(Color::WHITE)->color(Color::BLACK)
      ->addFlag(Flag::waveform())
      ->assetType(AssetType::VIDEO);
    Python:
    Copy to clipboard
    CloudinaryVideo("bumblebee.png").image(height=200, width=500, flags="waveform", color="black", background="white")
    Node.js:
    Copy to clipboard
    cloudinary.image("bumblebee.png", {height: 200, width: 500, flags: "waveform", color: "black", background: "white", resource_type: "video"})
    Java:
    Copy to clipboard
    cloudinary.url().transformation(new Transformation().height(200).width(500).flags("waveform").color("black").background("white")).resourceType("video").imageTag("bumblebee.png");
    JS:
    Copy to clipboard
    cloudinary.videoTag('bumblebee.png', {height: 200, width: 500, flags: "waveform", color: "black", background: "white"}).toHtml();
    jQuery:
    Copy to clipboard
    $.cloudinary.image("bumblebee.png", {height: 200, width: 500, flags: "waveform", color: "black", background: "white", resource_type: "video"})
    React:
    Copy to clipboard
    <Video publicId="bumblebee.png" resourceType="video">
      <Transformation height="200" width="500" flags="waveform" color="black" background="white" />
    </Video>
    Vue.js:
    Copy to clipboard
    <cld-video publicId="bumblebee.png" resourceType="video">
      <cld-transformation height="200" width="500" flags="waveform" color="black" background="white" />
    </cld-video>
    Angular:
    Copy to clipboard
    <cl-video public-id="bumblebee.png" resource-type="video">
      <cl-transformation height="200" width="500" flags="waveform" color="black" background="white">
      </cl-transformation>
    </cl-video>
    .NET:
    Copy to clipboard
    cloudinary.Api.UrlVideoUp.Transform(new Transformation().Height(200).Width(500).Flags("waveform").Color("black").Background("white")).BuildImageTag("bumblebee.png")
    Android:
    Copy to clipboard
    MediaManager.get().url().transformation(new Transformation().height(200).width(500).flags("waveform").color("black").background("white")).resourceType("video").generate("bumblebee.png");
    iOS:
    Copy to clipboard
    cloudinary.createUrl().setResourceType("video").setTransformation(CLDTransformation().setHeight(200).setWidth(500).setFlags("waveform").setColor("black").setBackground("white")).generate("bumblebee.png")
    Black-on-White Waveform Image

  • Waveform segments. To capture a waveform segment of an audio, add these three parameters:

    • start_offset: Add the so parameter to the URL to denote the start.
    • end_offset: Add the eo parameter to the URL to denote the end.
    • duration: Add the du parameter to the URL to denote the duration.

Below is an edited PNG waveform image of the bumblebee.mp3 audio. The waveform is blue on a green background with a duration between two-second mark and the four-second mark, scaled to a height of 250 pixels and a width of 400 pixels:

Ruby:
Copy to clipboard
cl_image_tag("bumblebee.png", :height=>250, :width=>400, :flags=>"waveform", :start_offset=>"2", :end_offset=>"4", :color=>"blue", :background=>"#02b30a", :resource_type=>"video")
PHP v1:
Copy to clipboard
cl_image_tag("bumblebee.png", array("height"=>250, "width"=>400, "flags"=>"waveform", "start_offset"=>"2", "end_offset"=>"4", "color"=>"blue", "background"=>"#02b30a", "resource_type"=>"video"))
PHP v2:
Copy to clipboard
(new ImageTag('bumblebee.png'))
  ->videoEdit(VideoEdit::trim()->startOffset(2)->endOffset(4))
  ->resize(Resize::scale()->width(400)->height(250))
  ->backgroundColor(Color::rgb('02b30a'))
  ->color(Color::BLUE)->addFlag(Flag::waveform())
  ->assetType(AssetType::VIDEO);
Python:
Copy to clipboard
CloudinaryVideo("bumblebee.png").image(height=250, width=400, flags="waveform", start_offset="2", end_offset="4", color="blue", background="#02b30a")
Node.js:
Copy to clipboard
cloudinary.image("bumblebee.png", {height: 250, width: 400, flags: "waveform", start_offset: "2", end_offset: "4", color: "blue", background: "#02b30a", resource_type: "video"})
Java:
Copy to clipboard
cloudinary.url().transformation(new Transformation().height(250).width(400).flags("waveform").startOffset("2").endOffset("4").color("blue").background("#02b30a")).resourceType("video").imageTag("bumblebee.png");
JS:
Copy to clipboard
cloudinary.videoTag('bumblebee.png', {height: 250, width: 400, flags: "waveform", startOffset: "2", endOffset: "4", color: "blue", background: "#02b30a"}).toHtml();
jQuery:
Copy to clipboard
$.cloudinary.image("bumblebee.png", {height: 250, width: 400, flags: "waveform", start_offset: "2", end_offset: "4", color: "blue", background: "#02b30a", resource_type: "video"})
React:
Copy to clipboard
<Video publicId="bumblebee.png" resourceType="video">
  <Transformation height="250" width="400" flags="waveform" startOffset="2" endOffset="4" color="blue" background="#02b30a" />
</Video>
Vue.js:
Copy to clipboard
<cld-video publicId="bumblebee.png" resourceType="video">
  <cld-transformation height="250" width="400" flags="waveform" startOffset="2" endOffset="4" color="blue" background="#02b30a" />
</cld-video>
Angular:
Copy to clipboard
<cl-video public-id="bumblebee.png" resource-type="video">
  <cl-transformation height="250" width="400" flags="waveform" start-offset="2" end-offset="4" color="blue" background="#02b30a">
  </cl-transformation>
</cl-video>
.NET:
Copy to clipboard
cloudinary.Api.UrlVideoUp.Transform(new Transformation().Height(250).Width(400).Flags("waveform").StartOffset("2").EndOffset("4").Color("blue").Background("#02b30a")).BuildImageTag("bumblebee.png")
Android:
Copy to clipboard
MediaManager.get().url().transformation(new Transformation().height(250).width(400).flags("waveform").startOffset("2").endOffset("4").color("blue").background("#02b30a")).resourceType("video").generate("bumblebee.png");
iOS:
Copy to clipboard
cloudinary.createUrl().setResourceType("video").setTransformation(CLDTransformation().setHeight(250).setWidth(400).setFlags("waveform").setStartOffset("2").setEndOffset("4").setColor("blue").setBackground("#02b30a")).generate("bumblebee.png")
Waveform of a Partial Audio Cut With Customized Colors

Creating Visual Depiction Uploaded Media

As an appealing visual depiction of audio files, waveform images work well for user-generated content, social networks, and social-messaging apps. You’ve now learned how to produce those images on Cloudinary, which also offers automated capabilities for optimizing and delivering them through fast content delivery networks (CDNs).

Remember that you can transform generated thumbnails for audio, as well as for images and videos, to match any graphic design and any responsive layout, as long as those media have been uploaded to your Cloudinary account’s media library.

In all its subscription plans, including the free tier, Cloudinary offers full support for audio, including upload, transformation, streaming, and generation of waveforms. Try it out yourself by first opening a free account.


Want to Learn More About Video Optimization?

Recent Blog Posts

Create Lightweight Sites With Low-Code and No-Code Technology

Consumers expect modern websites to be mainly visual. But, the more compelling and complex the related media is, the more data is involved, compounding the site’s weight. In today’s content-craving world, delivering unoptimized media can cost you because it leads to sluggish page loads, resulting in visitors abandoning your site in search of a faster alternative. In fact, a page load that takes more than three seconds can cause as many as 40% of your visitors to bounce. Given this competitive, digital-first environment, you can’t afford to lose page views, for time is of the essence.

Read more
A Blueprint for AWS-Secured Webhook Listeners for Cloudinary

tl;dr: An AWS-secured and optimized Cloudinary webhook listener for extending the Cloudinary service

Code: Github

A webhook is a communication medium for sending notifications from one platform to another about events that occurred. In place are user-defined HTTP callbacks that are triggered by specific events. When a triggered event takes place on the source site, the webhook listens to the event, collects the data, and sends it to the URL you specified in the form of an HTTP request.

Read more
New Accessibility Features for Cloudinary’s Product Gallery Widget

Cloudinary’s Product Gallery widget, which launched in 2019, has enabled many brands to effectively and efficiently showcase their products in a sleek and captivating manner, saving countless hours of development time and accelerating release cycles. By adding Cloudinary’s Product Gallery widget with its customizable UI to their product page, retailers reap numerous benefits, often turning visitors into customers in short order.

Read more
Why Successful Businesses Engage With and Convert Audiences With Visual Media

Most business buyers prefer to research purchase options online, as do many shoppers. No wonder online retail sales in the U.S. rose by 32.4% in 2020—an impressive gain of $105 billion.

For B2B and B2C businesses, text-heavy websites are no longer adequate in attracting shoppers. Instead, engaging visual media—spin images, videos, 3D models, augmented reality—are becoming a must for conveying eye-catching details and differentiators about products or services.

Read more
Making User-Generated Content (UGC) Shoppable With Cloudinary

User-generated content (UGC) is a powerful marketing tool. Not only does video complement marketing efforts for e-commerce by enabling customers to explore products in greater detail, but UGC also adds an element of trust. As a bonus, user-generated video is an exceptional opportunity for e-businesses to attract website traffic without their marketing team having to create promotional videos from scratch. User-generated content drives conversions and brand loyalty as a direct result of authentic interaction.

Read more