Watson Speechtotext crash app android when Microphonehelper is called

Asked

Viewed 24 times

1

I cannot start the audio recording. I am receiving the following error:

E/AudioRecord: start() status -38
E/AndroidRuntime: FATAL EXCEPTION: Thread-7713
    Process: com.sienaapp.sienaapp, PID: 5005
    java.lang.IllegalArgumentException: capacity < 0: -6
        at java.nio.ByteBuffer.allocate(ByteBuffer.java:54)
        at com.ibm.watson.developer_cloud.android.library.audio.MicrophoneCaptureThread.run(MicrophoneCaptureThread.java:91)

That’s the code where I call Microphonehelper

 @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.fab:
                try {
                    mMicrophoneStream = mMicrophoneHelper.getInputStream(true);
                } catch (Exception e) {
                    e.printStackTrace();
                }

                new Thread(new Runnable() {
                    @Override
                    public void run() {
                        mSpeechToText.recognizeUsingWebSocket(mMicrophoneStream,
                                getRecognizeOptions(),
                                baseRecognizeListener);
                    }
                }).start();
                break;
        }
    }

Settings for Speechtotext Recognize

private RecognizeOptions getRecognizeOptions() {
        return new RecognizeOptions.Builder()
                .model("pt-BR_BroadbandModel")
                .contentType(ContentType.OPUS.toString())
                .interimResults(true)
                .timestamps(true)
                .inactivityTimeout(-1)
                .smartFormatting(true)
                .model(SpeechModel.PT_BR_BROADBANDMODEL.getName())
                .build();
    }

File part build.gradle

android {
    compileSdkVersion 27
    defaultConfig {
        applicationId "com.teste.testeapp"
        minSdkVersion 22
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

Recalling that the minSdkVersion is in accordance with the request (greater than API level 19) and the permissions of RECORD_AUDIO and WRITE_EXTERNAL_STORAGE were properly requested and implemented for API Level >= 23.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.