當前位置: 首頁>>代碼示例>>Java>>正文


Java TextToSpeech類代碼示例

本文整理匯總了Java中android.speech.tts.TextToSpeech的典型用法代碼示例。如果您正苦於以下問題:Java TextToSpeech類的具體用法?Java TextToSpeech怎麽用?Java TextToSpeech使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


TextToSpeech類屬於android.speech.tts包,在下文中一共展示了TextToSpeech類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: Init

import android.speech.tts.TextToSpeech; //導入依賴的package包/類
public void Init() {
    if (_ttsInitialized) {
        Logger.getInstance().Warning(TAG, "Already initialized!");
        return;
    }

    _ttsSpeaker = new TextToSpeech(_context, status -> {
        if (status == TextToSpeech.SUCCESS) {
            int result = _ttsSpeaker.setLanguage(Locale.US);
            if (result == TextToSpeech.LANG_MISSING_DATA || result == TextToSpeech.LANG_NOT_SUPPORTED) {
                Logger.getInstance().Error(TAG, "This Language is not supported!");
            } else {
                _receiverController.RegisterReceiver(_speakReceiver, new String[]{TTS_SPEAK_TEXT_BROADCAST});
                _ttsInitialized = true;
            }
        } else {
            Logger.getInstance().Error(TAG, "Initialization failed!");
        }
    });
}
 
開發者ID:GuepardoApps,項目名稱:LucaHome-AndroidApplication,代碼行數:21,代碼來源:TTSController.java

示例2: onInit

import android.speech.tts.TextToSpeech; //導入依賴的package包/類
@Override
public void onInit(int status) {
    // TODO Auto-generated method stub

    if (status == TextToSpeech.SUCCESS) {
        //int result= tts.setLanguage(Locale.ENGLISH);
        Locale locale = new Locale("tr", "TR");
        int result = tts.setLanguage(locale);

        if (result == TextToSpeech.LANG_MISSING_DATA
                || result == TextToSpeech.LANG_NOT_SUPPORTED) {
            Log.e("TTS", "Language is not supported");
        } else {
            btn_konus.setEnabled(true);
            String text = editText1.getText().toString();
            speakOut(text);
        }

    } else {
        Log.e("TTS", "Initilization Failed");
    }
}
 
開發者ID:nrkdrk,項目名稱:Image-Text-Reader-And-Tools,代碼行數:23,代碼來源:TextToSpeechActivity.java

示例3: init

import android.speech.tts.TextToSpeech; //導入依賴的package包/類
public void init(Context ctx) {
    prefs = PreferenceManager.getDefaultSharedPreferences(ctx);
    prefsÆndret();
    tts = new TextToSpeech(ctx, new TextToSpeech.OnInitListener() {
      @Override
      public void onInit(int status) {
        if (status == TextToSpeech.SUCCESS) {
          initialiseret = true;
          int res = tts.setLanguage(new Locale("da", ""));
          if (res == TextToSpeech.LANG_MISSING_DATA || res == TextToSpeech.LANG_NOT_SUPPORTED) {
            res = tts.setLanguage(Locale.getDefault());
            if (res == TextToSpeech.LANG_MISSING_DATA || res == TextToSpeech.LANG_NOT_SUPPORTED) {
              res = tts.setLanguage(Locale.US);
              if (res == TextToSpeech.LANG_MISSING_DATA || res == TextToSpeech.LANG_NOT_SUPPORTED) {
                initialiseret = false;
              }
            }
          }

//          udtal("Tekst til tale initialiseret for sproget " + tts.getLanguage().getDisplayLanguage(tts.getLanguage()));
        }
      }
    });
  }
 
開發者ID:nordfalk,項目名稱:EsperantoRadio,代碼行數:25,代碼來源:Talesyntese.java

示例4: getSpeechFromText

import android.speech.tts.TextToSpeech; //導入依賴的package包/類
/**
 * Create a new audio recording based on text passed in, update the callback with the changing states
 * @param text the text to render
 * @param callback
 */
public void getSpeechFromText(String text, SpeechFromTextCallback callback){

    //create a new unique ID
    String utteranceId = AuthorizationManager.createCodeVerifier();

    //add the callback to our list of callbacks
    mCallbacks.put(utteranceId, callback);

    //get our TextToSpeech engine
    TextToSpeech textToSpeech = getTextToSpeech();

    //set up our arguments
    HashMap<String, String> params = new HashMap<>();
    params.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, utteranceId);

    //request an update from TTS
    textToSpeech.synthesizeToFile(text, params, getCacheFile(utteranceId).toString());
}
 
開發者ID:vaibhavs4424,項目名稱:AI-Powered-Intelligent-Banking-Platform,代碼行數:24,代碼來源:VoiceHelper.java

示例5: getAvailableLocales

