What are the options to be able to morph recorded voices to funny tones in Android? iPhone possibly has options like http://dirac.dspdimension.com, do we have some similar library for android that will help create funny voices from recorded files? The requirement is to create something on the lines of 'talking tom'/'chipmunkify' (if that helps understand the context).
If there are no ready libraries, what are other ways to do this?
We can make use of FFMPEG for voice changing purpose.
Example:
/**
* Function to execute FFMPEG Query
*/
private fun exceuteFFMPEG(cmd: Array<String>) {
FFmpeg.execute(cmd)
val rc = FFmpeg.getLastReturnCode()
val output = FFmpeg.getLastCommandOutput()
if (rc == RETURN_CODE_SUCCESS) {
Log.i("GetInfo", "Command execution completed successfully.")
hideProgress()
isEffectAddedOnce = true
start()
} else if (rc == RETURN_CODE_CANCEL) {
Log.i("GetInfo", "Command execution cancelled by user.")
} else {
Log.i(
"GetInfo",
String.format(
"Command execution failed with rc=%d and output=%s.",
rc,
output
)
)
}
}
/**
* Function used to play the audio like a Radio
*/
private fun playRadio(fileName1: String, fileName2: String) {
showProgress()
player?.stop()
val cmd = arrayOf(
"-y",
"-i",
fileName1,
"-af",
"atempo=1",
fileName2
)//Radio
exceuteFFMPEG(cmd)
}
/**
* Function used to play the audio like a Chipmunk
*/
private fun playChipmunk(fileName1: String, fileName2: String) {
showProgress()
player?.stop()
val cmd = arrayOf(
"-y",
"-i",
fileName1,
"-af",
"asetrate=22100,atempo=1/2",
fileName2
)//Chipmunk
exceuteFFMPEG(cmd)
}
/**
* Function used to play the audio like a Robot
*/
private fun playRobot(fileName1: String, fileName2: String) {
showProgress()
player?.stop()
val cmd = arrayOf(
"-y",
"-i",
fileName1,
"-af",
"asetrate=11100,atempo=4/3,atempo=1/2,atempo=3/4",
fileName2
)//Robot
exceuteFFMPEG(cmd)
}
/**
* Function used to play the audio like a Cave
*/
private fun playCave(fileName1: String, fileName2: String) {
showProgress()
player?.stop()
val cmd = arrayOf(
"-y",
"-i",
fileName1,
"-af",
"aecho=0.8:0.9:1000:0.3",
fileName2
)//Cave
exceuteFFMPEG(cmd)
}
For more details, you can refer the sample at
https://github.com/sachinvarma/VoiceChanger
Please have a look on to the below site for more information regarding informations that will help us to handle other effects.
https://ffmpeg.org/ffmpeg-filters.html
Hope, this may help someone in future.
One option is to use AudioTrack. It is available since API 3 and is quite widely used. It will help you modify the frequency, and hence the pitch, of the audio file you want to distort. A higher pitch will give you the chipmunk like sound you were looking for.
However, due to its old age, AudioTrack may be difficult to implement for you. Try Android's soundpool api. Its flexible, can play tens of sounds at a time, and lets you modify pitch/frequency very easily.
Here is how I tested it (it works):
SoundPool soundPool = new SoundPool(1, AudioManager.STREAM_MUSIC, 0);
boolean isSoundLoaded = false;
float frequencyPitch = 1.3f; // tweak this. it accepts any number between 0.5f and 2.0f
int soundID = soundPool.load(filePath+fileName, 1);
soundPool.setOnLoadCompleteListener(new OnLoadCompleteListener() {
@Override
public void onLoadComplete(SoundPool soundPool, int sampleId, int status) {
isSoundLoaded = true;
if(isSoundLoaded)
{
soundPool.play(soundID, 1f, 1f, 1, 0, frequencyPitch);
}
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With