本文整理匯總了Java中android.speech.tts.TextToSpeech.ERROR屬性的典型用法代碼示例。如果您正苦於以下問題:Java TextToSpeech.ERROR屬性的具體用法?Java TextToSpeech.ERROR怎麽用?Java TextToSpeech.ERROR使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類android.speech.tts.TextToSpeech
的用法示例。
在下文中一共展示了TextToSpeech.ERROR屬性的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: onInit
@Override
public void onInit(int status) {
if (status != TextToSpeech.ERROR) {
Locale localeToSet = Locale.US;
Locale current = Locale.getDefault();
if (!useEnglishOnly && SUPPORTED_LOCALES.containsKey(current.getLanguage())) {
localeToSet = current;
}
Configuration currentConfig = originalContext.getResources().getConfiguration();
if (!currentConfig.locale.equals(localeToSet)) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) {
setContextToUseLegacy(currentConfig, localeToSet);
} else {
setContextToUse(currentConfig, localeToSet);
}
}
tts.setLanguage(localeToSet);
DecimalFormatSymbols dfs = new DecimalFormatSymbols(localeToSet);
decimalSeparator = Character.toString(dfs.getDecimalSeparator());
isInitialized = true;
}
}
示例2: onInit
@Override
public void onInit(int status) {
switch (status) {
case TextToSpeech.SUCCESS:
notifyHardwareOfShieldSelection();
configureTTSLocale();
break;
case TextToSpeech.ERROR:
Toast.makeText(activity, R.string.text_to_speech_text_to_speech_failed, Toast.LENGTH_SHORT)
.show();
Log.e("[ERROR] doc.saulmm.text2speech.MainActivity.onInit ",
"TTS Failed");
break;
}
}
示例3: initTTS
public void initTTS(Locale locale) {
ttsInit = false;
ttsLocale = locale;
// Init text to speech
tts = new TextToSpeech(this, new TextToSpeech.OnInitListener() {
@Override
public void onInit(int status) {
if (status != TextToSpeech.ERROR) {
tts.setLanguage(ttsLocale);
// Make it say it slowly
tts.setSpeechRate(0.75f);
ttsInit = true;
} else ttsInit = false;
}
});
}
示例4: onInit
@Override
public void onInit(int status) {
if(status==TextToSpeech.SUCCESS){
ready=true;
mTts.setLanguage(Locale.getDefault());//telefonun dili neyse o
// Toast.makeText(this,"başarılı tts",Toast.LENGTH_SHORT).show();
Log.i("tts","tts success");
}
else if(status==TextToSpeech.ERROR){
ready=false;
// Toast.makeText(this,"error tts",Toast.LENGTH_SHORT).show();
Log.e("tts","tts error");
}
}
示例5: onCreate
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.list_standard_layout);
// Load the TTS engine and ask the user to choose a language
textToSpeech = new TextToSpeech(this, new TextToSpeech.OnInitListener() {
@Override
public void onInit(int status) {
if (status == TextToSpeech.ERROR) {
// Display an error message
setContents(new StandardListItem(getResources().getString(R.string.error_tts_engine)));
} else {
textToSpeechReady = true;
// Ask the user to choose a language
askUserToChooseALanguage();
// Show a list of languages the user must select
SupportedLanguage[] supportedLanguages = SupportedLanguage.values();
SimpleListItem[] listItems = new SimpleListItem[supportedLanguages.length];
for (int i = 0; i < supportedLanguages.length; i++) {
listItems[i] = new LanguageListItem(supportedLanguages[i]);
}
setContents(listItems);
}
}
});
}
示例6: onCreate
@Override
protected void onCreate(Bundle savedInstanceState) {
// Set the resources locale
String languageExtra = getIntent().getStringExtra(SupportedLanguage.class.getSimpleName());
language = languageExtra == null ? SupportedLanguage.ENGLISH : SupportedLanguage.valueOf(languageExtra);
LocaleUtils.setResourcesLocale(language.getLocale(), this);
// Initialize the activity content
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_camera);
cameraPreview = (CameraPreview) findViewById(R.id.cameraPreview);
// Load the TTS engine and explain to the user that he can take a picture
textToSpeech = new TextToSpeech(this, new TextToSpeech.OnInitListener() {
@Override
public void onInit(int status) {
if (status == TextToSpeech.ERROR) {
Toast.makeText(CameraActivity.this, R.string.error_tts_engine, Toast.LENGTH_SHORT).show();
} else {
textToSpeechReady = true;
textToSpeech.setLanguage(language.getLocale());
askUserToTakePhoto();
openCamera();
}
}
});
}
示例7: onInit
@Override
public void onInit(int initStatus) {
//check for successful instantiation
if (initStatus == TextToSpeech.SUCCESS) {
if(tts.isLanguageAvailable(Locale.US)==TextToSpeech.LANG_AVAILABLE)
tts.setLanguage(Locale.US);
}
else if (initStatus == TextToSpeech.ERROR) {
Toast.makeText(getActivity(), "Sorry! Text To Speech failed...", Toast.LENGTH_LONG).show();
}
}
示例8: onCreate
@Override
protected void onCreate(Bundle savedInstanceState) {
handler = new Handler();
// Set the resources locale
String languageExtra = getIntent().getStringExtra(SupportedLanguage.class.getSimpleName());
final SupportedLanguage language = languageExtra == null ? SupportedLanguage.ENGLISH : SupportedLanguage.valueOf(languageExtra);
LocaleUtils.setResourcesLocale(language.getLocale(), this);
// Load configuration
InputStream inputStream = null;
try {
inputStream = getBaseContext().getAssets().open("application.properties");
applicationProperties.load(inputStream);
} catch (IOException e) {
Log.e(TAG, "Unable to load application.properties", e);
} finally {
IOUtils.closeQuietly(inputStream);
}
// Get the cloudSightService
String cloudSightApiKey = applicationProperties.getProperty("cloudSight.apiKey");
cloudSightService = new CloudSightServiceImpl(cloudSightApiKey);
// Initialize the activity content
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_photo_analysis);
// Display the photo
final byte[] photo = getIntent().getByteArrayExtra(INTENT_PHOTO_EXTRA);
ImageView photoImageView = (ImageView) findViewById(R.id.photoImageView);
photoImageView.setImageBitmap(BitmapFactory.decodeByteArray(photo, 0, photo.length));
// Load the TTS engine
textToSpeech = new TextToSpeech(this, new TextToSpeech.OnInitListener() {
@Override
public void onInit(int status) {
if (status == TextToSpeech.ERROR) {
Toast.makeText(PhotoAnalysisActivity.this, R.string.error_tts_engine, Toast.LENGTH_SHORT).show();
} else {
textToSpeech.setLanguage(language.getLocale());
// Send the photo to Cloud Sight API to analyze the photo
Toast.makeText(PhotoAnalysisActivity.this, R.string.analyze_photo, Toast.LENGTH_SHORT).show();
textToSpeech.speak(getResources().getString(R.string.analyze_photo), TextToSpeech.QUEUE_ADD, null);
new AnalyzePhotoTask(photo, language).execute();
}
}
});
}
示例9: onInit
@Override
public void onInit(int status) {
if (status != TextToSpeech.ERROR) {
textToSpeech.setLanguage(Locale.getDefault());
}
}
示例10: speak
private void speak(final String message, final Locale loc, final int retries) {
Log.d(LOG_TAG, "InternalTTS speak called, message = " + message);
if (retries > ttsMaxRetries) {
Log.d(LOG_TAG, "max number of speak retries exceeded: speak will fail");
callback.onFailure();
}
// If speak was called before initialization was complete, we retry after a delay.
// Keep track of the number of retries and fail if there are too many.
if (isTtsInitialized) {
Log.d(LOG_TAG, "TTS initialized after " + retries + " retries.");
tts.setLanguage(loc);
tts.setOnUtteranceCompletedListener(
new TextToSpeech.OnUtteranceCompletedListener() {
@Override
public void onUtteranceCompleted(String utteranceId) {
// onUtteranceCompleted is not called on the UI thread, so we use
// Activity.runOnUiThread() to call callback.onSuccess().
activity.runOnUiThread(new Runnable() {
public void run() {
callback.onSuccess();
}
});
}
});
// We need to provide an utterance id. Otherwise onUtteranceCompleted won't be called.
HashMap<String, String> params = new HashMap<String, String>();
params.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, Integer.toString(nextUtteranceId++));
int result = tts.speak(message, tts.QUEUE_FLUSH, params);
if (result == TextToSpeech.ERROR) {
Log.d(LOG_TAG, "speak called and tts.speak result was an error");
callback.onFailure();
}
} else {
Log.d(LOG_TAG, "speak called when TTS not initialized");
mHandler.postDelayed(new Runnable() {
public void run() {
Log.d(LOG_TAG,
"delaying call to speak. Retries is: " + retries + " Message is: " + message);
speak(message, loc, retries + 1);
}
}, ttsRetryDelay);
}
}