7

I have managed to play audio files using ffmpeg and AudioTrack class in my android project. I can change the speed of audio using AudioTrack class setRate method. But it also change the pitch of audio, I want to change only Tempo of audio but I found no solution on net.

anyone can please help me on this as there is no support for this.

Goo
  • 1,318
  • 1
  • 13
  • 31
Vipul Purohit
  • 9,807
  • 6
  • 53
  • 76

4 Answers4

15

You can use the atempo filter in ffmpeg 1.0 and later:

ffmpeg -i input.wav -f:a atempo=1.25 output.wav

atempo only accepts values between 0.5 and 2.0, but you can bypass the limitation by chaining multiple filters:

ffmpeg -i input.wav -f:a atempo=2,atempo=1.5 output.wav
Lri
  • 26,768
  • 8
  • 84
  • 82
8

Solution : I tried SoundTouch library. I compiled it successfully for android but then I failed to use its function because I don't know how to use this library to load audio.

But after that I tried library called Sonic. Its basically for Speech as it use PSOLA algo to change pitch and tempo. But its ok.

Vipul Purohit
  • 9,807
  • 6
  • 53
  • 76
  • Hi vipul . I am trying to concatenate and change tempo of mp3 files in my android app. As i am new to android I dont know how to use library Sonic that you suggested above. As the work you have done with audio files , I hope that you have solution for my problem. If you can help me out in changing tempo , that will be a great help. And if you have answer I can post a question for it. Thank you Vipul – Harsh Aug 01 '12 at 02:20
  • Hello @Harsh User OpenSL ES library which is a part of android OS and try this question [OPEN SL ES](http://stackoverflow.com/questions/11094377/android-how-to-change-playback-rate-of-music-using-opensl-es) This will help you to use OpensSL ES lib. – Vipul Purohit Aug 01 '12 at 06:15
  • @Vipul Purhit I am developing a video player which records a video and manipulates its sound i.e change its pitch. how can i use libsonic for that since it is only working for audio files. – Talha Malik Mar 30 '13 at 08:10
  • 1
    Hi @VipulPurohit I had gone through the Sonic Library and I saw a talking.bin file in that, so can you tell me how can I make that .bin file by recording or manually from any mp3,etc file. – Jagdeep Singh Jun 12 '13 at 07:28
2

Pitch and tempo are very strongly linked. What you're trying to do is called "time stretching", and is a somewhat complicated algorithm. You can find information online about it, and a java library for it can be found here, along with a paper describing the process.

Geobits
  • 22,218
  • 6
  • 59
  • 103
0

The answer by @Lri does not work for me, it shows error:

'atempo=1.2' is not a suitable output format

The next command works properly:

ffmpeg -i input.mkv -filter:a "atempo=2.0" -vn output.mkv

Taken from ffmpeg.org.

Yuriy N.
  • 4,936
  • 2
  • 38
  • 31