import android.speech.tts.TextToSpeech; //導入依賴的package包/類
@ReactMethod 
public void getAvailableLocales(Promise promise) {
	if(notReady(promise)) return;
	
	try {
		WritableArray localeList = Arguments.createArray();
		Locale[] localesArray = Locale.getAvailableLocales();
		for(Locale locale: localesArray) {
			int isAvailable = tts.isLanguageAvailable(locale);
			if(isAvailable == TextToSpeech.LANG_COUNTRY_AVAILABLE) {
				WritableMap newLocale = returnMapForLocale(locale);
				localeList.pushMap(newLocale);
			}
		}

		promise.resolve(localeList);
	} catch(Exception e) {
		promise.reject("error", "Unable to retrieve locales for getAvailableLocales()", e);
	}
}
 
開發者ID:echo8795,項目名稱:react-native-android-text-to-speech,代碼行數:21,代碼來源:RNAndroidTextToSpeechModule.java

示例6: searchVoice

import android.speech.tts.TextToSpeech; //導入依賴的package包/類
public static Voice searchVoice(String voiceName, TextToSpeech tts) {
    if (MainActivity.isLoggingEnabled)
        Log.i("VOICES:", tts.getVoices().toString()); //stampa tutte le voci disponibili
    for (Voice tmpVoice : tts.getVoices()) {
        if (tmpVoice.getName().equals(voiceName)) {
            return tmpVoice;
        }
    }
    return null;
}
 
開發者ID:Cesarsk,項目名稱:Say_it,代碼行數:11,代碼來源:UtilityTTS.java

示例7: speakResults

import android.speech.tts.TextToSpeech; //導入依賴的package包/類
public void speakResults(TextToSpeech tts, List<Recognition> results) {
    if (results.isEmpty()) {
        tts.speak("I don't understand what I see.", TextToSpeech.QUEUE_ADD, null, UTTERANCE_ID);
        if (isFeelingFunnyNow()) {
            tts.speak("Please don't unplug me, I'll do better next time.",
                    TextToSpeech.QUEUE_ADD, null, UTTERANCE_ID);
        }
    } else {
        if (isFeelingFunnyNow()) {
            playJoke(tts);
        }
        if (results.size() == 1
                || results.get(0).getConfidence() > SINGLE_ANSWER_CONFIDENCE_THRESHOLD) {
            tts.speak(String.format(Locale.getDefault(),
                    "I see a %s", results.get(0).getTitle()),
                    TextToSpeech.QUEUE_ADD, null, UTTERANCE_ID);
        } else {
            tts.speak(String.format(Locale.getDefault(), "This is a %s, or maybe a %s",
                    results.get(0).getTitle(), results.get(1).getTitle()),
                    TextToSpeech.QUEUE_ADD, null, UTTERANCE_ID);
        }
    }

}
 
開發者ID:FoxLabMakerSpace,項目名稱:SIGHT-For-the-Blind,代碼行數:25,代碼來源:TtsSpeaker.java

示例8: playJoke

import android.speech.tts.TextToSpeech; //導入依賴的package包/類
private boolean playJoke(TextToSpeech tts) {
    long now = System.currentTimeMillis();
    // choose a random joke whose last occurrence was far enough in the past
    SortedMap<Long, Utterance> availableJokes = mJokes.headMap(now - JOKE_COOLDOWN_MILLIS);
    Utterance joke = null;
    if (!availableJokes.isEmpty()) {
        int r = RANDOM.nextInt(availableJokes.size());
        int i = 0;
        for (Long key : availableJokes.keySet()) {
            if (i++ == r) {
                joke = availableJokes.remove(key); // also removes from mJokes
                break;
            }
        }
    }
    if (joke != null) {
        joke.speak(tts);
        // add it back with the current time
        mJokes.put(now, joke);
        return true;
    }
    return false;
}
 
開發者ID:FoxLabMakerSpace,項目名稱:SIGHT-For-the-Blind,代碼行數:24,代碼來源:TtsSpeaker.java

示例9: speak

import android.speech.tts.TextToSpeech; //導入依賴的package包/類
@SuppressWarnings("deprecation")
private void speak(String text) {
    boolean ttsEnabled = preferences.getBoolean("tts_enabled", true);
    if (ttsEnabled) {
        speakingDialog.show();
        // Stop listening so it doesn't trigger itself.
        if (hotwordDetector != null) {
            hotwordDetector.stopListening();
        }
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            tts.speak(text, TextToSpeech.QUEUE_FLUSH, null, "messageID");
        } else {
            HashMap<String, String> map = new HashMap<String, String>();
            map.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID,"messageID");
            tts.speak(text, TextToSpeech.QUEUE_FLUSH, map);
        }
    }
}
 
開發者ID:timstableford,項目名稱:P-BrainAndroid,代碼行數:19,代碼來源:MainActivity.java

示例10: onInit

import android.speech.tts.TextToSpeech; //導入依賴的package包/類
@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,代碼行數:23,代碼來源:TextSpeaker.java

示例11: audioEnroll

import android.speech.tts.TextToSpeech; //導入依賴的package包/類
/**
 * All is well - begin the audio enrollment
 */
