I have a working text to speech but I was wondering instead of a female voice when the app calls it to be played it will do a male voice instead?
It is now possible to use male/female voice and change it from App UI dynamically. Define TTS like this (add google tts engine in constructor):
tts = new TextToSpeech(context, this, "com.google.android.tts");
contex = activity/app
this= TextToSpeech.OnInitListener
From tts.getVoices() list, chose your desired voice by it's name like this:
for (Voice tmpVoice : tts.getVoices()) {
if (tmpVoice.getName().equals(_voiceName)) {
return tmpVoice;
break;
}
}
N.B: U need to set _voiceName by getting hard coded voice_name from tts.getVoices(). e.g: for English male it would be: "en-us-x-sfg#male_1-local"
It is possible to change voice into male
here is my code,hope it will help you!
//onCreate
T2S= new TextToSpeech(testApp.getInstance().getApplicationContext(), this, "com.google.android.tts");
Set<String> a=new HashSet<>();
a.add("male");//here you can give male if you want to select male voice.
Voice v=new Voice("en-us-x-sfg#male_2-local",new Locale("en","US"),400,200,true,a);
T2S.setVoice(v);
T2S.setSpeechRate(0.8f);
implements TextToSpeech.OnInitListener on Activity.
#Override
public void onInit(int status) {
if (status == TextToSpeech.SUCCESS) {
Set<String> a=new HashSet<>();
a.add("male");//here you can give male if you want to select male voice.
//Voice v=new Voice("en-us-x-sfg#female_2-local",new Locale("en","US"),400,200,true,a);
Voice v=new Voice("en-us-x-sfg#male_2-local",new Locale("en","US"),400,200,true,a);
T2S.setVoice(v);
T2S.setSpeechRate(0.8f);
// int result = T2S.setLanguage(Locale.US);
int result = T2S.setVoice(v);
if (result == TextToSpeech.LANG_MISSING_DATA
|| result == TextToSpeech.LANG_NOT_SUPPORTED) {
Log.e("TTS", "This Language is not supported");
} else {
// btnSpeak.setEnabled(true);
speakOut(mMessageVoice);
}
} else {
Log.e("TTS", "Initilization Failed!");
}
}
And add this function also:
private void speakOut(String message) {
t1.speak(message, TextToSpeech.QUEUE_FLUSH, null);
}
You cannot make the Android TextToSpeech sounds like a male. If you change the TextToSpeech.setPitch() value to something low, like 0.1, it will sound very bad.
Your only option is to try another Text-to-Speech engine, or live with the female sounding voice.
That depends on the underlying TTS engine. Some are configurable and have different voices (male, female, etc.), some only have one voice. In any case, you cannot control this from your app, the user has to change the TTS engine settings from the Settings app. You could only instruct them to install a particular engine, and setup your app to use it.
Contrary to some previous answers, gender is not a parameter (or even a "feature") of a Voice object.
As you can see... as of 5/2021, there is no "isMale" boolean parameter.
There is a "features" Set<String> parameter, but what those strings actually contain is engine dependent and extremely poorly documented and/or implemented... and no engines describe gender using this parameter that I know of.
TextToSpeech.setVoice() is designed such that the Voice being set must be an exact match/instance of one of the Voice objects that was previously returned by TextToSpeech.getVoices() -- it is not a way to somehow create/request a new custom Voice or to attempt to mix and match parameters. (That's not to say some engines won't try to make a best approximation of the non-existent new voice you try to send to it).
Even if gender were implemented, Voice parameters are not designed to be independently settable.
Voice objects are a means by which an engine can describe its available voices using getVoices() -- they are not the voices themselves.
As far as I can tell, the Voice class' constructor is really not useful to anyone other than a speech engine developer.
All of this means that unless the authors of a specific engine have chosen to include "male" or "female" as a substring of the voice's name, there is no way for you to determine whether a voice sounds male or female other than listening to it first.
So, in order to control whether speech output "is" male/female, all the following would have to be true:
you already know the unique voice name (String) you are looking for
the engine that contains that voice is installed on the users device (not in your control)
the installed version of that engine is recent enough to contain that voice (not in your control)
the installed version of that engine is not too recent so as to no longer contain that voice (not in your control)
the user has that particular voice installed (not in your control)
if the voice is not installed, the user is connected to the internet (not in your control)
PS - Even if you think you've found a male voice, it could actually be a female that just sounds male to you. :)
PPS - You could use a cloud service instead to remove all the device unpredictability.
It is possible to change voice into male. Set in onCreate(): tts.setEngineByname("com.google.android.tts") and make the google tts service default in text to speech settings and instaling the male voice in google tts service.
Like this you can use any third party android tts services and check the device. Or ask to install.
Either way you can set your android Text-to-Speech to google TTS service by :
tts = new TextToSpeech(context, this, "com.google.android.tts"), or
Install new male ( English ) voice and set it by default in android.
Hope it helps.
I found 3 Male voices in google tts
en-in-x-ene-network
en-in-x-end-network
hi-in-x-hie-local
Use these in the following way:
textToSpeechEngine.voice = Voice("hi-in-x-hie-local", Locale("hi_IN"), 400, 200, false, HashMap<String>())
Related
My Android app features a text input box that has a button on the right of the EditText to call the voice-input feature.
I am porting the app with Codename One. At present time the iOS port is the goal.
The button has a suitable icon. This is the code:
voiceInputButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent voiceIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
voiceIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_WEB_SEARCH);
try {
activity.startActivityForResult(voiceIntent, RESULT_SPEECH_REQUEST_CODE);
} catch (ActivityNotFoundException ex) {
}
}
});
It works very well, the voice-input screen is called and then the result is passed back to the app as a string.
The string is what the user said (for example, a single word).
I need to have this functionality in the CodenameOne app for iOS.
What should be the equivalent? Is it necessary to call native iOS functions, through the native interface?
You can implement speech-to-text via Speech framework, to perform speech recognition on live or prerecorded audio. More info: https://developer.apple.com/documentation/speech
About Codename One, you can create a native interface using Objective-C code.
To use the Speech framework with Objective-C, see this answer:
https://stackoverflow.com/a/43834120
The answer says so: «[...] To get this running and test it you just need a very basic UI, just create an UIButton and assign the microPhoneTapped action to it, when pressed the app should start listening and logging everything that it hears through the microphone to the console (in the sample code NSLog is the only thing receiving the text). It should stop the recording when pressed again. [...]». This seems very close to what you asked.
Obviously the creation of the native interface takes time. For further help, you can ask more specific questions, I hope I have given you a useful indication.
Lastly, there are also alternative solutions, again in Objective-C, such as: https://github.com/Azure-Samples/cognitive-services-speech-sdk/tree/master/quickstart/objectivec/ios/from-microphone
You can search on the web for: objective-c speech-to-text
I got this simple problem whenever I say "search music click" its searching for 'search music click' too it's supposed to search my music file name click. I tried to put different variables but only boolean is the one that not causing an error.
if(voice_result.indexOf("search music") != -1){
voice_result.contains(voice_result)
String a = voice_result;
Intent intent = new Intent(MediaStore.INTENT_ACTION_MEDIA_PLAY_FROM_SEARCH);
intent.putExtra(MediaStore.EXTRA_MEDIA_FOCUS, MediaStore.Audio.Media.ENTRY_CONTENT_TYPE);
intent.putExtra(SearchManager.QUERY, a);
startActivity(intent);}
the voice_result here is the process result of my voice and if ever I try to search a music from voice command it always search "search music risky" instead of "risky".
You should write a parser/filter for whatever returned from the voice recognition api first. For example, you say "search music risk":
Remove unnecessary or confusing strings like "search" "music" from the raw data. I suggest you use regex matcher and map the with a set of commands with values.
After filtering the raw data (now only has "risk"), use the result for next job
I am trying to write a simple piece of code that will execute some other code if true. What I want to do is check if my app is running on the 'Amazon Fire-TV (BOX, not the Fire-TV stick)' I think it would not be that hard to do but I am guessing it would be something like this?
String osName = android.getSystemOS();
if(!osName.equals("AMAZON FIRE-TV")){
Toast.makeText(MainActivity.class, "This app may not be compatible with your device..., Toast.LENGTH_LONG").show();
...
}
You can check any device name specifically using:
boolean isFireTV = Build.MODEL.equalsIgnoreCase("AFTB");
(see this page for FireTV model strings, and this one for Fire Tablets)
I'd also check out this answer for a more generic test to help you determine if your app is running on an Amazond device, or installed via the Amazon AppStore (eg on a Blackberry device)
the following function:
public static boolean isTV() {
return android.os.Build.MODEL.contains("AFT");
}
should detect either firetv or fire tv stick
see
https://developer.amazon.com/public/solutions/devices/fire-tv/docs/amazon-fire-tv-sdk-frequently-asked-questions
for details
I need to play Alert.startAudio() through the loudspeaker of a Blackberry device instead of the headset.
I know that I can change the Audio path through the AudioPathControl interface, but I don't know how to get an instance of AudioPathControl.
I found a LINK on how to do it on the Blackberry Knowledge base, but it only tells me how to do it using the Player class, which I don't want to do. Is there any way to get an instance of AudioPathControl of the current Application?
I would prefer to play a tone programmatically instead of including my own sound file. I found the following code snippet for that.
Player p = javax.microedition.media.Manager.createPlayer(javax.microedition.media.Manager.TONE_DEVICE_LOCATOR);
p.realize();
ToneControl tc = (ToneControl) p.getControl("ToneControl");
AudioPathControl apc = (AudioPathControl) p
.getControl("AudioPathControl");
apc.setAudioPath(AudioPathControl.AUDIO_PATH_HANDSFREE);
tc.setSequence(mySequence);
p.start();
But the problem is that apc is null and throws an Exception. Any solution?
Check the section Where Does the Sound Go? (preview from Google Books), from Advanced BlackBerry 6 Development By Chris King.
I am working on an android application that uses the TextToSpeech functionality provided by google and have followed this example:
TTS Example from Google
I want to know with this line:
int result = mTts.setLanguage(Locale.US);
if (result == TextToSpeech.LANG_MISSING_DATA ||
result == TextToSpeech.LANG_NOT_SUPPORTED) {
// Lanuage data is missing or the language is not supported.
}
What can I do if the Language data is missing off the users device? The app will not continue if the data is not there? Is there a way to allow the user to get the language on their device? I have a test device that seems to not have any languages on it at all.
From http://developer.android.com/resources/articles/tts.html:
// missing data, install it
Intent installIntent = new Intent();
installIntent.setAction(
TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA);
startActivity(installIntent);
No good way to know exactly what happens if the language they want simply doesn't exist at all, but....that is the recommended way of dealing with it.