0

我正在将 TarsosDSP 用于 android 项目,但出现此错误:

Unable to start activity ComponentInfo{com.example.song2sheet/com.example.song2sheet.RecordingActivity}: java.lang.IllegalStateException: startRecording() called on an uninitialized AudioRecord.

根据我所读到的,要开始取样,我所需要的就是这个

        AudioDispatcher dispatcher = AudioDispatcherFactory.fromDefaultMicrophone(22050, 1024, 0);
        PitchDetectionHandler detectionHandler = new PitchDetectionHandler() {
            @Override
            public void handlePitch(PitchDetectionResult pitchDetectionResult, AudioEvent audioEvent) {
                final float pitchInHz = pitchDetectionResult.getPitch();
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        sampledFrequency = pitchInHz;
                    }
                });
            }
        };
        AudioProcessor pitchProcessor = new PitchProcessor(PitchProcessor.PitchEstimationAlgorithm.FFT_PITCH, 22020, 1024, detectionHandler);
        dispatcher.addAudioProcessor(pitchProcessor);

        Thread recordingThread = new Thread(dispatcher, "Recording Thread");
        recordingThread.start();

但如上所示,我收到了 IllegalStateException。

我是否从这段代码中遗漏了一些东西,因为错误是在第一行抛出的?

任何帮助都会很重要。

谢谢。

4

0 回答 0