<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Armen Gevorgyan</title>
    <description>The latest articles on DEV Community by Armen Gevorgyan (@armen101).</description>
    <link>https://dev.to/armen101</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F364646%2Fafeaa029-a658-4984-a8df-6b7085de98fc.jpeg</url>
      <title>DEV Community: Armen Gevorgyan</title>
      <link>https://dev.to/armen101</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/armen101"/>
    <language>en</language>
    <item>
      <title>AudioRecordView</title>
      <dc:creator>Armen Gevorgyan</dc:creator>
      <pubDate>Sat, 11 Apr 2020 10:28:52 +0000</pubDate>
      <link>https://dev.to/armen101/audiorecordview-3jn5</link>
      <guid>https://dev.to/armen101/audiorecordview-3jn5</guid>
      <description>&lt;h2&gt;
  
  
  &lt;em&gt;Real-time audio visualizer for&amp;nbsp;android&lt;/em&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--8A3M_Jia--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/800/1%2AMjlyouM0wJLiGx8VFWRrcQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--8A3M_Jia--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn-images-1.medium.com/max/800/1%2AMjlyouM0wJLiGx8VFWRrcQ.png" alt="alt text" title="Logo Title Text 1"&gt;&lt;/a&gt;&lt;/p&gt;



&lt;h3&gt;
  
  
  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.
&lt;/h3&gt;

&lt;h3&gt;
  
  
  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.
&lt;/h3&gt;

&lt;h3&gt;
  
  
  What are the advantages of this library?
&lt;/h3&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Benefits:&lt;/strong&gt;
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;The library is easy to use&lt;/li&gt;
&lt;li&gt;Small and clear code&lt;/li&gt;
&lt;li&gt;Support to use in both: code and XML&lt;/li&gt;
&lt;li&gt;Active support and improvements&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;What do we mean when we say flexible? You&amp;nbsp;can&lt;/strong&gt;
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Choose one of two types of alignment mode: "bottom" and "center"&lt;/li&gt;
&lt;li&gt;Change the color of the chunks&lt;/li&gt;
&lt;li&gt;Set minimum/maximum height of chunks&lt;/li&gt;
&lt;li&gt;Change the width of chunks&lt;/li&gt;
&lt;li&gt;Change space between two chunks.&lt;/li&gt;
&lt;li&gt;Set the mode of rounded corners&lt;/li&gt;
&lt;li&gt;Enable/disable "Soft Transition" mode&lt;/li&gt;
&lt;li&gt;Control drawing speed&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Setup AudioRecordView&lt;/strong&gt;
&lt;/h2&gt;

&lt;h3&gt;
  
  
  In your application project (or root project if you prefer) build.gradle,make sure you have jcenter repository added:
&lt;/h3&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;allprojects&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;repositories&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="p"&gt;...&lt;/span&gt;
        &lt;span class="nx"&gt;maven&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;url&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;https://jitpack.io&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h3&gt;
  
  
  Add AudioRecordView SDK dependency to your app-levelbuild.gradle:
&lt;/h3&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt; &lt;span class="nx"&gt;implementation&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;com.github.Armen101:AudioRecordView:latest_version&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
 &lt;span class="c1"&gt;//for example &lt;/span&gt;
 &lt;span class="c1"&gt;//implementation'com.github.Armen101:AudioRecordView:1.0.2'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h3&gt;
  
  
  After that, in your code (perhaps MainActivity class), find or create AudioRecordView object programmatically
&lt;/h3&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="k"&gt;lateinit&lt;/span&gt; &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="py"&gt;audioRecordView&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;AudioRecordView&lt;/span&gt;

&lt;span class="k"&gt;override&lt;/span&gt; &lt;span class="k"&gt;fun&lt;/span&gt; &lt;span class="nf"&gt;onCreate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;savedInstanceState&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Bundle&lt;/span&gt;&lt;span class="p"&gt;?)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;super&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;onCreate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;savedInstanceState&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="nf"&gt;setContentView&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;R&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;layout&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;activity_main&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="n"&gt;audioRecordView&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;findViewById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;R&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;audioRecordView&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h3&gt;
  
  
  In XML