private void audioEnroll(@NonNull final String profileId) {
    if (DEBUG) {
        MyLog.i(CLS_NAME, "audioEnroll");
    }


    final String utterance;

    if (SPH.getEnrollmentVerbose(getApplicationContext())) {
        utterance = getApplicationContext().getString(R.string.speech_enroll_instructions_40);
    } else {
        SPH.setEnrollmentVerbose(getApplicationContext());
        utterance = getApplicationContext().getString(R.string.speech_enroll_instructions_first);
    }

    final LocalRequest request = new LocalRequest(getApplicationContext());
    request.prepareDefault(LocalRequest.ACTION_SPEAK_LISTEN, utterance);
    request.setQueueType(TextToSpeech.QUEUE_ADD);
    request.setCondition(Condition.CONDITION_IDENTITY);
    request.setIdentityProfile(profileId);
    request.execute();
}
 
開發者ID:brandall76,項目名稱:Saiy-PS,代碼行數:26,代碼來源:FragmentSuperuserHelper.java

示例12: createTTS

import android.speech.tts.TextToSpeech; //導入依賴的package包/類
private void createTTS() {

        //Creates an instance of Google API TTS
        mTTS = new TextToSpeech(mContext, new TextToSpeech.OnInitListener() {
            @Override
            public void onInit(int status) {
                
                //If initializaation is sucessful so set language.
                if (status == TextToSpeech.SUCCESS) {

                    //Set language to PT-BR and get the value returned
                    int result = mTTS.setLanguage(new Locale("pt", "br"));

                    //Check if the language is supported, if not print it on Android Monitor.
                    if (result == TextToSpeech.LANG_MISSING_DATA
                            || result == TextToSpeech.LANG_NOT_SUPPORTED) {
                        Log.e("TextToSpeechManager", "This Language is not supported");
                    }

                } else {
                    Log.e("TextToSpeechManager", "Initilization Failed!");
                }
            }
        });
    }
 
開發者ID:aidaferreira,項目名稱:synesthesiavision,代碼行數:26,代碼來源:TextToSpeechManager.java

示例13: TtsPlatformImpl

import android.speech.tts.TextToSpeech; //導入依賴的package包/類
protected TtsPlatformImpl(long nativeTtsPlatformImplAndroid, Context context) {
    mInitialized = false;
    mNativeTtsPlatformImplAndroid = nativeTtsPlatformImplAndroid;
    mTextToSpeech = new TextToSpeech(context, new TextToSpeech.OnInitListener() {
            @Override
            public void onInit(int status) {
                if (status == TextToSpeech.SUCCESS) {
                    ThreadUtils.runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            initialize();
                        }
                    });
                }
            }
        });
    addOnUtteranceProgressListener();
}
 
開發者ID:rkshuai,項目名稱:chromium-for-android-56-debug-video,代碼行數:19,代碼來源:TtsPlatformImpl.java

示例14: speak

import android.speech.tts.TextToSpeech; //導入依賴的package包/類
/**
 * Attempt to start speaking an utterance. If it returns true, will call back on
 * start and end.
 *
 * @param utteranceId A unique id for this utterance so that callbacks can be tied
 *     to a particular utterance.
 * @param text The text to speak.
 * @param lang The language code for the text (e.g., "en-US").
 * @param rate The speech rate, in the units expected by Android TextToSpeech.
 * @param pitch The speech pitch, in the units expected by Android TextToSpeech.
 * @param volume The speech volume, in the units expected by Android TextToSpeech.
 * @return true on success.
 */
@CalledByNative
private boolean speak(int utteranceId, String text, String lang,
                      float rate, float pitch, float volume) {
    if (!mInitialized) {
        mPendingUtterance = new PendingUtterance(this, utteranceId, text, lang, rate,
                pitch, volume);
        return true;
    }
    if (mPendingUtterance != null) mPendingUtterance = null;

    if (!lang.equals(mCurrentLanguage)) {
        mTextToSpeech.setLanguage(new Locale(lang));
        mCurrentLanguage = lang;
    }

    mTextToSpeech.setSpeechRate(rate);
    mTextToSpeech.setPitch(pitch);

    int result = callSpeak(text, volume, utteranceId);
    return (result == TextToSpeech.SUCCESS);
}
 
開發者ID:rkshuai,項目名稱:chromium-for-android-56-debug-video,代碼行數:35,代碼來源:TtsPlatformImpl.java

示例15: onInit

import android.speech.tts.TextToSpeech; //導入依賴的package包/類
@Override
public void onInit(int status) {
    if (status == TextToSpeech.SUCCESS) {
        int result = mTts.setLanguage(Locale.getDefault());
        isInit = true;

        if (result == TextToSpeech.LANG_MISSING_DATA || result == TextToSpeech.LANG_NOT_SUPPORTED) {

            Log.e("error", "This Language is not supported");
        }
        Log.d("TextToSpeech", "Initialization Suceeded! " + System.currentTimeMillis());

        speak(mContext.getString(R.string.hello1) + ",");
    } else {
        Log.e("error", "Initialization Failed! " + status);
    }
}
 
開發者ID:quaap,項目名稱:PhoneFoneFun,代碼行數:18,代碼來源:TextToVoice.java


注:本文中的android.speech.tts.TextToSpeech類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。