我们可以利用 FFMPEG 来改变声音。
例子:
/**
* 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)
}
更多细节可以参考示例
https://github.com/sachinvarma/VoiceChanger
请查看以下网站,了解有关有助于我们处理其他影响的信息的更多信息。
https://ffmpeg.org/ffmpeg-filters.html
希望,这可能对将来的某人有所帮助。