&lt;/h3&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight xml"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;com.visualizer.amplitude.AudioRecordView&lt;/span&gt;
        &lt;span class="na"&gt;android:id=&lt;/span&gt;&lt;span class="s"&gt;"@+id/audioRecordView"&lt;/span&gt;
        &lt;span class="na"&gt;android:layout_width=&lt;/span&gt;&lt;span class="s"&gt;"256dp"&lt;/span&gt;
        &lt;span class="na"&gt;android:layout_height=&lt;/span&gt;&lt;span class="s"&gt;"64dp"&lt;/span&gt;
        &lt;span class="na"&gt;app:chunkAlignTo=&lt;/span&gt;&lt;span class="s"&gt;"bottom"&lt;/span&gt;   
        &lt;span class="na"&gt;app:chunkRoundedCorners=&lt;/span&gt;&lt;span class="s"&gt;"true"&lt;/span&gt;
        &lt;span class="na"&gt;app:chunkSoftTransition=&lt;/span&gt;&lt;span class="s"&gt;"true"&lt;/span&gt;
        &lt;span class="na"&gt;app:chunkColor=&lt;/span&gt;&lt;span class="s"&gt;"#2196F3"&lt;/span&gt;
        &lt;span class="na"&gt;app:chunkSpace=&lt;/span&gt;&lt;span class="s"&gt;"1dp"&lt;/span&gt;
        &lt;span class="na"&gt;app:chunkWidth=&lt;/span&gt;&lt;span class="s"&gt;"2dp"&lt;/span&gt;
        &lt;span class="na"&gt;app:chunkMaxHeight=&lt;/span&gt;&lt;span class="s"&gt;"48dp"&lt;/span&gt;
        &lt;span class="na"&gt;app:chunkMinHeight=&lt;/span&gt;&lt;span class="s"&gt;"2dp"&lt;/span&gt;&lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h3&gt;
  
  
  And then, in any kind of timer, get the &lt;a href="https://developer.android.com/reference/android/media/MediaRecorder#getMaxAmplitude()"&gt;max amplitude&lt;/a&gt; from &lt;a href="https://developer.android.com/reference/android/media/MediaRecorder"&gt;MediaRecorder&lt;/a&gt; and just call the AudioRecordView update function
&lt;/h3&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight kotlin"&gt;&lt;code&gt;&lt;span class="n"&gt;timer&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Timer&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="n"&gt;timer&lt;/span&gt;&lt;span class="o"&gt;?.&lt;/span&gt;&lt;span class="nf"&gt;schedule&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;object&lt;/span&gt; &lt;span class="err"&gt;: &lt;/span&gt;&lt;span class="nc"&gt;TimerTask&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;override&lt;/span&gt; &lt;span class="k"&gt;fun&lt;/span&gt; &lt;span class="nf"&gt;run&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="kd"&gt;val&lt;/span&gt; &lt;span class="py"&gt;currentMaxAmplitude&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;recorder&lt;/span&gt;&lt;span class="o"&gt;?.&lt;/span&gt;&lt;span class="n"&gt;maxAmplitude&lt;/span&gt;
        &lt;span class="n"&gt;audioRecordView&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;update&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;currentMaxAmplitude&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;//redraw view&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h3&gt;
  
  
  Now, you have the simplest use of AudioRecordView
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--saKNsnSV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/700/1%2A7HmdtALT6irTe4VqtI2jSg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--saKNsnSV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/700/1%2A7HmdtALT6irTe4VqtI2jSg.png" alt="alt text" title="app:chunkRoundedCorners=true"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight xml"&gt;&lt;code&gt;app:chunkRoundedCorners="true"
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--EUxZqRcM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/700/1%2A0BbMIo6N020CA6ORynM0yA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--EUxZqRcM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/700/1%2A0BbMIo6N020CA6ORynM0yA.png" alt="alt text" title="app:chunkAlignTo=center"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight xml"&gt;&lt;code&gt;app:chunkAlignTo="center"
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--QyDb6RAS--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/700/1%2AKcnQnPskpJBPIogGMXWrVw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--QyDb6RAS--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://miro.medium.com/max/700/1%2AKcnQnPskpJBPIogGMXWrVw.png" alt="alt text" title="app:chunkAlignTo=bottom"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight xml"&gt;&lt;code&gt;app:chunkAlignTo="bottom"
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h3&gt;
  
  
  &lt;em&gt;Note:&lt;/em&gt; AudioRecordView SDK supports Android API 16 or later.
&lt;/h3&gt;

&lt;h3&gt;
  
  
  &lt;em&gt;License:&lt;/em&gt; &lt;a href="https://www.apache.org/licenses/LICENSE-2.0"&gt;Apache License, Version 2.0&lt;/a&gt;
&lt;/h3&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;References&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;&lt;a href="//www.youtube.com/watch?v=RnteDAeydoY"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--HTGZN1a3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://img.youtube.com/vi/RnteDAeydoY/0.jpg" alt="IMAGE ALT TEXT HERE"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  If you have questions until now, you can see more in the &lt;a href="https://github.com/Armen101/AudioRecordViewSample"&gt;sample project&lt;/a&gt; in Github.
&lt;/h3&gt;

&lt;h2&gt;
  
  
  Thanks for your attention!
&lt;/h2&gt;

</description>
      <category>android</category>
      <category>kotlin</category>
      <category>audiorecordview</category>
    </item>
  </channel>
</rss>
