Pass language to voice search
This commit is contained in:
@@ -5,12 +5,16 @@ import android.content.Context
|
|||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.speech.RecognizerIntent
|
import android.speech.RecognizerIntent
|
||||||
import androidx.activity.result.contract.ActivityResultContract
|
import androidx.activity.result.contract.ActivityResultContract
|
||||||
|
import androidx.core.os.ConfigurationCompat
|
||||||
|
import java.util.Locale
|
||||||
|
|
||||||
class VoiceInputContract : ActivityResultContract<String?, String?>() {
|
class VoiceInputContract : ActivityResultContract<String?, String?>() {
|
||||||
|
|
||||||
override fun createIntent(context: Context, input: String?): Intent {
|
override fun createIntent(context: Context, input: String?): Intent {
|
||||||
val intent = Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH)
|
val intent = Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH)
|
||||||
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM)
|
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM)
|
||||||
|
val locale = ConfigurationCompat.getLocales(context.resources.configuration).get(0) ?: Locale.getDefault()
|
||||||
|
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, locale.toLanguageTag())
|
||||||
intent.putExtra(RecognizerIntent.EXTRA_PROMPT, input)
|
intent.putExtra(RecognizerIntent.EXTRA_PROMPT, input)
|
||||||
return intent
|
return intent
|
||||||
}
|
}
|
||||||
@@ -23,4 +27,4 @@ class VoiceInputContract : ActivityResultContract<String?, String?>() {
|
|||||||
null
|
null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user