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


Java TextToSpeech.speak方法代碼示例

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


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

示例1: 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

示例2: speak

import android.speech.tts.TextToSpeech; //導入方法依賴的package包/類
@Override
public void speak(TextToSpeech tts) {
    tts.setPitch(0.2f);
    tts.speak("I see dead people...", TextToSpeech.QUEUE_ADD, null, UTTERANCE_ID);
    tts.setPitch(1);
    tts.speak("Just kidding...", TextToSpeech.QUEUE_ADD, null, UTTERANCE_ID);
}
 
開發者ID:FoxLabMakerSpace,項目名稱:SIGHT-For-the-Blind,代碼行數:8,代碼來源:TtsSpeaker.java

示例3: onBtnTextToSpeechClicked

import android.speech.tts.TextToSpeech; //導入方法依賴的package包/類
@OnClick(R.id.btn_text_to_speech)
public void onBtnTextToSpeechClicked() {
    onInitListener = new TextToSpeech.OnInitListener() {
        @Override
        public void onInit(int status) {
            if (status == TextToSpeech.SUCCESS) {
                int result = speech.setLanguage(Locale.ENGLISH);
                if (result == TextToSpeech.LANG_MISSING_DATA
                        || result == TextToSpeech.LANG_NOT_SUPPORTED) {
                    ToastUtils.showShortToast("語言不支持");
                } else {
                    String content = "This is a default voice";
                    if (!TextUtils.isEmpty(etTextContent.getText().toString())) {
                        content = etTextContent.getText().toString();
                    }
                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                        speech.speak(content, TextToSpeech.QUEUE_FLUSH, null, null);
                    } else {
                        speech.speak(content, TextToSpeech.QUEUE_FLUSH, null);
                    }

                }
            }
        }
    };
    speech = new TextToSpeech(this, onInitListener);
}
 
開發者ID:jiangkang,項目名稱:KTools,代碼行數:28,代碼來源:AudioActivity.java

示例4: onCreate

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

示例5: speakReady

import android.speech.tts.TextToSpeech; //導入方法依賴的package包/類
public void speakReady(TextToSpeech tts) {
    tts.speak("I'm ready!", TextToSpeech.QUEUE_ADD, null, UTTERANCE_ID);
}
 
開發者ID:FoxLabMakerSpace,項目名稱:SIGHT-For-the-Blind,代碼行數:4,代碼來源:TtsSpeaker.java


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