battle programmers alliance
Would you like to react to this message? Create an account in a few clicks or log in to continue.

battle programmers allianceLog in

the LivinGrimoire Artificial General Intelligence software design pattern forum

descriptioncustomized TTS text to speech for kotlin android studio Emptycustomized TTS text to speech for kotlin android studio

I built it specifically for the livingrimoire but it works for kotlin android studio projects in

MainActivity kotlin :


package com.yotamarker.lgkotlin1

import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.content.IntentFilter
import android.os.BatteryManager
import android.os.Bundle
import android.speech.tts.TextToSpeech
import android.text.TextUtils.substring
import android.util.Log
import android.view.View
import android.view.Window
import java.nio.file.Files.size
import java.util.*

class MainActivity : AppCompatActivity() , TextToSpeech.OnInitListener{
    private var tts: TextToSpeech? = null
    var chii = Chobit()
    var spoke = false
    var mbTTS = TTSVoice(this)
    private val mBatInfoReceiver = object : BroadcastReceiver() {
        override fun onReceive(ctxt: Context, intent: Intent) {
            val level = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, 0)
            val b8TRiStr = chii.doIt("","$level charge","")
            if (b8TRiStr != ""){editText.setText(b8TRiStr)}
            //editText.setText(chii.doIt("","$level charge",""))
            //txtBox.setText("$level% $b8TRcounter")
            val status: Int = intent.getIntExtra(BatteryManager.EXTRA_STATUS, -1)
            val isCharging: Boolean = status == BatteryManager.BATTERY_STATUS_CHARGING
                    || status == BatteryManager.BATTERY_STATUS_FULL

            val chargePlug: Int = intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1)
            val usbCharge: Boolean = chargePlug == BatteryManager.BATTERY_PLUGGED_USB
            val acCharge: Boolean = chargePlug == BatteryManager.BATTERY_PLUGGED_AC

    override fun onCreate(savedInstanceState: Bundle?) {
        tts = TextToSpeech(this, this)
        this.registerReceiver(this.mBatInfoReceiver, IntentFilter(Intent.ACTION_BATTERY_CHANGED));
    fun clrText(view: View){
    fun engage(view: View){
        if (spoke){editText.setText("");spoke = false}
        val str1 = editText.text.toString()
        var resultStr = chii.doIt(str1,"","")
        if (mbTTS.TTS){speakOut(resultStr)}
        if (!resultStr.isEmpty()){spoke = true}
    override fun onInit(status: Int) {

        if (status == TextToSpeech.SUCCESS) {
            // set US English as language for tts
            val result = tts!!.setLanguage(Locale.US)

            if (result == TextToSpeech.LANG_MISSING_DATA || result == TextToSpeech.LANG_NOT_SUPPORTED) {
                Log.e("TTS","The Language specified is not supported!")
            } else {
                //buttonSpeak!!.isEnabled = true

        } else {
            Log.e("TTS", "Initilization Failed!")

    private fun speakOut(leftOver:String) {
        tts!!.speak(leftOver, TextToSpeech.QUEUE_FLUSH, null,"")
    public override fun onDestroy() {
        // Shutdown TTS
        if (tts != null) {

and add also the attached TTSVoice kotlin file

:chii: :ryu ranger:

descriptioncustomized TTS text to speech for kotlin android studio Empty TTSVoice kotlin class

attached is the TTSVoice kotlin class moti barski has made

:krebskulm:  :LF:  :ON:

moti barskis TTSVoice kotlin class

You don't have permission to download attachments.

(60 Kb) Downloaded 195 times

descriptioncustomized TTS text to speech for kotlin android studio Emptydemo of the custom TTS


notice if a voice file missing she will use the auxiliary default text to speech

descriptioncustomized TTS text to speech for kotlin android studio Emptyupdate

see GitHub for ver with phone numbers added

TTSVoice 071019

privacy_tip Permissions in this forum:
You cannot reply to topics in this forum
power_settings_newLogin to reply