Giter Club home page Giter Club logo

amplituda's Introduction

GitHub release (latest by date) GitHub

GitHub followers GitHub stars GitHub forks

This library using ffmpeg source. If you want to calculate amplitudes from and draw waveform - use Amplituda library

Used pre-build libraries: libavutil.so, libavcodec.so, libavformat.so, libavresampe.so

Download

Gradle

allprojects {
  repositories {
    maven { url 'https://jitpack.io' }
  }
}
dependencies {
  implementation 'com.github.lincollincol:Amplituda:1.3'
}

Maven

<repositories>
  <repository>
    <id>jitpack.io</id>
    <url>https://jitpack.io</url>
  </repository>
</repositories>
<dependency>
  <groupId>com.github.lincollincol</groupId>
  <artifactId>Amplituda</artifactId>
  <version>1.3</version>
</dependency>

Usage

Amplituda library provide processed audio data to draw a waveform. You can get this data in different format:

  • sequence (single/new line)
  • json
  • list of integers.

Permissions

Add permissions to Manifest.xml file in your app and grant it, before using Amplituda

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

Reduce size

Add android:extractNativeLibs="false" to application in the Manifest.xml

<application
      . . .
    android:extractNativeLibs="false"
      . . . >
    <activity . . ./>
</application>

Examples

• Get amplitudes from audio as json (String):

Java

Amplituda amplituda = new Amplituda();
. . .
amplituda.fromPath("/storage/emulated/0/Music/Linc - Amplituda.mp3")
         .amplitudesAsJson(json -> {
            System.out.println("As json ====== " + json);
         });
// Output: [0, 0, 0, 0, 0, 5, 3, 6, . . . , 6, 4, 7, 1, 0, 0, 0]

Kotlin

val amplituda = Amplituda();
. . .
amplituda.fromPath("/storage/emulated/0/Music/Linc - Amplituda.mp3")
         .amplitudesAsJson {
            println("As json ====== $it")
         }
// Output: [0, 0, 0, 0, 0, 5, 3, 6, . . . , 6, 4, 7, 1, 0, 0, 0]

• Get amplitudes from audio as list of integers (List):

Java

Amplituda amplituda = new Amplituda();
. . .
amplituda.fromPath("/storage/emulated/0/Music/Linc - Amplituda.mp3")
         .amplitudesAsList(list -> {
            System.out.print("As list ====== ");
            for(int tmp : list) {
                System.out.print(tmp + " ");
            }
            System.out.println();
         });
// Output: 0 0 0 0 0 5 3 6 . . . 6 4 7 1 0 0 0

Kotlin

val amplituda = Amplituda();
. . .
amplituda.fromPath("/storage/emulated/0/Music/Linc - Amplituda.mp3")
         .amplitudesAsList {
            print("As list ====== ")
            for(tmp in it) {
                print("$tmp ")
            }
            println()
         }
// Output: 0 0 0 0 0 5 3 6 . . . 6 4 7 1 0 0 0

• Get amplitudes from audio as default single line sequence (String):

Java

Amplituda amplituda = new Amplituda();
. . .
amplituda.fromPath("/storage/emulated/0/Music/Linc - Amplituda.mp3")
         .amplitudesAsSequence(Amplituda.SINGLE_LINE_SEQUENCE_FORMAT, defSeq -> {
            System.out.println("As sequence default ====== " + defSeq);
         });
// Output: 0 0 0 0 0 5 3 6 . . . 6 4 7 1 0 0 0

Kotlin

val amplituda = Amplituda();
. . .
amplituda.fromPath("/storage/emulated/0/Music/Linc - Amplituda.mp3")
         .amplitudesAsSequence(Amplituda.SINGLE_LINE_SEQUENCE_FORMAT) {
            println("As sequence default ====== $it")
         }
// Output: 0 0 0 0 0 5 3 6 . . . 6 4 7 1 0 0 0

• Get amplitudes from audio as custom single line sequence (String):

Java

Amplituda amplituda = new Amplituda();
. . .
amplituda.fromPath("/storage/emulated/0/Music/Linc - Amplituda.mp3")
         .amplitudesAsSequence(Amplituda.SINGLE_LINE_SEQUENCE_FORMAT, " * ", customSeq -> {
            System.out.println("As sequence custom ====== " + customSeq);
         });
// Output: 0 * 0 * 0 * 0 * 0 * 5 * 3 * 6 * . . . 6 * 4 * 7 * 1 * 0 * 0 * 0

Kotlin

val amplituda = Amplituda();
. . .
amplituda.fromPath("/storage/emulated/0/Music/Linc - Amplituda.mp3")
         .amplitudesAsSequence(Amplituda.SINGLE_LINE_SEQUENCE_FORMAT, " * ") {
            println("As sequence custom ====== $it")
         }
// Output: 0 * 0 * 0 * 0 * 0 * 5 * 3 * 6 * . . . 6 * 4 * 7 * 1 * 0 * 0 * 0

• Get amplitudes from audio as new line sequence (String):

Java

Amplituda amplituda = new Amplituda();
. . .
amplituda.fromPath("/storage/emulated/0/Music/Linc - Amplituda.mp3")
         .amplitudesAsSequence(Amplituda.NEW_LINE_SEQUENCE_FORMAT, newLineSeq -> {
            System.out.println("As sequence new line ====== " + newLineSeq);
         });
/* Output: 
0 
0 
5 
3 
. . . 
6 
1 
0 
0
*/

Kotlin

val amplituda = Amplituda();
. . .
amplituda.fromPath("/storage/emulated/0/Music/Linc - Amplituda.mp3")
         .amplitudesAsSequence(Amplituda.NEW_LINE_SEQUENCE_FORMAT) {
            println("As sequence new line ====== $it")
         }
/* Output: 
0 
0 
5 
3 
. . . 
6 
1 
0 
0
*/

Supported formats (tested):

  • mp3
  • opus
  • oga
  • ogg
  • m4a
  • mp4
  • test more formats and contact me.

Unsupported formats:

  • wav

WARNING

Amplituda process audio in the main thread ! You can run Amplituda with RxJava, Kotlin coroutines and Java Threads to process audio in the background therad.

Amplituda don't process audio in the background thread because of :

  • You can use your own approach to work in the background thread. It makes Amplituda library more flexible.
  • Reduce library size. Third-party library uses a lot of space and Amplituda delegates this task to user.

How to draw waveform

  • Use PlayerVisualizerView from this StackOverflow answer in which you should pass Amplituda data to updateVisualizer() as a parameter.
  • Use another third-party library to draw waveform or create cutsom view in which this waveform view use processed audio data byAmplituda to draw every line.

Feedback

[email protected]

License

   Copyright 2020 lincollincol

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.

amplituda's People

Contributors

lincollincol avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.