本文整理汇总了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);
}
}
}
示例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);
}
示例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);
}
示例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();
}
}
});
}
示例5: speakReady
import android.speech.tts.TextToSpeech; //导入方法依赖的package包/类
public void speakReady(TextToSpeech tts) {
tts.speak("I'm ready!", TextToSpeech.QUEUE_ADD, null, UTTERANCE_ID);
}