当前位置: 首页>>代码示例>>Java>>正文


Java TextToSpeech.ERROR属性代码示例

本文整理汇总了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;
    }
}
 
开发者ID:voroshkov,项目名称:Chorus-RF-Laptimer,代码行数:22,代码来源:TextSpeaker.java

示例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;
    }
}
 
开发者ID:Dnet3,项目名称:CustomAndroidOneSheeld,代码行数:17,代码来源:TextToSpeechShield.java

示例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;
        }
    });
}
 
开发者ID:feelfreelinux,项目名称:WordLing,代码行数:16,代码来源:WordLing.java

示例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");

    }
}
 
开发者ID:kbrkkn,项目名称:Uygulama-Android,代码行数:18,代码来源:MainActivity.java

示例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);
            }
        }
    });
}
 
开发者ID:marcplouhinec,项目名称:speaking-glasses,代码行数:29,代码来源:MainActivity.java

示例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();
            }
        }
    });
}
 
开发者ID:marcplouhinec,项目名称:speaking-glasses,代码行数:27,代码来源:CameraActivity.java

示例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();
    }
}
 
开发者ID:vikasdesale,项目名称:News24x7-news-from-every-part-of-the-world,代码行数:11,代码来源:DetailsFragment.java

示例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();
            }
        }
    });
}
 
开发者ID:marcplouhinec,项目名称:speaking-glasses,代码行数:50,代码来源:PhotoAnalysisActivity.java

示例9: onInit

@Override
public void onInit(int status) {
  if (status != TextToSpeech.ERROR) {
    textToSpeech.setLanguage(Locale.getDefault());
  }
}
 
开发者ID:mapbox,项目名称:mapbox-navigation-android,代码行数:6,代码来源:DefaultPlayer.java

示例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);
  }
}
 
开发者ID:mit-cml,项目名称:appinventor-extensions,代码行数:43,代码来源:InternalTextToSpeech.java


注:本文中的android.speech.tts.TextToSpeech.ERROR属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。