0

我正在制作 android 应用程序来检测 18k~20k。但是 Pitch 值没有得到它。音高值不能超过 11000Hz。我尝试更改采样率的值 sampleSizeInBits,但它无法正常工作。请帮我解决这个问题。这可能是关于 TarasosDSP 库的问题吗..?

'''

tarsosDSPAudioFormat=new TarsosDSPAudioFormat(TarsosDSPAudioFormat.Encoding.PCM_SIGNED, 22050, 16, 1, 2 * 1, 22050, ByteOrder.BIG_ENDIAN.equals(ByteOrder.nativeOrder()));

    pitchTextView = findViewById(R.id.pitchTextView);
    recordButton = findViewById(R.id.recordButton);
    playButton = findViewById(R.id.playButton);

    recordButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if(!isRecording)
            {
                recordAudio();
                isRecording = true;
                recordButton.setText("stop");
            }
            else
            {
                stopRecording();
                isRecording = false;
                recordButton.setText("record");
            }
        }
    });

}

public void recordAudio()
{
    releaseDispatcher();
    dispatcher = AudioDispatcherFactory.fromDefaultMicrophone(22050,1024,0);

    try {
        RandomAccessFile randomAccessFile = new RandomAccessFile(file,"rw");
        AudioProcessor recordProcessor = new WriterProcessor(tarsosDSPAudioFormat, randomAccessFile);
        dispatcher.addAudioProcessor(recordProcessor);

        PitchDetectionHandler pitchDetectionHandler = new PitchDetectionHandler() {
            @Override
            public void handlePitch(PitchDetectionResult res, AudioEvent e){
                final float pitchInHz = res.getPitch();
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        pitchTextView.setText(pitchInHz + "");
                    }
                });
            }
        };

        AudioProcessor pitchProcessor = new PitchProcessor(PitchProcessor.PitchEstimationAlgorithm.FFT_YIN, 22050, 1024, pitchDetectionHandler);
        dispatcher.addAudioProcessor(pitchProcessor);

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

    } catch (IOException e) {
        e.printStackTrace();
    }
}

'''

4

0 回答 0