Text to speech not working on Head Unit and DHU - android

I am trying to implement Text-to-speech in my android auto app but unable to hear it on Desktop head unit. I have also tried it on Car Head unit but no luck.
below is the code i am using
TextToSpeech tts=new TextToSpeech(getApplicationContext(), new TextToSpeech.OnInitListener() {
#Override
public void onInit(int status) {
if(status != TextToSpeech.ERROR) {
t1.setLanguage(Locale.UK);
}
}
});
and on button click i am using
tts.speak(toSpeak, TextToSpeech.QUEUE_FLUSH, null);
also tried to turn OFF Bluetooth Headset as suggested in xda forums
but still same issue.
Do i need to add any extra library like "gear.aar" to make it work for Auto as the code is in CarActivity

speak() method requires four parameters to execute the job
I solved this using below code
tts.speak(readText, TextToSpeech.QUEUE_ADD, null, ""+Calendar.getInstance().getTimeInMillis());

I had the same problem.
This is what should be done:
be sure you call tts.speak(...) after TTS is initialized (return 0 - SUCCESS)
turn off bluetooth on the computer

Related

Is it possible to playback some text using Google Assistant?

I have an android app with a custom intent that is fired by the Google Assistant with some text like "open my app and activate some action" (for example, "open clients database and sort clients").
All this is done very well but I would like to add some speech once the job is done, maybe a "job done" text or more specific "clients list is now sorted".
Is this possible with the Assistant. Can we send back a result for it to speak it?
I haven't found any solution on playing voice using the Assistant but I could play voice using TextToSpeech.speak. Very simple.
TextToSpeech oTextToSpeech=new TextToSpeech(getApplicationContext(), new TextToSpeech.OnInitListener() {
#Override
public void onInit(int status) {
if(status != TextToSpeech.ERROR) {
oTextToSpeech.speak("Hello this is a test", TextToSpeech.QUEUE_ADD, null);
}
}
});
The only problem is that I cannot use the same voice but it works very well and it is very simple.

Do Android Wearables support text-to-speech?

I am trying to follow this tutorial for my Android wearables app:
https://www.sitepoint.com/using-android-text-to-speech-to-create-a-smart-assistant/
Here is the code for my Activity file:
import android.speech.tts.TextToSpeech;
public class ScoresActivity extends Activity {
private TextToSpeech tts;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_scores);
// Text to speech setup
tts = new TextToSpeech(this, new TextToSpeech.OnInitListener() {
#Override
public void onInit(int status) {
System.out.println("status: " + status); // Always returns -1
if (status == TextToSpeech.SUCCESS) {
int result = tts.setLanguage(Locale.US);
if (result == TextToSpeech.LANG_MISSING_DATA || result == TextToSpeech.LANG_NOT_SUPPORTED) {
Log.e("TTS", "This Language is not supported");
}
speak("Hello");
} else {
Log.e("TTS", "Initilization Failed!");
}
}
});
}
I always see this error message in the Logs:
Is it even possible to run the Android SDK's text-to-speech library on wearable devices? I tried running this code on a mobile Android app and everything worked fine.
Yes this is possible as they even have docs for this feauture in Adding Voice Capabilities:
Voice actions are an important part of the wearable experience. They let users carry out actions hands-free and quickly. Wear provides two types of voice actions:
System-provided These voice actions are task-based and are built into the Wear platform. You filter for them in the activity that you
want to start when the voice action is spoken. Examples include "Take
a note" or "Set an alarm".
App-provided These voice actions are app-based, and you declare them just like a launcher icon. Users say "Start " to use these voice
actions and an activity that you specify starts.
You can also check this SO post for additional reference.
Depends which device you have. I think it needs to have android wear 2.0 and then possibly a speaker would make it more likely. Im only saying that based on knowing my nixon mission does not have tts installed but the lg urbane 2 does. Very annoying as tts could be used over bluetooth.
Would be good to get a full listed of supported devices.

Turning notifications to text-to-speech when driving

