This library using ffmpeg source. If you want to calculate amplitudes from and draw waveform - use Amplituda library
allprojects {
repositories {
maven { url 'https://jitpack.io' }
}
}
dependencies {
implementation 'com.github.lincollincol:Amplituda:1.5'
}
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
<dependency>
<groupId>com.github.lincollincol</groupId>
<artifactId>Amplituda</artifactId>
<version>1.5</version>
</dependency>
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.
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" />
Add android:extractNativeLibs="false"
to application in the Manifest.xml
<application
. . .
android:extractNativeLibs="false"
. . . >
<activity . . ./>
</application>
Amplituda amplituda = new Amplituda(context);
. . .
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]
val amplituda = Amplituda(context);
. . .
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]
Amplituda amplituda = new Amplituda(context);
. . .
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
val amplituda = Amplituda(context);
. . .
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
Amplituda amplituda = new Amplituda(context);
. . .
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
val amplituda = Amplituda(context);
. . .
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
Amplituda amplituda = new Amplituda(context);
. . .
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
val amplituda = Amplituda(context);
. . .
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
Amplituda amplituda = new Amplituda(context);
. . .
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
*/
val amplituda = Amplituda(context);
. . .
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
*/
- mp3
- wav
- opus
- oga
- ogg
- test more formats and contact me.
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.
- You can use my WaveformSeekBar library fork in which Amplituda implemented. Example screenshot below:
- 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.
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.