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


Java TextToSpeech.QUEUE_ADD屬性代碼示例

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


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

示例1: speak

@ReactMethod
public void speak(String utterance, String queueMode, Promise promise) {
	if(notReady(promise)) return;

	if(IS_DUCKING) {
		int amResult = audioManager.requestAudioFocus(afChangeListener, 
														AudioManager.STREAM_MUSIC, 
														AudioManager.AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK);

		if(amResult != AudioManager.AUDIOFOCUS_REQUEST_GRANTED)
			promise.reject("error", "Android AudioManager error, failed to request audio focus");
	}

	String utteranceId = Integer.toString(utterance.hashCode());

	int mode = TextToSpeech.QUEUE_ADD;
	if(queueMode.equals("ADD")) 
		mode = TextToSpeech.QUEUE_ADD;
	else if(queueMode.equals("FLUSH")) 
		mode = TextToSpeech.QUEUE_FLUSH;

	int speakResult = speak(utterance, mode, utteranceId);
	if(speakResult == TextToSpeech.SUCCESS) {
		promise.resolve(utteranceId);
	} else {
		promise.reject("error", "Unable to play. Error at speak(utterance, queueMode)");
	}
}
 
開發者ID:echo8795,項目名稱:react-native-android-text-to-speech,代碼行數:28,代碼來源:RNAndroidTextToSpeechModule.java

示例2: onServiceConnected

@Override
public void onServiceConnected(final ComponentName className, final IBinder iBinder) {

    if (iBinder != null) {

        if (DEBUG) {
            MyLog.i(CLS_NAME, "onServiceConnected");
            MyLog.i(CLS_NAME, "onServiceConnected: CLS: " + iBinder.getClass().getSimpleName());
            MyLog.v(CLS_NAME, "onServiceConnected: binder alive: " + iBinder.isBinderAlive());
        }

        selfAwareService = ((SelfAware.BoundSA) iBinder).getService();

        if (DEBUG) {
            MyLog.i(CLS_NAME, "onServiceConnected: TTS Locale: " + request.getTTSLocale().toString());
            MyLog.i(CLS_NAME, "onServiceConnected: Recognition Locale: " + request.getVRLocale().toString());
        }

        final Pair<Boolean, Integer> isSpeakingPair = selfAwareService.isSpeaking();
        final boolean isListening = selfAwareService.isListening();
        final Pair<Boolean, Boolean> isHotwordActive = selfAwareService.isHotwordActive();

        if (DEBUG) {
            MyLog.i(CLS_NAME, "isSpeaking: " + isSpeakingPair.first);
            MyLog.i(CLS_NAME, "isListening:" + isListening);
            MyLog.i(CLS_NAME, "isHotwordActive:" + isHotwordActive.first);
            MyLog.i(CLS_NAME, "isHotwordRestartScheduled:" + isHotwordActive.second);
        }

        if (request.getAction() == LocalRequest.ACTION_TOGGLE_HOTWORD) {

            if (isHotwordActive.first || isHotwordActive.second) {
                request.setAction(LocalRequest.ACTION_STOP_HOTWORD);
                request.setShutdownHotword();
            } else {
                request.setAction(LocalRequest.ACTION_START_HOTWORD);
            }
        }

        if (isHotwordActive.first && request.getAction() == LocalRequest.ACTION_START_HOTWORD) {
            if (DEBUG) {
                MyLog.i(CLS_NAME, "ACTION_START_HOTWORD: already running");
            }
        } else if (isListening) {
            selfAwareService.stopListening(request.getShutdownHotword());
        } else if (isSpeakingPair.first) {

            final int currentPriority = isSpeakingPair.second;
            final int requestPriority = request.getSpeechPriority();

            if (requestPriority == currentPriority && request.getQueueType() != TextToSpeech.QUEUE_ADD) {
                if (DEBUG) {
                    MyLog.i(CLS_NAME, "priorities match - stopping speech");
                }
                selfAwareService.stopSpeech(request.shouldPreventRecognition());
            } else {

                if (request.getAction() == LocalRequest.ACTION_UNKNOWN) {
                    if (DEBUG) {
                        MyLog.i(CLS_NAME, "priority mismatch - ACTION_UNKNOWN - stopping speech");
                    }
                    selfAwareService.stopSpeech(request.shouldPreventRecognition());
                } else {
                    if (DEBUG) {
                        MyLog.i(CLS_NAME, "priority mismatch - completing request");
                    }
                    completeRequest();
                }
            }

        } else {
            completeRequest();
        }
    } else {
        if (DEBUG) {
            MyLog.w(CLS_NAME, "onServiceConnected: iBinder null");
        }
    }

    doUnbindService();
}
 
開發者ID:brandall76,項目名稱:Saiy-PS,代碼行數:81,代碼來源:ServiceConnector.java

示例3: isQueueAdd

/**
 * Check if the queue type is {@link TextToSpeech#QUEUE_ADD}
 *
 * @param bundle the parameters
 * @return true if the queue type is {@link TextToSpeech#QUEUE_ADD}. False otherwise
 */
public boolean isQueueAdd(final Bundle bundle) {
    return bundle != null && bundle.getInt(LocalRequest.EXTRA_QUEUE_TYPE,
            TextToSpeech.QUEUE_FLUSH) == TextToSpeech.QUEUE_ADD;
}
 
開發者ID:brandall76,項目名稱:Saiy-PS,代碼行數:10,代碼來源:SelfAwareConditions.java


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