1 Reply Latest reply: Nov 22, 2010 4:06 PM by captfoss RSS

    get Microphone input level (amplitude) live

    817082
      Hi

      I'm working on a VoIP application, which has big problems with its echo... (mic->otherusers speakers->his mic->my speakers... i thing you know this szenario...)

      I have now the idea to block my partners microphone while i'm speaking, and vice-versa - first of all i know thats not the best idea- since i know that on skype or other VOIP applications echo cancellation works quite well...
      but i don' have the know-how how to do that with JAVA-Sound-API (targetdataline and sourcedatalines...)

      the problem is, that the program needs to recognize if a person is speaking (to block the other's mic)... i found a VolumeRMS code in this forum (but it seems only to work fine with 8 Bit audio data - and i'm using 16 for better speech quality - the source for this was:



           public double volumeRMS(double[] raw) {
      double sum = 0d;
      if (raw.length==0) {
      return sum;
      } else {
      for (int ii=0; ii<raw.length; ii++) {
      sum += raw[ii];
      }
      }
      double average = sum/raw.length;

      double[] meanSquare = new double[raw.length];
      double sumMeanSquare = 0d;
      for (int ii=0; ii<raw.length; ii++) {
      sumMeanSquare += Math.pow(raw[ii]-average,2d);
      meanSquare[ii] = sumMeanSquare;
      }
      double averageMeanSquare = sumMeanSquare/raw.length;
      double rootMeanSquare = Math.pow(averageMeanSquare,0.5d);

      return rootMeanSquare;
           }


      There are (i think so) one bug in this code:
      its maximum amplitude is at about 0-60 (not 100)


      the question is now, how can the program know when someone is speaking? (next to all the background-noise in my room)..
      like a "isSomeBodySpeaking(soundbuffer[])" method?

      or are there any better ideas to deal with echo-cancellation?

      Can anybody help?
        • 1. Re: get Microphone input level (amplitude) live
          captfoss
          user10491813 wrote:
          the question is now, how can the program know when someone is speaking? (next to all the background-noise in my room)..
          like a "isSomeBodySpeaking(soundbuffer[])" method?
          You'd have to record the average volume when they aren't speaking and then consider them to be speaking if the average captured volume in a sliding window goes above that threshold...
          or are there any better ideas to deal with echo-cancellation?
          If you're not to the level where you can code a tradional echo-cancellation algorithm, then I'd recommend you simply put in a button the user has to hold down in order to speak...and disable the rendering to the speakers while the user has the button pressed.