# 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:


```js
allprojects {
    repositories {
        ...
        maven { url 'https://jitpack.io' }
    }
}
```
### Add AudioRecordView SDK dependency to your app-levelbuild.gradle:
```js
 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

```kotlin
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

```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](https://developer.android.com/reference/android/media/MediaRecorder#getMaxAmplitude) from [MediaRecorder](https://developer.android.com/reference/android/media/MediaRecorder) and just call the [AudioRecordView](https://github.com/Armen101/AudioRecordView) update function

```kotlin 
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](https://github.com/Armen101/AudioRecordView)


![alt text](https://miro.medium.com/max/700/1*7HmdtALT6irTe4VqtI2jSg.png "app:chunkRoundedCorners=true")
```xml
app:chunkRoundedCorners="true"
```

![alt text](https://miro.medium.com/max/700/1*0BbMIo6N020CA6ORynM0yA.png "app:chunkAlignTo=center")
```xml
app:chunkAlignTo="center"
```

![alt text](https://miro.medium.com/max/700/1*KcnQnPskpJBPIogGMXWrVw.png "app:chunkAlignTo=bottom")
```xml
app:chunkAlignTo="bottom"
```
### *Note:* AudioRecordView SDK supports Android API 16 or later.
### *License:* [Apache License, Version 2.0](https://www.apache.org/licenses/LICENSE-2.0 "Apache License")

## Thanks for your attention!


## **References**

[![Demo](https://img.youtube.com/vi/RnteDAeydoY/0.jpg)](www.youtube.com/watch?v=RnteDAeydoY)


### If you have questions until now, you can see more in the [sample project](https://github.com/Armen101/AudioRecordViewSample "AudioRecordViewSample") in Github.


