I'm using the pico default android TTS engine with IPA caracters doing this
String text3 = "<speak xml:lang=\"fr-FR\"> <phoneme alphabet=\"ipa\" ph=\"+"+words+"\"/>.</speak>";
myTTS.speak(text3, TextToSpeech.QUEUE_ADD, null);
It's generally working, but for some letters it doesn't like "ã" or "ɑ" etc.
So my question is, How can I add theses letters/sounds, to this TTS engine ?
Hey you can use addEarcon() to add sounds to testToSpeech link.
This medthod is used to add earcons.It will link a text to a speecific sound file.
You can also find example on this.
mTts = new TextToSpeech(this, new OnInitListener() {
#Override
public void onInit(int status) {
mTts.addEarcon("[tock]", "com.ideal.itemid", R.raw.tock_snd);
showRecordingView();
}
});
There is also a very good explanation on addEarcon in book Professional Android Sensor Programming by Greg Milette, Adam Stroud
at page no 366 and 367.
You can also find example on this link.
Related
I want my app to read out the message contained in the push notification.
I already searched the internet but I was not able to find some code which was working.
I expect that the text is translated to speech and automatically played.
If you need an easy approach, you can use SpeakerBox Library. It's very easy to use.
Just create a new instance
Speakerbox speakerbox = new Speakerbox(activity);
Now you are all set.
If you want to make a speech from the text "Hello World"
Just do this -
Speakerbox speakerbox = new Speakerbox(activity);
speakerbox.play("Hello World");
You will find more details from the mentioned link
The gradle dependency for this library is -
implementation 'com.mapzen.android:speakerbox:1.4.1'
you should use TextToSpeech within your notification class / service
TextToSpeech tts = new TextToSpeech(this, this);//(Context,TextToSpeech.OnInitListener)
tts.setLanguage(Locale.US);
tts.speak("Text to say aloud", TextToSpeech.QUEUE_ADD, null);
here is a link for more information about TextToSpeech
I have a class that uses the Android TTS API to transcribe text to audio. I can control the pitch and speed; but I noticed the engine requires a text string and also a hash object. I noticed some words are pronounced too quickly to be easily recognized, and inflection seems too unnatural. Is there a way I can control these two things; possibly through the HashMap? The following is how I'm using the engine:
mTts = new TextToSpeech(Globals.context, this); // context, listener
}
#Override
public void onInit(int status) {
HashMap<String, String> myHashRender = new HashMap();
myHashRender.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, speech);
mTts.setPitch(0.8f);
mTts.setSpeechRate(0.6f);
mTts.synthesizeToFile(speech, myHashRender, fileOutPath);
while (mTts.isSpeaking()) try {
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
mTts.stop();
mTts.shutdown();
Google TTS does not currently support that, but here is what you can do: During parsing of your text, you can change parts of it to get the intonation and inflection you want.
For example, if you encounter the word 'Hey' you rewrite it on the fly to 'Heeeey' before you send it to the TTS engine to get a different pronounciation.
It is not pretty but it is a workaround.
Google TTS does not currently support changing inflection, nor does it
support inline prosody tags as defined in SSML. - alanv Jun 5 at 20:30
Google TTS does not currently support changing inflection, nor does it support inline prosody tags as defined in SSML. While there are parameters you can set, none of them control inflection or per-word prosody.
There may be other engines that do support these features. eSpeak, for example, does support SSML tags and has an Android port available on Play Store.
I am learning to write an app that is intended to perform TTS on given strings, and have tried an example modified from web:
Coding as follows:
// setup TTS part 1
mTts = new TextToSpeech(Lesson2_dialog_revision_simple.this, this); // TextToSpeech.OnInitListener
speakBtn.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
StringTokenizer loveTokens = new StringTokenizer("他們 one two是 three ",",.");
int i = 0;
loveArray = new String[loveTokens.countTokens()];
while(loveTokens.hasMoreTokens())
{
loveArray[i++] = loveTokens.nextToken();
}
speakText();
}
});
}
// setup TTS part 2
#Override
public void onUtteranceCompleted(String utteranceId)
{
Log.v(TAG, "Get completed message for the utteranceId " + utteranceId);
lastUtterance = Integer.parseInt(utteranceId);
}
// setup TTS part 3
#Override
public void onInit(int status)
{
if(status == TextToSpeech.SUCCESS)
{
int result = mTts.setLanguage(Locale.CHINESE); // <====== set speech location
if(result == TextToSpeech.LANG_MISSING_DATA || result == TextToSpeech.LANG_NOT_SUPPORTED)
{
Toast.makeText(Lesson2_dialog_revision_simple.this, "Language is not supported", Toast.LENGTH_LONG).show();
speakBtn.setEnabled(false);
}
else
{
speakBtn.setEnabled(true);
mTts.setOnUtteranceCompletedListener(this);
}
}
}
// setup TTS part 4
private void speakText()
{
lastUtterance++;
if(lastUtterance >= loveArray.length)
{
lastUtterance = 0;
}
Log.v(TAG, "the begin utterance is " + lastUtterance);
for(int i = lastUtterance; i < loveArray.length; i++)
{
params.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, String.valueOf(i));
mTts.speak(loveArray[i], TextToSpeech.QUEUE_ADD, params);
}
}
Questions:
Everything is ok if the int result = mTts.setLanguage(Locale.US); in part 3 above is set as US and to read out "one two three" in English perfectly. (in the above example, it will skip all the chinese words and just read out one two three)
However, if I change the string to read out Chinese by setting language as setLanguage(Locale.CHINESE), it immediately toasts out that "Language is not supported".
I would like to ask
the current TTS still does not support Chinese? I would even more prefer Cantonese rather than Chinese.
The phone is ABLE to recognize Cantonese when I inputting messages via speech (Cantonese). Is it actually there are some other way to perform TTS with output being Cantonese?
Thanks!!
1 - The Google TTS Engine at its current version does not support Cantonese as output yet. Putonghua works fine.
2 - Ekho is a TTS Engine that supports Cantonese.
You might want to give a try on the TTS app I developed that works with Ekho and Google TTS Engine: Voice Out TTS
As far as I know there's no specific Locale in JAVA to distinguish between Cantonese or Putonghua because Cantonese is a Chinese dialect. The Locale in JAVA refers only to the writings (Simplified or Traditional).
For example you can read a string written in Traditional Chinese with Cantonese or Putonghua.
#Pearmak: you can check the language that are supported in your device
int i = mTts.isLanguageAvailable(Locale.ENGLISH);
where mTts is object of TextToSpeech
If you get the value of i >=0 then that language is supported on you device otherwise not.
You may also pass the language locale string.
int i = mTts.isLanguageAvailable(new Locale("zh_CN")); //for chinese simplified
Yue, a tiny Chinese text to speech (TTS) synthesis engine of Cantonese, Mandarin for offline embedded system. Yue is extremely small size, offline, independent, and PCM audio output no needs of server or network connection. It has high naturalness of synthesised voice for hybrid text input, the Cantonese and Mandarin speech synthesis for same text input, with Yale, Jyutping and Pinyin romanization. The engine can continues produce and play voice for long text, the length of the text without limit. It has build-in intelligent detecter that can handle any traditional Chinese, simplified Chinese, English, number and punctuations, symbol mixed text input. Yue is written in ANSI C, no dependent of third part library, running on ARM, AVR embedded system such as watch, toy, robot and iPhone, Android, … mobile platforms, of course normal desktops, ebook, news paper reader, story teller. Yue can be loaded into memory and embedded in other programs, because of its extremely small size, it is well suited to embedded systems, and is also suitable for desktop operating systems. The engine can have bindings for a large number of programming languages.
The link:http://www.sevenuc.com/en/tts.html
Google TTS recently added support for Cantonese (and also Mandarin). http://www.androidpolice.com/2015/07/24/google-tts-now-supports-four-new-languages-including-cantonese-and-mandarin/
some phones have the cantonese locale that you can use with TTS.
try
new Locale("yue", "HK"); //yue for 粤语
Once you have set the system language to Cantonese, then you can use setLanguage(Locale.getDefault()).
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);
//...
}
Android is providing a cool feature (from Android 1.6) called Text to Speech (TTS) which speaks the text in different languages. I have written a code on TTS. It is working fine. But now I want to set Language of TTS to "Bengali ". But TTS currently does not support "Bengali". Is there any way to set Language of TTS to "Bengali" .
tts = new TextToSpeech(TextToSpeechSultan.this,new TextToSpeech.OnInitListener() {
public void onInit(int status)
{
if(status != TextToSpeech.ERROR)
{
tts.setLanguage(Locale.US);
}
}
});
No, unfortunately Bengali or Hindi is not supported by Android. See the list of Locales supported below
http://developer.android.com/reference/java/util/Locale.html
Many other languages are also not supported by the looks of it.