Я использую демонстрационный код " Quickstart: распознавание речи в Java на Android с помощью Speech SDK ", но код находится в Java
, и я использую его в Kotlin
, поэтомуЯ должен был преобразовать код.когда я нажимаю кнопку для вызова функции onSpeechButtonClicked(v:View)
, появляется следующая ошибка:
Process: robertopinheiro_iotlab.pixelspeech, PID: 13047
java.lang.IllegalStateException: Could not execute method for android:onClick
at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:389)
at android.view.View.performClick(View.java:6294)
at android.view.View$PerformClick.run(View.java:24770)
at android.os.Handler.handleCallback(Handler.java:790)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6494)
at java.lang.reflect.Method.invoke(Native Method)
...
Caused by: java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/robertopinheiro_iotlab.pixelspeech-lVHD6wyC3gwL3rSAtctmIw==/base.apk", zip file "/data/app/robertopinheiro_iotlab.pixelspeech-lVHD6wyC3gwL3rSAtctmIw==/split_lib_dependencies_apk.apk", zip file "/data/app/robertopinheiro_iotlab.pixelspeech-lVHD6wyC3gwL3rSAtctmIw==/split_lib_resources_apk.apk", zip file "/data/app/robertopinheiro_iotlab.pixelspeech-lVHD6wyC3gwL3rSAtctmIw==/split_lib_slice_0_apk.apk", zip file "/data/app/robertopinheiro_iotlab.pixelspeech-lVHD6wyC3gwL3rSAtctmIw==/split_lib_slice_1_apk.apk", zip file "/data/app/robertopinheiro_iotlab.pixelspeech-lVHD6wyC3gwL3rSAtctmIw==/split_lib_slice_2_apk.apk", zip file "/data/app/robertopinheiro_iotlab.pixelspeech-lVHD6wyC3gwL3rSAtctmIw==/split_lib_slice_3_apk.apk", zip file "/data/app/robertopinheiro_iotlab.pixelspeech-lVHD6wyC3gwL3rSAtctmIw==/split_lib_slice_4_apk.apk", zip file "/data/app/robertopinheiro_iotlab.pixelspeech-lVHD6wyC3gwL3rSAtctmIw==/split_lib_slice_5_apk.apk", zip file "/data/app/robertopinheiro_iotlab.pixelspeech-lVHD6wyC3gwL3rSAtctmIw==/split_lib_slice_6_apk.apk", zip file "/data/app/robertopinheiro_iotlab.pixelspeech-lVHD6wyC3gwL3rSAtctmIw==/split_lib_slice_7_apk.apk", zip file "/data/app/robertopinheiro_iotlab.pixelspeech-lVHD6wyC3gwL3rSAtctmIw==/split_lib_slice_8_apk.apk", zip file "/data/app/robertopinheiro_iotlab.pixelspeech-lVHD6wyC3gwL3rSAtctmIw==/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/robertopinheiro_iotlab.pixelspeech-lVHD6wyC3gwL3rSAtctmIw==/lib/x86, /system/lib, /vendor/lib]]] couldn't find "libMicrosoft.CognitiveServices.Speech.java.bindings.so"
at java.lang.Runtime.loadLibrary0(Runtime.java:1011)
at java.lang.System.loadLibrary(System.java:1657)
at com.microsoft.cognitiveservices.speech.SpeechConfig.<clinit>(SpeechConfig.java:44)
at com.microsoft.cognitiveservices.speech.SpeechConfig.fromSubscription(SpeechConfig.java:67)
at robertopinheiro_iotlab.pixelspeech.MainActivity.onSpeechButtonClicked(MainActivity.kt:33)
...
Это мой простой код MainActivity.kt
:
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
// Note: we need to request the permissions
val requestCode = 5 // unique code for the permission request
ActivityCompat.requestPermissions(this@MainActivity, arrayOf(RECORD_AUDIO, INTERNET), requestCode)
}
fun onSpeechButtonClicked(v: View) {
try {
//THE ERROR START HERE
val config = SpeechConfig.fromSubscription(speechSubscriptionKey, serviceRegion)!!
val reco = SpeechRecognizer(config)!!
val task = reco.recognizeOnceAsync()!!
// Note: this will block the UI thread, so eventually, you want to
// register for the event (see full samples)
val result = task.get()!!
if (result.reason == ResultReason.RecognizedSpeech) {
text.setText(result.toString())
} else {
text.setText("Error recognizing. Did you update the subscription info?" + System.lineSeparator() + result.toString())
}
reco.close()
} catch (ex: Exception) {
Log.e("SpeechSDKDemo", "unexpected " + ex.message)
assert(false)
}
}
companion object {
// Replace below with your own subscription key
private val speechSubscriptionKey = "YourSubscriptionKey"
// Replace below with your own service region (e.g., "westus").
private val serviceRegion = "YourServiceRegion"
}
}
Это базовый примерв документации Microsoft, что я могу сделать, чтобы решить эту проблему?