JorenSix / TarsosDSP

A Real-Time Audio Processing Framework in Java
http://0110.be/tag/TarsosDSP
GNU General Public License v3.0
1.97k stars 472 forks source link

How to work with PitchShifter? #209

Open HaXxanParhar opened 2 years ago

HaXxanParhar commented 2 years ago

I have just added this library to my android project but unfortunately, I'm unable to find proper documentation/guide or demo project on how to use the library. I need to change the pitch of the audio without changing its length i.e. Voice changing from male to female and vice versa. I'm using the PitchShifter class but it is not giving the desired output. Following is my code:

` currentFactor = 1.5; outputFile = createAudioFile(); bytesList = new ArrayList<>();

    // SampleRate, BufferSize, Overlap
    dispatcher = AudioDispatcherFactory.fromDefaultMicrophone(SAMPLE_RATE, BUFFER_SIZE, 0);

    //pitchShiftRatio, sampleRate, BufferSize,  Overlap
    PitchShifter pitchShifter = new PitchShifter(currentFactor, SAMPLE_RATE, BUFFER_SIZE, 1024 - 256);
    dispatcher.addAudioProcessor(pitchShifter);

    dispatcher.addAudioProcessor(new AndroidAudioPlayer(new TarsosDSPAudioFormat(
            SAMPLE_RATE, CHANNEL_CONFIG, CHANNELS, true, true), BUFFER_SIZE, AudioManager.STREAM_MUSIC));

    Thread audioThread = new Thread(dispatcher, "Audio Thread");
    audioThread.start();`

I also used the combination of RateTransposer and WaveformSimilarityBasedOverlapAdd for pitch shifting but again no desired results because I don't know how to use them properly as there is no documentation available. Kindly guide me. Thanks