I can not start the audio recording. I'm getting 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)
This is the code where I call the 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;
}
}
The 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();
}
Part of file 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'
}
}
}
Remembering that minSdkVersion
is compliant 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.