hiteshsahu / Android-TTS-STT

One line solution for Android Text to speech(TTS) & Speech to Text(STT) translation problem
103 stars 40 forks source link

Don't use it - it supports only english #5

Open superzebra2 opened 5 years ago

superzebra2 commented 5 years ago

and i was trying to modify libs to add support of multi language for tts and voice recognition - but it is hard

hiteshsahu commented 5 years ago

Change language in intent,


class SpeechToTextConverter(private val conversionCallback: ConversionCallback)  : TranslatorFactory.IConverter {
    private   val  TAG = SpeechToTextConverter::class.java.name
    override fun initialize(message: String, appContext: Activity): SpeechToTextConverter {
        val intent = Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH)
        intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
                RecognizerIntent.LANGUAGE_MODEL_FREE_FORM)
        intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, Locale.getDefault())

example for chinease

intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, "zh-cmn");

hiteshsahu commented 5 years ago

For Text to speech

Replace

textToSpeech!!.language = Locale.getDefault()

in


override fun initialize(message: String, appContext: Activity): TranslatorFactory.IConverter {
        textToSpeech = TextToSpeech(appContext, TextToSpeech.OnInitListener { status ->
            if (status != TextToSpeech.ERROR) {
                textToSpeech!!.language = Locale.getDefault()

with your local example chinese:

textToSpeech!!.language =new Locale("zh-cmn");

ahmedbilal205 commented 1 year ago

what if we want to change languages at runtime