I have an application that according to some events, changes a normal notification to text-to-speech in order to since sometimes the phone isn't available to users, and it'll be safer not to handle the phone.
For example, when you're driving, this is dangerous, so i want to turn the notifications to text-to-speech.
I've looked for a long time some explanation for turning text-to-speech when driving, but i can't find any reference for that no where i search.
For generating text-to-speech, i have this part, which works fine :
private TextToSpeech mTextToSpeech;
public void sayText(Context context, final String message) {
mTextToSpeech = new TextToSpeech(context, new TextToSpeech.OnInitListener() {
#Override
public void onInit(int status) {
try {
if (mTextToSpeech != null && status == TextToSpeech.SUCCESS) {
mTextToSpeech.setLanguage(Locale.US);
mTextToSpeech.speak(message, TextToSpeech.QUEUE_ADD, null);
}
} catch (Exception ex) {
System.out.print("Error handling TextToSpeech GCM notification " + ex.getMessage());
}
}
});
}
But, i don't know how to check if i'm currently driving or not.
As Ashwin suggested, you can use Activity recognition Api, but there's a downside of that, the driving samples you'll receive, has a field of 'confidence' which isn't always accurate, so you'll have to do extra work(such as check locations to see if you actually moved) in order to fully know if the user moved.
You can use google's FenceApi which allows you to define a fence of actions such as driving, walking, running, etc. This api launched recently. If you want a sample for using it, you can use this answer.
You can pull this git project (everything free), which does exactly what you want : adds to the normal notification a text-to-speech when you're driving.
In order to know whether you are driving or not you can use Activity Recognition API
Here is a great tutorial that might help you out Tutorial and Source Code

Hindi Text To Speak Issue

I have referred speak-with-tts-such-as-hindi
and i have done like this:
extToSpeech text2speechHi;
text2speechHi=new TextToSpeech(getApplicationContext(), new TextToSpeech.OnInitListener() {
#Override public void onInit(int status) {
if(status != TextToSpeech.ERROR) {
text2speechHi.setLanguage(new Locale("hin"));
}
}
});
text2speechHi.speak(getResources().getString(R.string.hindi_text), TextToSpeech.QUEUE_FLUSH, null);
But still not reading....
how to see the output ? whether change any device setting in which i run the code?? or need to install anything??
what is this eSpeak they have mention in that link...any other free option available?? Any one who implemented this successfully????
It is working in fine for English text2speech.setLanguage(Locale.UK);
You are calling speak() before initialization is done, i.e., before onInit is called, consequently setLanguage hasn't been called yet. Refactor your code to follow the asynchronous pattern, by e.g. moving speak() into the onInit method.
EDIT: OP says code snippet in question is not representative of the actual code. Awaiting clarification before removing or updating answer.

Android TextToSpeech addSpeech() is not working

I have an HD Desire phone with android 2.3.
The TTS is working fine and it speaks every text I give. But when I use this either of the lines below to set my own voice for some texts, it simply ignores it and synthesizes the text, just like the line is not written!
tts.addSpeech("salam", "/sdcard/salam.wav");
tts.addSpeech("shalam", "com.company.appname", R.raw.shalam);
...
tts.speak("salam", TextToSpeech.QUEUE_FLUSH, null); //<--This isn't playing my voice file.
tts.speak("shalam", TextToSpeech.QUEUE_FLUSH, null); //<--Neither is this
I am sure of the existence of both files.
Why is that? Is there any restriction on the sound files? For example on their Frequency, or being mono or stereo?
I already checked the docs and saw nothing related.
OK, I found my problem, very silly situation which wasted several hours of mine!! I hope it will help if someone makes my mistake.
We should postpone this mapping of texts to the point TTS is successfully initialized, for example in onInit function:
#Override
public void onInit(int status) {
if(status == TextToSpeech.SUCCESS)
{
tts.setLanguage(Locale.US);
mapVoices();
}
else
...
}
private void mapVoices()
{
tts.addSpeech("salam", "/sdcard/salam.wav");
tts.addSpeech("shalam", "com.company.appname", R.raw.shalam);
//...
}

Categories

Resources