I'm learning android development for the first time and my goal is to create a simple Hello World application that takes in some text, and reads them out loud.
I've based my code off an example I found and here's my code:
class MainFeeds : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main_feeds)
card.setOnClickListener{
Toast.makeText(this, "Hello", Toast.LENGTH_LONG).show()
TTS(this, "Hello this is leo")
}
}
}
class TTS(private val activity: Activity,
private val message: String) : TextToSpeech.OnInitListener {
private val tts: TextToSpeech = TextToSpeech(activity, this, "com.google.android.tts")
override fun onInit(i: Int) {
if (i == TextToSpeech.SUCCESS) {
val localeUS = Locale.US
val result: Int
result = tts.setLanguage(localeUS)
if (result == TextToSpeech.LANG_MISSING_DATA || result == TextToSpeech.LANG_NOT_SUPPORTED) {
Toast.makeText(activity, "This Language is not supported", Toast.LENGTH_SHORT).show()
} else {
speakOut(message)
}
} else {
Toast.makeText(activity, "Initilization Failed!", Toast.LENGTH_SHORT).show()
}
}
private fun speakOut(message: String) {
tts.speak(message, TextToSpeech.QUEUE_FLUSH, null, null)
}
}
And it works perfectly fine, the issue that I'm running into is that the audio that's coming out of the synthesizer sounds extremely robotic, almost like when I'm using Google Maps and I get disconnected from the internet. Is using the voice Google Assistant leverages some other API that I have to enable?
EDIT: I've tried running the app on my pixel 2xl and it still sounds robotic, as in it's not using the Google Assistant voice.
from Android Text-To-Speech API Sounds Robotic
No comments:
Post a Comment