How to slow down and stretch audio in Android?

I found out that the MediaPlayer class does not support changing playback speed. I tried Soundpool, it works, but when I slow down the speed to 0.5f, the step becomes weird (low step). I want to change the speed, but I keep the same characteristic of the sound, so if I slow it down, it stretches the sound, but does not take a step lower. What is the best day for this? Thank you in advance for your help!

+4
source share
2 answers

Check out this website: http://www.pitchtech.ch/

"The PitchTech research project aims to provide high-quality sound transformations implemented in Java." It hosts numerous research articles with sufficient information to create your own or use one of the implemented audio transforms.

I found it using this Google search: Audio conversion is stretched .

+1
source

This may be helpful. After everything was done, I decided to go with SoundPool to change Pitch. The playback speed 2.0 leads to the fact that the sound is reproduced at a frequency of two times compared with the original, and the playback speed of 0.5 leads to the fact that it reproduces half of its original frequency. The playback speed range is from 0.5 to 2.0. But he worked with frequencies lower and higher than 0.5 and 2.0.

I submit my working code,

but as its just for demo purpose, here you need to manually change the "playback speed" every time you install the application, for example: "sp.play (explosion, 1,1,0,0,1,5f)", here " 1.5f "is the playback speed. You can easily create an EditView or something similar to set the value of the playback speed at runtime.

In this application, you just need to click on the application screen to play music with the set playback speed.

import java.io.IOException; import android.app.Activity; import android.content.res.AssetFileDescriptor; import android.media.AudioManager; import android.media.SoundPool; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; public class SoundPoolActivity extends Activity implements OnClickListener { SoundPool sp; int explosion = 0; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); View v = new View(this); v.setOnClickListener(this); setContentView(v); sp = new SoundPool(1,AudioManager.STREAM_MUSIC,0); //explosion = sp.load(this, R.raw.hh,0); explosion = sp.load("/sdcard/hh.m4a",0); } public void onClick(View v){ if (explosion!=0){ sp.play(explosion, 1,1,0,0,2.3f); } } } 
+1
source

All Articles