how to highlight text along with sound in android - android

I have a audio file and I want to read this text file with highlight the text.Can I do this.Please help me.

You might begin by reading some introductory documentation on the Text to Speech the Android class android.speech.tts.TextToSpeech at http://developer.android.com/reference/android/speech/tts/TextToSpeech.html
With this class you may have your app to easily speak from text. You just create an instance of the class, wait for it to complete its initialization, and speak. Something along this, just to get you started.
import com.google.tts.TTS;
...
private TTS myTts;
...
myTts = new TTS(this, ttsInitListener, true);
...
private TTS.InitListener ttsInitListener = new TTS.InitListener() {
public void onInit(int version) {
myTts.speak("Hello world", 0, null);
}
};
Things will get more complex when you try to change the "Hello world" by the actual text read from your text file while highlighting the text on screen. I leave it as an exercise for you.

Related

text widget integration in android

I want to integrate text widget in my application in android studio. I tried running the samples and they are working fine. Now i want to toast the digital text that appears after user input. I want to save that text somehere. I used this code in OnRecognitionEnd() function
#Override
public void onRecognitionEnd() {
String Result = mEditText.getText().toString();
Log.d(TAG, "result is: " +Result);
}
Now can you kindly tell me I want to display the text that is being stored in “Result” I used multiple ways but it says UNFORTUNETLY THE APPLICATION HAS STOPPED. For Example i simply did this
TextView textElement = null;
textElement.setText(Result);
Please tell me what I am doing wrong what should i do to display it ?
If you do this :
TextView textElement = null;
textElement.setText(Result);
You will try to setText on null. I suppose the error in your logcat is NullPointerException.
You have to instantiate your textElement.
TextView textElement=(TextView)findViewById(R.id.myid);
Where "myid" is the id in your layout.xml.

how to add an action to part of a string android

I have the fallowing text: "By clicking OK you will disable the service. Learn more".
i want to make "Learn more" clickable, however i want a popup menu to appear instead of directing to a website
i have used the fallowing stack question :
How to set the part of the text view is clickable
which worked great. i found the index of learn more by ". ". this solution crashes the application in Chinese and Hindi languages (in Hindi a point is written -> |).
How can i make the "Learn more" clickable in a generic way to show a popup menu?
Is there maybe a way to define the click action in strings.xml, like calling a link? (instead of calling a link -> launch popup menu?)
You can use WebView and anchor. Create new WebViewClient (especially you need this method: shouldOverrideUrlLoading()) and do everything you want when user will click your anchor.
You can create a click event based on the text as you defined.. Check this library.. it may help you.. https://github.com/klinker24/Android-TextView-LinkBuilder
solved it, might be a hack but it works fine.
in strings.xml i have added
//<a></a> tags to be removed later on
<string name="learn_more">By clicking OK you will disable the service. <a>Learn more</a></string>
in the code :
TextView textView= (TextView) findViewById(R.id.textViewInLayout);
textView.setMovementMethod(LinkMovementMethod.getInstance());
textView.setText(R.string.learn_more);
//indexes of the clickable text
int start = textView.getText().toString().indexOf("<a>");
int end = textView.getText().toString().indexOf("</a>");
//set the text as html to make the tags disappear
textView.setText(Html.fromHtml(getString(R.string.learn_more)));
//make the text clickable
Spannable spannable = (Spannable) textView.getText();
ClickableSpan myClickableSpan = new ClickableSpan() {
#Override
public void onClick(View widget) {
yourActionHere();
}
};
// end - 3 beacuse of </a>
spannable.setSpan(myClickableSpan, start, end - 3,Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);`

An existed Layout can not be resolved to a field

I have a customised view, and at certain moment of the game I am developing, I want to show a confirmation message to the user. For the confirmation message, I created a new xml file in the layout folder, and in the cistomised view og the game I am trying to refer to that layout as follows:
private void showConfirmation() {
LayoutInflater mLayoutInf = LayoutInflater.from(this.mContext);
View confMSG_View = mLayoutInf.inflater(R.layout.confirm_msg, null);
.....
.....
}
But, at this step, eclipse underscores the R.Layout.confirm_msg with red and says it can not be resolved to a field.
Please let me know what I am doing wrong here.

Optimization of my soundboard code

I think the best is to first say, that I recently started Android programming. Despite the fact of me getting better now, I can't seem to find good ways to optimize my piece of code.
I've written this piece of code. It's a soundboard. And when you long click a button you're able to save it as a ringtone, as a alarm, as a notification or share it with your friends. For every method I've made a string.
This string is set by the corresponding button to "btn1" till "btn20". After this I open the method (in the example below showSelectedSaveDialog(). And in that method I've made a if or if else statement to open the correct sound.
This way of coding makes a very long code. Because for every button I have to make an if else statement. Is there a better way to code kind codes? Is there a good tutorial, or something like that? Or someone who can post an example?
Setting the string:
ringToneManager = "btn1";
showSelectSaveDialog();
Setting the correct sound:
if (str.equals("btn1")) {
fIn = getSherlockActivity().getBaseContext().getResources()
.openRawResource(R.raw.sound01);
Starting the method to share the sound file
shareButton("btn14");
Getting the corresponding sound file
private void shareButton(String str) {
// SAVE THE FILE
byte[] buffer = null;
if (str.equals("btn1")) {
fIn = getSherlockActivity().getBaseContext().getResources()
.openRawResource(R.raw.sound01);
[...] etc
Thanks in advance! :)
You can simplify your code by using the "tag" property, available on all Views and widgets. The tag property is a general purpose container.
Load the tag property for each button with the id of the sound file associated with the button, this can be done on an activities onCreate:
findViewById(R.id.btn1).setTag(R.raw.sound01);
findViewById(R.id.btn2).setTag(R.raw.sound02);
//etc.
findViewById(R.id.btn20).setTag(R.raw.sound20);
Each button can now share the same onClick handler and all run the same piece of code, no ifs required:
public void onClick(View arg0) {
fIn = getSherlockActivity().getBaseContext().getResources().openRawResource((Integer)arg0.getTag());
}
Likewise change the shareButton method to take an integer instead of a string:
shareButton((Integer)arg0.getTag());
private void shareButton(int soundID) {
// SAVE THE FILE
byte[] buffer = null;
fIn = getSherlockActivity().getBaseContext().getResources().openRawResource(soundID);
[...] etc

Bengali unicoded character showing problem

I have created an android application where I want to display unicoded bengali sentences.
For this I have done the following steps.
Step1: I store my bengali font named Siyamrupali.ttf in the Assets folder.
Step2: In main.xml file I took a text view where I display characters.
Step3: In my MainActivity. Java I wrote this...
public class mainAc extends Activity
{
AssetManager arabi_font;
TextView tx;
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
tx=(TextView)findViewById(R.id.tv);
try
{
String str="\u0986";
tx.setTypeface(Typeface.createFromAsset(getAssets(),"Siyamrupali.ttf"));
tx.setText(str);
}
catch(Exception ex)
{
tx.setText("font cannot load: "+ ex.toString() );
}
}
Then output show আ Which one is correct But When i wrote String str="\u0986\u09AE\u09Bf";
In MainActivity. Java
Then output shows আমই But i should be আমি
What can I do now to solve this problem. Any body give me some advice or link or sample code.
\u0986\u09A\u09BF is not a valid unicode character. I am afraid why you didnot get error. please have a look on the following like
Unicode character of Bengali scripts
Thanks
Android doesn't have full complex text layout support for all of Unicode yet, and Bengali matras are one feature that isn't rendered right. See issue 5925. Sorry!

Categories

Resources