1

ここですでに尋ねられた多くの質問を検索しても、この問題の解決策の例は見つかりませんでした (このJava のような他のリンクを投稿しないでください: 2 つの異なるマイク入力から独立してオーディオをキャプチャする原因はありません)。私が試すことができる答え)。

これは現在1つのマイクで機能しているコードですが、2番目のマイクの2行目を定義する方法が見つかりません。助けてください:)。

パブリッククラスSecondTest {

public static void main(String[] args) throws LineUnavailableException {

    ByteArrayOutputStream byteArrayOutputStream;
    TargetDataLine line;
    int counter1;

    byte tempBuffer[] = new byte[8000];
    int countzero, countdownTimer;    
    short convert[] = new short[tempBuffer.length];     

    /**
     * This variable controls the accuracy of the volume recorded, 
     * for detecting lower volumes this number should be increased.
     */
    int soundAccuarracy = 3000;


    try {
        byteArrayOutputStream = new ByteArrayOutputStream();
        countdownTimer = 0;

        //Start capturing
        while (stopWatch.getTime() < timeOut) {
            AudioFormat audioFormat = new AudioFormat(8000.0F, 16, 1, true, false);
            DataLine.Info dataLineInfo = new DataLine.Info(TargetDataLine.class, audioFormat);

            line = (TargetDataLine) AudioSystem.getLine(dataLineInfo);
            line.open(audioFormat);
            line.start();


            counter1 = line.read(tempBuffer, 0, tempBuffer.length);
            byteArrayOutputStream.write(tempBuffer, 0, counter1); 

            try {
                countzero = 0;
                for (int i = 0; i < tempBuffer.length; i++) {                                     
                    convert[i] = tempBuffer[i];
                    if (convert[i] == 0) {
                        countzero++;
                    }
                }


                countdownTimer++;

                //This line prints the current volume accuracy detected and the times that the buffer run
                System.out.println("Volume level is: " + countzero + ", counter number " + countdownTimer);

} catch (StringIndexOutOfBoundsException e) {
                System.out.println(e.getMessage());
            }

            Thread.sleep(0);
            line.close();
        }

    } catch (Exception e) {
        System.out.println(e);
    }
}

}

4

0 に答える 0