我一直在尝试为用户录制的语音设置一些不同的语音配置文件。到目前为止,我只能选择更改音频剪辑的音调和速度,但无法添加其他效果,例如“来自下水道的声音”或“浴缸效果”等。我使用了PlaybackParams,但由于前面已经提到,我只能更改音高和速度。
如果有人需要,这是我的代码:
private void startRecording() {
//Starts recording.
mediaRecorder = new MediaRecorder();
mediaRecorder.setOutputFile(mediaFileName);
mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
mediaRecorder.setAudioEncodingBitRate(128000);
mediaRecorder.setAudioSamplingRate(96000);
try {
mediaRecorder.prepare();
} catch (IOException e) {
e.printStackTrace();
}
mediaRecorder.start();
}
这是发生回击的地方:
private void useDarthBtn() {
//Called when darthBtn is pressed.
mediaPlayer = new MediaPlayer();
mediaPlayer = MediaPlayer.create(getApplicationContext(), Uri.parse(mediaFileName));
if (mediaPlayer != null) {
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
PlaybackParams params = new PlaybackParams();
params.setPitch(0.7f);
mediaPlayer.setPlaybackParams(params);
//Setting up params element and loading mediaPlayer.
mediaPlayer.start();
playingStarted = true;
mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
//Detects mediaPlayer's task completion.
@SuppressLint("SetTextI18n")
@Override
public void onCompletion(MediaPlayer mediaPlayer) {
completion();
}
});
}
}
除了音高和速度水平之外,我们如何添加更多其他种类?