Comments (1)
package com.example.texttospeechexample;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.speech.tts.TextToSpeech;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import java.util.Locale;
public class MainActivity extends AppCompatActivity implements TextToSpeech.OnInitListener {
private static final int TTS_ENGINE_REQUEST =101;
private TextToSpeech textToSpeech;
private EditText TextForSpeech;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextForSpeech = (EditText)findViewById(R.id.speech_text);
}
public void performSpeech(View view) {
Intent checkIntent = new Intent();
checkIntent.setAction(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA);
startActivityForResult(checkIntent,TTS_ENGINE_REQUEST);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == TTS_ENGINE_REQUEST && resultCode == TextToSpeech.Engine.CHECK_VOICE_DATA_PASS) {
textToSpeech = new TextToSpeech(this, this);
} else {
Intent installIntent = new Intent();
installIntent.setAction(TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA);
startActivity(installIntent);
}
}
@Override
public void onInit(int status) {
if (status==TextToSpeech.SUCCESS){
int languageStatus = textToSpeech.setLanguage(Locale.US);
if (languageStatus==TextToSpeech.LANG_MISSING_DATA || languageStatus==TextToSpeech.LANG_NOT_SUPPORTED){
Toast.makeText(this, "Language is not Support..", Toast.LENGTH_SHORT).show();
}else {
String data = TextForSpeech.getText().toString();
int speechStatus = textToSpeech.speak(data,TextToSpeech.QUEUE_FLUSH,null);
if (speechStatus==TextToSpeech.ERROR){
Toast.makeText(this, "Error while Speech..", Toast.LENGTH_SHORT).show();
}
}
}else{
Toast.makeText(this, "Text to speech engine failed..", Toast.LENGTH_SHORT).show();
}
}
}
from softenido.
Related Issues (20)
- [wifix][0.3.2] Can't send FeedBack HOT 2
- [audible][0.3.0] java.lang.NullPointerException in com.softenido.audible HOT 2
- [audible][0.4.0]java.lang.NullPointerException in com.softenido.audible HOT 2
- [audible][0.4.0]java.lang.NullPointerException in com.softenido.audible HOT 1
- [audible][0.4.0]NullPointerException in AudibleMain.n() HOT 2
- [audible][0.4.1]android.content.ActivityNotFoundException in com.softenido.audible HOT 2
- [audible][0.4.1] java.lang.IllegalArgumentException in android.os.Parcel.readException HOT 8
- [audible][0.4.1] java.lang.NullPointerException in android.app.ActivityThread.handleStopActivity HOT 3
- [audible][0.4.1] java.lang.NullPointerException in com.softenido.audible.AudibleMain.p HOT 1
- [audible][0.4.1] ANR keyDispatchingTimedOut in android/com.android.internal.app.ChooserActivity HOT 2
- [audible][0.4.1] java.lang.NullPointerException in com.softenido.cafedroid.e.k.b HOT 2
- [audible][0.5.0] java.lang.NullPointerException in com.softenido.a.g.b.a HOT 1
- [audible][0.5.1]java.lang.IllegalArgumentException in java.lang.Enum.valueOf HOT 3
- [audible] Start file browser in the last directory when called from load file button HOT 2
- [audible] Rewrite K-9 Mail to send text to Audible TTS in one step.
- [audible][0.5.1] java.lang.NullPointerException in com.softenido.cafedroid.e.k.a HOT 1
- [audible][0.5.1] android.view.ViewRootImpl$CalledFromWrongThreadException in android.view.ViewRootImpl.checkThread HOT 1
- java.lang.StringIndexOutOfBoundsException in java.lang.String.startEndAndLength HOT 3
- [audible][0.6.2] java.lang.NullPointerException in com.softenido.audible.AudibleMain.loadHeadAndBody HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from softenido.