AudioRecordView

AudioRecordView

Real-time audio visualizer for android

I am pleased to present to you my work, which I did about three years ago. As I've faced with the problems of drawing real waveforms while recording sound, so I've planned to create something to provide the simplest way to do it.

At that time I was looking for a suitable library for my task and I found libraries that draw amplitudes in real-time, but almost every library had two big problems: a fixed interface and not flexible for use. Finally, I decided to write my own flexible custom view.

What are the advantages of this library?

Benefits:

  • The library is easy to use

  • Small and clear code

  • Support to use in both: code and XML

  • Active support and improvements

What do we mean when we say flexible? You can

  • Choose one of two types of alignment mode: "bottom" and "center"

  • Change the color of the chunks

  • Set minimum/maximum height of chunks

  • Change the width of chunks

  • Change space between two chunks.

  • Set the mode of rounded corners

  • Enable/disable "Soft Transition" mode

  • Control drawing speed

Setup AudioRecordView

In your application project (or root project if you prefer) build.gradle,make sure you have jcenter repository added:

allprojects {
    repositories {
        ...
        maven { url 'https://jitpack.io' }
    }
}

Add AudioRecordView SDK dependency to your app-levelbuild.gradle:

 implementation'com.github.Armen101:AudioRecordView:latest_version'
 //for example 
 //implementation'com.github.Armen101:AudioRecordView:1.0.2'

After that, in your code (perhaps MainActivity class), find or create AudioRecordView object programmatically

private lateinit var audioRecordView: AudioRecordView

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_main)

    audioRecordView = findViewById(R.id.audioRecordView)
}

In XML

<com.visualizer.amplitude.AudioRecordView
        android:id="@+id/audioRecordView"
        android:layout_width="256dp"
        android:layout_height="64dp"
        app:chunkAlignTo="bottom"   
        app:chunkRoundedCorners="true"
        app:chunkSoftTransition="true"
        app:chunkColor="#2196F3"
        app:chunkSpace="1dp"
        app:chunkWidth="2dp"
        app:chunkMaxHeight="48dp"
        app:chunkMinHeight="2dp"/>

And then, in any kind of timer, get the max amplitude from MediaRecorder and just call the AudioRecordView update function

timer = Timer()
timer?.schedule(object : TimerTask() {
    override fun run() {
        val currentMaxAmplitude = recorder?.maxAmplitude
        audioRecordView.update(currentMaxAmplitude); //redraw view
    }
}, 0, 100)

Now, you have the simplest use of AudioRecordView

alt text

app:chunkRoundedCorners="true"

alt text

app:chunkAlignTo="center"

alt text

app:chunkAlignTo="bottom"

Note: AudioRecordView SDK supports Android API 16 or later.

License: Apache License, Version 2.0

Thanks for your attention!

References

Demo

If you have questions until now, you can see more in the sample project in Github.