我无法开始录音。我收到以下错误:
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)
这是我拨打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;
}
}
SpeechToText识别的设置
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();
}
build.gradle
文件的一部分
android {
compileSdkVersion 27
defaultConfig {
applicationId "com.test.testapp"
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'
}
}
}
请记住,minSdkVersion
符合请求(大于API级别19),并且已经为API级别> = 23正确请求并实现了RECORD_AUDIO
和WRITE_EXTERNAL_STORAGE
权限。
有人可以帮我解决这个问题吗?我研究的答案并没有太大帮助。感激