在Android上使用TarsosDSP进行实时音高转换

时间:2016-05-23 08:42:09

标签: android pitch-shifting tarsosdsp

这就是我想要的:
1.播放歌曲时的实时音高变化 2.音高转换也应记录到文件中。

代码:

    double rate = 1.0;
    RateTransposer rateTransposer;
    AudioDispatcher dispatcher;
    WaveformSimilarityBasedOverlapAdd wsola;

    dispatcher = AudioDispatcherFactory.fromPipe(mAudiopath, 44100, 5000, 2500);
    rateTransposer = new RateTransposer(rate);
    wsola = new WaveformSimilarityBasedOverlapAdd(WaveformSimilarityBasedOverlapAdd.Parameters.musicDefaults(rate, 44100));
    WaveformWriter writer = new WaveformWriter((TarsosDSPAudioFormat) dispatcher.getFormat(), BASE_PATH + "Recorded" + File.separator + "PITCHED_" + mVideoFileName + ".mp3");

    wsola.setDispatcher(dispatcher);
    dispatcher.addAudioProcessor(wsola);
    dispatcher.addAudioProcessor(rateTransposer);
    dispatcher.addAudioProcessor(new AndroidAudioPlayer(dispatcher.getFormat()));
    dispatcher.setZeroPadFirstBuffer(true);
    dispatcher.setZeroPadLastBuffer(true);
    dispatcher.addAudioProcessor(writer);

但在这里我面临以下错误:

Error:(362, 41) error: cannot access AudioFormat
class file for javax.sound.sampled.AudioFormat not found

换行

   WaveformWriter writer = new WaveformWriter((TarsosDSPAudioFormat) dispatcher.getFormat(), BASE_PATH + "Recorded" + File.separator + "PITCHED_" + mVideoFileName + ".mp3");

如果删除此行,一切正常,只有歌曲不会录制到文件中 如果有人可以提供帮助,请告诉我。

1 个答案:

答案 0 :(得分:2)

使用不依赖于JVM的WriterProcessor类解决了此问题。

ref:https://github.com/JorenSix/TarsosDSP/issues/64