Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fatal Exception: java.lang.Error: Error while reading audio input stream #211

Open
JulyanMayer opened this issue Oct 23, 2022 · 0 comments

Comments

@JulyanMayer
Copy link

JulyanMayer commented Oct 23, 2022

I'm getting this error in firebase and I don't know how to solve it :(

Fatal Exception: java.lang.Error: Error while reading audio input stream: The end of the audio stream has not been reached and the number of bytes read (2147483647) is not equal to the expected amount of bytes(8192).
at be.tarsos.dsp.AudioDispatcher.run(:149)
at java.lang.Thread.run(Thread.java:764)

This is only happening with android 8 and 9
Remembering that this code is in a Fragment, I don't know if it makes a difference

My code

private Thread thread;
private AudioDispatcher;
private PitchDetectionHandler handler;

private void initHertzCapture(){
new Handler().postDelayed(new Runnable() {
@OverRide
public void run() {
dispatcher = AudioDispatcherFactory.fromDefaultMicrophone(22050,4096,0);
thread = new Thread(dispatcher,"Audio Dispatcher");

            handler = new PitchDetectionHandler() {
                @Override
                public void handlePitch(PitchDetectionResult pitchDetectionResult, AudioEvent audioEvent) {

                    pitchInHz = pitchDetectionResult.getPitch();

                    if (isAdded()){
                        activity.runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                
                                setHertz();
                                audioEvent.clearFloatBuffer();
                            }
                        });
                    }else{
                        dispatcher.stop();
                        if (!thread.isInterrupted()){
                            thread.interrupt();
                        }
                    }
                }
            };

            dispatcher.addAudioProcessor(new PitchProcessor(PitchProcessor.PitchEstimationAlgorithm.YIN, 22050, 4096, handler));
            thread.start();
        }
    },300);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant