I'm experimenting with Google cloud speech to text service. It works OK, but I can't update the version of the google-cloud-speech. If I put more recent version instead of 0.41.0-alpha
it throws this error as soon as I try to launch it:
16681-16681/com.example.voice_test E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.voice_test, PID: 16681
java.lang.NoSuchMethodError: No direct method <init>(Ljava/lang/String;)V in class
Lio/grpc/internal/AbstractManagedChannelImplBuilder; or its super classes (declaration of
'io.grpc.internal.AbstractManagedChannelImplBuilder' appears in /data/app/com.example.voice_test-
dOPemX43m_vBjq_Tc8tk7w==/base.apk:classes3.dex)
How to fix this error?
Gradle dependecies for speech recognition:
implementation 'io.grpc:grpc-okhttp:1.10.0'
implementation 'com.google.cloud:google-cloud-speech:0.41.0-alpha'
Creating the speech client:
private val mSpeechClient by lazy {
applicationContext.resources.openRawResource(R.raw.credential).use {
SpeechClient.create(
SpeechSettings.newBuilder()
.setCredentialsProvider { GoogleCredentials.fromStream(it) }
.build())
}
}
OnCreate function. The speech recorder itself is using AudioRecord class, nothing special there.
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
mTextView = findViewById(R.id.last_recognize_result)
mSpeakButton = findViewById(R.id.button)
// get permissions
ActivityCompat.requestPermissions(this, PERMISSIONS, REQUEST_RECORD_AUDIO_PERMISSION)
val config = RecognitionConfig.newBuilder()
.setEncoding(RecognitionConfig.AudioEncoding.LINEAR16)
.setSampleRateHertz(16000)
.setLanguageCode(LANGCODE)
.build()
val audioRecorder = AudioRecorder()
val clicker: View.OnClickListener = View.OnClickListener {
val byteArrayAudio: ByteString = audioRecorder.record(5000)
val audio: RecognitionAudio = RecognitionAudio.newBuilder()
.setContent(byteArrayAudio).build()
val resultsList = mSpeechClient.recognize(config, audio).resultsList
for (result in resultsList) {
val resultText = result.alternativesList[0].transcript
mTextView.setText(resultText)
Log.d(TAG, "-- Transcription: %s".format(resultText))
}
}
mSpeakButton.setOnClickListener(clicker)
}