当前位置: 首页>>代码示例>>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;未经允许,请勿转载。