Skip to content

Commit

Permalink
ASR uses input language #2
Browse files Browse the repository at this point in the history
  • Loading branch information
krabatom committed Apr 10, 2022
1 parent ff81801 commit d27dabd
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@ import android.content.Context
import android.content.Intent
import android.speech.RecognizerIntent
import androidx.activity.result.contract.ActivityResultContract
import cz.cuni.mff.ufal.translator.ui.translations.models.Language

/**
* @author Tomas Krabac
*/
class VoiceContract : ActivityResultContract<Unit, String?>() {
class VoiceContract(val language: Language) : ActivityResultContract<Unit, String?>() {

override fun createIntent(context: Context, input: Unit): Intent {
return Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH)
.putExtra(
RecognizerIntent.EXTRA_LANGUAGE_MODEL,
RecognizerIntent.LANGUAGE_MODEL_FREE_FORM
)
return Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH).apply {
putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM)
putExtra(RecognizerIntent.EXTRA_LANGUAGE, language.locale.language)
}
}

override fun parseResult(resultCode: Int, intent: Intent?): String? {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ fun ActionsRow(
) {
val isSpeechRecognizerAvailable = viewModel.isSpeechRecognizerAvailable
val isTextToSpeechAvailable by viewModel.isTextToSpeechAvailable.collectAsState()
val inputLanguage by viewModel.inputLanguage.collectAsState()

val voiceLauncher = rememberLauncherForActivityResult(VoiceContract()) { text ->
val voiceLauncher = rememberLauncherForActivityResult(VoiceContract(inputLanguage)) { text ->
if (text != null) {
viewModel.setInputText(InputTextData(text, TextSource.Voice))
}
Expand Down

0 comments on commit d27dabd

Please sign in to comment.