gpt4 book ai didi

java - 更改录制音频的音调和频率

转载 作者:搜寻专家 更新时间:2023-11-01 08:55:52 25 4
gpt4 key购买 nike

我一直在尝试使用以下代码调整一段音频的音调:

http://developer.android.com/guide/topics/media/audio-capture.html

我的猜测是这个调整应该用 MediaRecorder 来完成。

http://developer.android.com/reference/android/media/MediaRecorder.html

但是,我不确定调用哪个方法来改变音调?

通过SO,我找到了changing the frequency of a soundfile in android但我对如何将 SoundPool 与我正在关注的音频捕获指南中的元素集成感到困惑。是否有基于我正在使用的开发人员指南的更直接的解决方案?

最佳答案

mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
mSoundPool = new SoundPool(size, AudioManager.STREAM_MUSIC, 0);
mSoundPoolMap = new HashMap<Integer, Integer>();
mSoundPoolMap.put(index, mSoundPool.load(context, R.raw.sound, 1));


mSoundPool.play(id, streamVolume, streamVolume, 1, loop, 1f);

频率是1f部分。如果您将其更改为介于 .5f 和 2.0f 之间的值,那么应该会减慢或加快采样速度,从而改变音高。

这是我的一个应用程序中的一些代码:

    private SoundPool soundpool; 
private HashMap<Integer, Integer> soundsMap;

protected void onCreate(Bundle savedInstanceState) {

soundpool = new SoundPool(4, AudioManager.STREAM_MUSIC, 100);
soundsMap = new HashMap<Integer, Integer>();
soundsMap.put(cowbell1, soundpool.load(this, R.raw.cowbell, 1));
soundsMap.put(cowbell2, soundpool.load(this, R.raw.cowbell1, 1));
soundsMap.put(cowbell3, soundpool.load(this, R.raw.windhh3, 1));

}

public void playSound(int sound, float fSpeed) {
AudioManager mgr = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
float streamVolumeCurrent = mgr.getStreamVolume(AudioManager.STREAM_MUSIC);
float streamVolumeMax = mgr.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
float volume = streamVolumeCurrent / streamVolumeMax;
soundpool.play(soundsMap.get(sound), volume, volume, 1, 0, fSpeed);
}

我用这个调用声音:

                playSound(cowbell1, 1.0f);
or
playSound(cowbell2, 1.0f);

速率可以通过改变 1.0f 值来改变。

如果您仍然无法发布代码,我会查看。

关于java - 更改录制音频的音调和频率,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18992943/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com