If I start the app on an emulator and press the button I can hear the sound, but if it runs on the real device I don't hear any sound (volume level is ca. 80%):
...
t1 = new TextToSpeech(getActivity().getApplicationContext(), new TextToSpeech.OnInitListener() {
#Override
public void onInit(int status) {
if (status != TextToSpeech.ERROR) {
t1.setLanguage(Locale.UK);
Log.d("TTS", "ok");
} else {
Log.d("TTS", "error");
}
}
});
button1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
t1.speak("What is your name?", TextToSpeech.QUEUE_FLUSH, null);
}
});
...
According to the output in LogCat everything is fine, but I cannot hear any sound if I press the button:
I/TextToSpeech: Sucessfully bound to com.google.android.tts
I/TextToSpeech: Connected to ComponentInfo{com.google.android.tts/com.google.android.tts.service.GoogleTTSService}
TTS: ok
What can be the problem? Emulator API Level is 4.2.2, device - 4.2.1.
root#android:/ # ls /system/tts/lang_pico/
de-DE_gl0_sg.bin
de-DE_ta.bin
en-GB_kh0_sg.bin
en-GB_ta.bin
en-US_lh0_sg.bin
en-US_ta.bin
es-ES_ta.bin
es-ES_zl0_sg.bin
fr-FR_nk0_sg.bin
fr-FR_ta.bin
it-IT_cm0_sg.bin
it-IT_ta.bin
If your device doesn't have the language installed or doesn't support, it, obviously, can't play it. If it's anything but US, try that...!
does this helped?
Related
I've seen some posts that seem similar, but they're all fairly old and slightly different. I have an app whose codebase I have not touched in a long time. It makes use of the android SpeechRecognizer Service, and has a toggle for the EXTRA_PREFER_OFFLINE intent param. Previously this was working with no issues, but since I've recently dusted it off I noticed that offline functionality immediately returns with error code 7 NO_MATCH.
I have confirmed that offline language packs are installed, and wrote some stand alone code to test SpeechRecognizer outside my larger code base.
I've not been able to find any documented solutions for the NO_MATCH error, but surely it must occur elsewhere.
For context: This was previously working last year/earlier this year (I've seen people claim this wasn't possible after 2015/17) and on Android 8
Sample code snippet:
speechRecognizer = SpeechRecognizer.createSpeechRecognizer(getContext());
final Intent speechRecognizerIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
speechRecognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
speechRecognizerIntent.putExtra(RecognizerIntent.EXTRA_PARTIAL_RESULTS, true);
speechRecognizerIntent.putExtra(RecognizerIntent.EXTRA_PREFER_OFFLINE, true);
speechRecognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, "en-US");
speechRecognizer.setRecognitionListener(new RecognitionListener() {
#Override
public void onReadyForSpeech(Bundle bundle) {
listening = true;
label.setText(R.string.listening_true);
}
#Override
public void onBeginningOfSpeech() {
}
#Override
public void onRmsChanged(float v) {
}
#Override
public void onBufferReceived(byte[] bytes) {
}
#Override
public void onEndOfSpeech() {
label.setText(R.string.listening_false);
listening = false;
}
#Override
public void onError(int i) {
Log.e(TAG, "Error code " + i);
label.setText(R.string.listening_false);
listening = false;
}
#Override
public void onResults(Bundle bundle) {
ArrayList<String> data = bundle.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION);
if (data != null && data.size() > 0) {
resultsTextView.setText(data.get(0));
resultsTextView.setTextColor(getResources().getColor(R.color.colorAccent));
listening = false;
}
}
#Override
public void onPartialResults(Bundle bundle) {
ArrayList<String> data = bundle.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION);
if (data != null && data.size() > 0) {
Log.i(TAG, "how many partial results? " + data.size());
resultsTextView.setText(data.get(0));
resultsTextView.setTextColor(getResources().getColor(R.color.design_default_color_primary));
Log.i(TAG, "Partial results: " + data);
}
}
#Override
public void onEvent(int i, Bundle bundle) {
}
});
view.findViewById(R.id.button_mic).setOnClickListener(view1 -> {
if (!listening) {
speechRecognizer.startListening(speechRecognizerIntent);
} else {
speechRecognizer.stopListening();
}
});
Google app's voice input could work offline previously, but unfortunately, this feature has been removed since version 11 (released in March 2020).
Thus, to use this feature, we have to keep the version of Google app on device at 10.99.8 or older.
However, on some new device released after March 2020, the pre-installed version of Google app is already 11 or 12, so it is not a simple task to downgrade it to an older version.
So we need to use adb command to downgrade it from PC. This command will try to force downgrade the app for the 'current user': adb install -r -d --user 0 google.apk
The answer is that this is no loner supported. If you need a short term fix then go to your "Google", not "Google Play Services", app and uninstall updates from the hamburger menu. This seems to downgrade a lot of libraries, including the voice recognition stuff.
A possibility might be to manually bring and load your own libraries, but I haven't tested this personally.
I am using TextToSpeech in a background service. It works fine with my device speaker and now I want to play that audio on Bluetooth device but TTS doesn't allow me to do so. So is there any way to achieve this.
I also searched on the internet that how TTS worked on Bluetooth but I don't found anything.
My Code:
myTTS = new TextToSpeech(this, new TextToSpeech.OnInitListener() {
#Override
public void onInit(int i) {
if (myTTS.getEngines().size() == 0) {
Toast.makeText(AssistantService.this, "There is no TTS", Toast.LENGTH_SHORT).show();
} else {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
myTTS.setLanguage(Locale.forLanguageTag("hi-in"));
myTTS.setVoice(new Voice("hi-in-x-cfn#male_3-local", Locale.forLanguageTag("hi-in"), Voice.QUALITY_VERY_HIGH, Voice.LATENCY_NORMAL, false, null));
}
speak(" " + "Hello Sir, मै आप के लिए क्या कर सकता हूँ");
}
}
});
I'm trying to create an app which would use Google's TTS to read English, German and Russian texts. However currently it only speaks English. The device runs on Android 4.2.1 with Google TTS 3.10.9.
Below is the code I use for testing.
t1 = new TextToSpeech(getActivity().getApplicationContext(), new TextToSpeech.OnInitListener() {
#Override
public void onInit(int status) {
if (status != TextToSpeech.ERROR) {
t1.setLanguage(Locale.US);
// t1.setLanguage(Locale.GERMANY);
// t1.setLanguage(new Locale("ru"));
Log.d("TTS", "ok");
} else {
Log.d("TTS", "error");
}
}
});
button1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
t1.speak("What is your name?", TextToSpeech.QUEUE_FLUSH, null);
// t1.speak("Wie heisst du?", TextToSpeech.QUEUE_FLUSH, null);
// t1.speak("Как Вас зовут?", TextToSpeech.QUEUE_FLUSH, null);
}
});
When I run the same code on an emulator on Android 7 I can hear all the three languages being spoken.
I couldn't find any information which would help me to answer the question: Since which version does TTS support German and Russian? The wiki page only says that the support for Russian was added in 2014. The corresponding Google Play page doesn't have any information related to versions.
When I open the TTS page on Google Play with that device I only see "Installed" button.
The solution was to turn on Wi-Fi on the device and add German and Russian in "Settings -> Language & Input -> Google voice typing -> Voices". After that the languages were downloaded and the app worked as desired.
I am trying to test the TextToSpeach engine using the tutorial from here:Android TextToSpeach tutorial
My setup is AndroidStudio and I use a real device for testing the result.
So my app compiles fine, opens on my device just fine, I enter a text there and click on the button, but nothing happens.
No sound can be heard besides the click sound of the button
No error shows in the LogCat
No Toast is showing on my device
I have volume set on the tablet (so it's not that)
I tryed to change the tutorial to make it say a specific sentence (to avoid the editBox) still nobody talks
What is wrong here? Do I need some permissions set for this app to work properly? I assume I would get an error somewhere if that were so...
Please help.
Implement your main Activity class from TextToSpeech.OnInitListener
public class AndroidTextToSpeechActivity extends Activity implements
TextToSpeech.OnInitListener
Initialization
tts = new TextToSpeech(this, this);
btnSpeak = (Button) findViewById(R.id.btnSpeak);
txtText = (EditText) findViewById(R.id.txtText);
Button on click event
btnSpeak.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View arg0) {
speakOut();
}
}) ;
On Init
#Override
public void onInit(int status) {
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");
} else {
btnSpeak.setEnabled(true);
speakOut();
}
} else {
Log.e("TTS", "Initilization Failed!");
}
}
private void speakOut() {
String text = txtText.getText().toString();
tts.speak(text, TextToSpeech.QUEUE_FLUSH, null);
}
More Refrence :
http://www.androidhive.info/2012/01/android-text-to-speech-tutorial/
For Me its Working Well -Api Level 19
I had a read aloud menu option which was working fine with the API 15. But fails to work in the API 19. There is no error as such in the code but clicking on the menu doesn't lead to anything. Here is the code:
I have added this in the onCreate
mSpeech = new TextToSpeech(this, new TextToSpeech.OnInitListener() {
public void onInit(int status) {
if(status == TextToSpeech.SUCCESS)
result=mSpeech.setLanguage(Locale.US);
if(result==TextToSpeech.LANG_MISSING_DATA ||
result==TextToSpeech.LANG_NOT_SUPPORTED){
Log.e("error", "This Language is not supported");
}
}
});
And this is the code i run when the menu is clicked:
case R.id.read_aloud_menu_item:
System.out.println("goes into read aloud case");
System.out.println(TextToSpeech.ERROR);
mSpeech.speak("Hello, this is a sample data", TextToSpeech.QUEUE_FLUSH, null);