---
title: TarsosDSP on Android - Audio Processing in Java on Android
canonical: https://0110.be/posts/TarsosDSP_on_Android_-_Audio_Processing_in_Java_on_Android
markdown_url: https://0110.be/posts/TarsosDSP_on_Android_-_Audio_Processing_in_Java_on_Android.md
id: 420
published_at: '2014-08-14T00:00:00Z'
updated_at: '2025-11-29T22:28:08Z'
author: Joren
tags:
- name: TarsosDSP
  markdown_url: https://0110.be/tags/TarsosDSP.md
- name: UGent
  markdown_url: https://0110.be/tags/UGent.md
---

# TarsosDSP on Android - Audio Processing in Java on Android

<img src="https://0110.be/files/attachments/420/android-audio.jpg"  width="20%" alt="Audio on Android" style="float:right;margin-left:1.5rem;margin-bottom:1.5rem"/>This post explains how to get TarsosDSP running on Android. TarsosDSP is a Java library for audio processing. Its aim is to provide an easy-to-use interface to practical music processing algorithms implemented, as simply as possible, in pure Java and without any other external dependencies.

Since version 2.0 there are no more references to `javax.sound.*` in the TarsosDSP core codebase. This makes it easy to run TarsosDSP on Android. Audio Input/Output operations that depend on either the JVM or Dalvik runtime have been abstracted and removed from the core. For each runtime target a Jar file is provided in the [TarsosDSP release directory](https://0110.be/releases/TarsosDSP).

The source code for the [audio I/O on the JVM](https://github.com/JorenSix/TarsosDSP/tree/master/jvm/be/tarsos/dsp/io/jvm) and the [audio I/O on Android](https://github.com/JorenSix/TarsosDSP/tree/master/android/be/tarsos/dsp/io/android) can be found on GitHub. To get an audio processing algorithm working on Android the only thing that is needed is to place [`TarsosDSP-Android-2.0.jar`](https://0110.be/releases/TarsosDSP/TarsosDSP-2.0/TarsosDSP-Android-2.0.jar) in the `lib` directory of your project.

The following example connects an `AudioDispatcher` to the microphone of an Android device. Subsequently, a real-time pitch detection algorithm is added to the processing chain. The detected pitch in Hertz is printed on a `TextView` element, if no pitch is present in the incoming sound, --1 is printed. To test the application download and install the https://0110.be/files/attachments/420/TarsosDSPAndroid.apk(https://0110.be/files/attachments/420/TarsosDSPAndroid.apk) application on your Android device. The [source code](https://0110.be/files/attachments/420/TarsosDSPAndroid.zip) is available as well.

````java
AudioDispatcher dispatcher = AudioDispatcherFactory.fromDefaultMicrophone(22050, 1024, 0);
PitchDetectionHandler pdh = new PitchDetectionHandler() {
    @Override
    public void handlePitch(PitchDetectionResult result, AudioEvent e) {
        final float pitchInHz = result.getPitch();
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                TextView text = (TextView) findViewById(R.id.textView1);
                text.setText("" + pitchInHz);
            }
        });
    }
};
AudioProcessor p = new PitchProcessor(PitchEstimationAlgorithm.FFT_YIN, 22050, 1024, pdh);
dispatcher.addAudioProcessor(p);
new Thread(dispatcher, "Audio Dispatcher").start();
````

Thanks to these changes, the fork of TarsosDSP kindly provided by GitHub user [srubin](https://github.com/srubin/TarsosDSP), created for [a programming assignment at UC Berkley](http://husk.eecs.berkeley.edu/courses/cs160-sp14/index.php/Individual_Programming_Assignment_3), is not needed any more.

Have fun hacking audio on Android!


- [android-audio.jpg](https://0110.be/files/attachments/420/android-audio.jpg)

- [TarsosDSPAndroid.apk](https://0110.be/files/attachments/420/TarsosDSPAndroid.apk)

- [TarsosDSPAndroid.zip](https://0110.be/files/attachments/420/TarsosDSPAndroid.zip)
