Android TTS API sounds robotic

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP


Android TTS API sounds robotic



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)

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?





You're probably using an emulator that doesn't have the google APIs installed and is therefore using the PICO engine. Is the device you're testing on the same device that you use for Google Assistant?
– Boober Bunz
9 hours ago





Ah no you're right I'm using an emulator and I did not try Google Assistant on the emulator itself. Do you happen to know which API I need installed? I believe I have level 27.
– Stupid.Fat.Cat
9 hours ago




1 Answer
1



The quality of speech first and foremost comes down to what "speech engine" is being used by the TextToSpeech object that you created:


private val tts: TextToSpeech = TextToSpeech(activity, this)



If you had instead entered:


private val tts: TextToSpeech = TextToSpeech(activity, this, "com.google.android.tts")



Then any device you run that code on will attempt to use the google speech engine... but it will only actually be used if it exists on the device.



Similarly, using "com.samsung.SMT" would attempt to use the Samsung speech engine (which is also high-quality, but usually only installed on Samsung [real] devices).



Whether or not the Google speech engine will be available is not so much dependent on the Android API level of the device (as long as it's recent enough to run the Google engine), but whether or not the actual Google text-to-speech engine is installed on the device at all.



To make sure that the Google engine is installed:



On an Android Studio Emulator:



Create a new emulator and select a system image that has "Google APIs" or "Google Play" in the "target" column.



On a real device:



Go to the Play Store and install the Google speech engine.



I'm currently writing a "TTS Diagnostics" app that I will post via Github when it's ready. I have learned that TTS on Android (or at least trying to predict its behavior) can be a real beast.



Also I suggest the documentation, of course: Java | Kotlin.






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Stripe::AuthenticationError No API key provided. Set your API key using “Stripe.api_key = ”

CRM reporting Extension - SSRS instance is blank

Keycloak server returning user_not_found error when user is already imported with LDAP