Integrating soundtouch lib in android for pitch shifting

48 views Asked by At

I'm trying to integrate the soundTouch lib to use it for my audio files pitch shifting ( added link in bottom for lib reference) , i have integrated most of code but it is not working as the file saved has 0KB and is not working properly because in the lib , they do not really specify how to get the output , if anyone worked with this lib before , i need some help and it is appreciated in advance . Thank you

  • Lib
https://github.com/qingmei2/soundtouch-android
  • My code

// Basically i pick wav file device , convert it to bytes
 private void showWav() {
       progressDialog.setMessage("Please wait .. Processing files");
       progressDialog.show();

       new Thread(new Runnable() {
           @Override
           public void run() {
               try{

                   // CONVERT FILE INTO BYTES
                   ByteArrayOutputStream out = new ByteArrayOutputStream();
                   BufferedInputStream in = new BufferedInputStream(new FileInputStream(file));

                   int read;
                   byte[] buff = new byte[1024];
                   while ((read = in.read(buff)) > 0) {
                       out.write(buff, 0, read);
                   }
                   out.flush();
                   byte[] audioBytes = out.toByteArray();

                   SoundTouch soundTouch = new SoundTouch(0, 2, 44100, 2, 1.0f, 2.0f);
                   soundTouch.putBytes(audioBytes);

                   // PROCESS AUDIO WITH SOUNDTOUCH
                   byte[] processedAudio = new byte[8192]; // Adjust the buffer size as needed
                   int bytesReceived;
                   String path;
                   byte[] mFile;

                   do {
                       bytesReceived = soundTouch.getBytes(processedAudio);
                       File f  = new File(Environment.getExternalStorageDirectory(),"CVS");
                       if(!f.exists()){
                           f.mkdir();
                       }

                       path = f.getPath() + File.separator + String.valueOf(System.currentTimeMillis())  + ".wav";
                       mFile = new byte[bytesReceived];

                   } while (bytesReceived != 0);

                   FileOutputStream fos = new FileOutputStream(path);
                   fos.write(mFile);
                   fos.close();
                   // RELEASE RESOURCES
                   soundTouch.clearBuffer();

                   hideProgressDialog();

               } catch (Exception e){
                   hideProgressDialog();
                   Log.d("TAG","Exception " + e.getMessage());
               }
           }
       }).start();

   }

0

There are 0 answers