battle programming a forum for elite programmers with extreme will power to sharpen theire skills
 
HomeCalendarFAQSearchMemberlistUsergroupsRegisterLog in
Post new topic   Reply to topicShare
 

 customized TTS text to speech for kotlin android studio

Go down 
AuthorMessage
Moti Barski
super
super
Moti Barski

Posts : 356
Join date : 2011-08-02

customized TTS text to speech for kotlin android studio Empty
PostSubject: customized TTS text to speech for kotlin android studio   customized TTS text to speech for kotlin android studio EmptyTue Aug 20, 2019 9:15 pm

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

MainActivity kotlin :

Code:
package com.yotamarker.lgkotlin1

import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.content.IntentFilter
import android.media.MediaPlayer
import android.os.BatteryManager
import android.support.v7.app.AppCompatActivity
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 kotlinx.android.synthetic.main.activity_main.*
import kotlinx.android.synthetic.main.activity_main.view.*
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","")
            mbTTS.voiceIt(b8TRiStr)
            //voiceIt(b8TRiStr)
            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
            //txtBox.setText("$usbCharge")
        }
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        tts = TextToSpeech(this, this)
        supportActionBar?.hide()
        this.registerReceiver(this.mBatInfoReceiver, IntentFilter(Intent.ACTION_BATTERY_CHANGED));
    }
    fun clrText(view: View){
        editText.setText("")
    }
    fun engage(view: View){
        //speakOut()
        if (spoke){editText.setText("");spoke = false}
        val str1 = editText.text.toString()
        var resultStr = chii.doIt(str1,"","")
        editText.setText(resultStr)
        mbTTS.voiceIt(resultStr)
        if (mbTTS.TTS){speakOut(resultStr)}
        if (!resultStr.isEmpty()){spoke = true}
        //editText.setText("")
        //voiceIt(resultStr)
    }
    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) {
            tts!!.stop()
            tts!!.shutdown()
        }
        super.onDestroy()
    }
}

and add also the attached TTSVoice kotlin file

chii ryu ranger

_________________
MB over and out emp it up
Back to top Go down
View user profile
Admin
Admin
Admin
Admin

Posts : 129
Join date : 2011-08-01

customized TTS text to speech for kotlin android studio Empty
PostSubject: TTSVoice kotlin class   customized TTS text to speech for kotlin android studio EmptyTue Aug 20, 2019 9:41 pm

attached is the TTSVoice kotlin class moti barski has made

krebskulm  life fuel  it is on
Attachments
customized TTS text to speech for kotlin android studio AttachmentTTSVoice kotlin 200819.txt
moti barskis TTSVoice kotlin class
(60 Kb) Downloaded 9 times

_________________
kurayami no kagi :TO:
Back to top Go down
View user profile http://yotamarker.forumotion.com
Moti Barski
super
super
Moti Barski

Posts : 356
Join date : 2011-08-02

customized TTS text to speech for kotlin android studio Empty
PostSubject: demo of the custom TTS   customized TTS text to speech for kotlin android studio EmptyTue Aug 20, 2019 9:47 pm

https://streamable.com/840ht

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

_________________
MB over and out emp it up
Back to top Go down
View user profile
 
customized TTS text to speech for kotlin android studio
Back to top 
Page 1 of 1

Permissions in this forum:You can reply to topics in this forum
battle programmers alliance :: battle programming alliance :: the LivinGrimoire-
Post new topic   Reply to topicJump to: