本文整理汇总了Java中android.speech.tts.TextToSpeech.Engine类的典型用法代码示例。如果您正苦于以下问题:Java Engine类的具体用法?Java Engine怎么用?Java Engine使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Engine类属于android.speech.tts.TextToSpeech包,在下文中一共展示了Engine类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: getEngines
import android.speech.tts.TextToSpeech.Engine; //导入依赖的package包/类
/**
* Gets a list of all installed TTS engines sorted by priority (see
* {@link #ENGINE_PRIORITY_COMPARATOR}).
*
* @return A sorted list of engine info objects. The list can be empty, but
* never {@code null}.
*/
public static List<TtsEngineInfo> getEngines(Context context) {
final PackageManager pm = context.getPackageManager();
final Intent intent = new Intent(Engine.INTENT_ACTION_TTS_SERVICE);
final List<ResolveInfo> resolveInfos = pm.queryIntentServices(
intent, PackageManager.MATCH_DEFAULT_ONLY);
final List<TtsEngineInfo> engines = new ArrayList<TtsEngineInfo>(resolveInfos.size());
for (ResolveInfo resolveInfo : resolveInfos) {
final TtsEngineInfo engine = getEngineInfo(resolveInfo, pm);
if (engine != null) {
engines.add(engine);
}
}
Collections.sort(engines, ENGINE_PRIORITY_COMPARATOR);
return Collections.unmodifiableList(engines);
}
开发者ID:google,项目名称:brailleback,代码行数:26,代码来源:TtsEngineUtils.java
示例2: getEngineInfo
import android.speech.tts.TextToSpeech.Engine; //导入依赖的package包/类
/**
* Returns the engine info for a given engine name. Note that engines are
* identified by their package name.
*/
public static TtsEngineInfo getEngineInfo(Context context, String packageName) {
if (packageName == null) {
return null;
}
final PackageManager pm = context.getPackageManager();
final Intent intent = new Intent(Engine.INTENT_ACTION_TTS_SERVICE).setPackage(packageName);
final List<ResolveInfo> resolveInfos = pm.queryIntentServices(intent,
PackageManager.MATCH_DEFAULT_ONLY);
if ((resolveInfos == null) || resolveInfos.isEmpty()) {
return null;
}
// Note that the current API allows only one engine per
// package name. Since the "engine name" is the same as
// the package name.
return getEngineInfo(resolveInfos.get(0), pm);
}
开发者ID:google,项目名称:brailleback,代码行数:23,代码来源:TtsEngineUtils.java
示例3: getEngines
import android.speech.tts.TextToSpeech.Engine; //导入依赖的package包/类
/**
* Gets a list of all installed TTS engines sorted by priority (see
* {@link #ENGINE_PRIORITY_COMPARATOR}).
*
* @return A sorted list of engine info objects. The list can be empty, but
* never {@code null}.
*/
private static List<TtsEngineInfo> getEngines(Context context) {
final PackageManager pm = context.getPackageManager();
final Intent intent = new Intent(Engine.INTENT_ACTION_TTS_SERVICE);
final List<ResolveInfo> resolveInfos = pm.queryIntentServices(
intent, PackageManager.MATCH_DEFAULT_ONLY);
final List<TtsEngineInfo> engines = new ArrayList<>(resolveInfos.size());
for (ResolveInfo resolveInfo : resolveInfos) {
final TtsEngineInfo engine = getEngineInfo(resolveInfo, pm);
if (engine != null) {
engines.add(engine);
}
}
Collections.sort(engines, ENGINE_PRIORITY_COMPARATOR);
return Collections.unmodifiableList(engines);
}
开发者ID:google,项目名称:talkback,代码行数:26,代码来源:TtsEngineUtils.java
示例4: getEngineInfo
import android.speech.tts.TextToSpeech.Engine; //导入依赖的package包/类
/**
* Returns the engine info for a given engine name. Note that engines are
* identified by their package name.
*/
private static TtsEngineInfo getEngineInfo(Context context, String packageName) {
if (packageName == null) {
return null;
}
final PackageManager pm = context.getPackageManager();
final Intent intent = new Intent(Engine.INTENT_ACTION_TTS_SERVICE).setPackage(packageName);
final List<ResolveInfo> resolveInfos = pm.queryIntentServices(intent,
PackageManager.MATCH_DEFAULT_ONLY);
if ((resolveInfos == null) || resolveInfos.isEmpty()) {
return null;
}
// Note that the current API allows only one engine per
// package name. Since the "engine name" is the same as
// the package name.
return getEngineInfo(resolveInfos.get(0), pm);
}
开发者ID:google,项目名称:talkback,代码行数:23,代码来源:TtsEngineUtils.java
示例5: speakApi21
import android.speech.tts.TextToSpeech.Engine; //导入依赖的package包/类
@TargetApi(21)
private int speakApi21(CharSequence text, HashMap<String, String> params, String utteranceId,
float pitch, float rate, int stream, float volume) {
Bundle bundle = new Bundle();
if (params != null) {
for (String key : params.keySet()) {
bundle.putString(key, params.get(key));
}
}
bundle.putInt(SpeechController.SpeechParam.PITCH, (int)(pitch*100));
bundle.putInt(SpeechController.SpeechParam.RATE, (int)(rate*100));
bundle.putInt(Engine.KEY_PARAM_STREAM, stream);
bundle.putFloat(SpeechController.SpeechParam.VOLUME, volume);
ensureQueueFlush();
return mTts.speak(text, SPEECH_FLUSH_ALL, bundle, utteranceId);
}
开发者ID:google,项目名称:talkback,代码行数:20,代码来源:FailoverTextToSpeech.java
示例6: needsFallbackLocale
import android.speech.tts.TextToSpeech.Engine; //导入依赖的package包/类
/**
* Returns whether we need to attempt to use a fallback language.
*/
private boolean needsFallbackLocale() {
// If the user isn't using Google TTS, or if they set a preferred
// locale, we do not need to check locale support.
if (!PACKAGE_GOOGLE_TTS.equals(mTtsEngine) || (mDefaultLocale != null)) {
return false;
}
if (mTts == null) {
return false;
}
// Otherwise, the TTS engine will attempt to use the system locale which
// may not be supported. If the locale is embedded or advertised as
// available, we're fine.
final Set<String> features = mTts.getFeatures(mSystemLocale);
return !(((features != null)
&& features.contains(Engine.KEY_FEATURE_EMBEDDED_SYNTHESIS))
|| !isNotAvailableStatus(mTts.isLanguageAvailable(mSystemLocale)));
}
开发者ID:google,项目名称:talkback,代码行数:23,代码来源:FailoverTextToSpeech.java
示例7: getEngines
import android.speech.tts.TextToSpeech.Engine; //导入依赖的package包/类
@Kroll.method
public KrollDict getEngines() {
KrollDict data = new KrollDict();
PackageManager pm = TiApplication.getInstance().getPackageManager();
Intent intent = new Intent(Engine.INTENT_ACTION_TTS_SERVICE);
List<ResolveInfo> resolveInfos = pm.queryIntentServices(intent,
PackageManager.MATCH_DEFAULT_ONLY);
if (resolveInfos == null)
return data;
for (ResolveInfo resolveInfo : resolveInfos) {
MyEngineInfo engine = getEngineInfo(resolveInfo, pm);
if (engine != null) {
data.put(engine.label, engine.name);
}
}
return data;
}
开发者ID:isis,项目名称:TTS-Module,代码行数:19,代码来源:TtsModule.java
示例8: speak
import android.speech.tts.TextToSpeech.Engine; //导入依赖的package包/类
@Kroll.method
public boolean speak(String text, @Kroll.argument(optional = true) String utteranceId) {
if (DBG) Log.d(LCAT, "speak " + text);
if (initialized) {
if (0 < text.length()) {
if (tts.setPitch(getPitch()) == TextToSpeech.ERROR) {
if (DBG) Log.e("TTS", "Ptich(" + getPitch() + ") set error.");
}
if (tts.setSpeechRate(getRate()) == TextToSpeech.ERROR) {
if (DBG) Log.e("TTS", "Speech rate(" + getRate() + ") set error.");
}
stopSpeaking();
tts.setOnUtteranceCompletedListener(this);
HashMap<String, String> options = new HashMap<String, String>();
//myHashAlarm.put(TextToSpeech.Engine.KEY_PARAM_STREAM,
// String.valueOf(AudioManager.STREAM_ALARM));
options.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID,
utteranceId);
tts.speak(text, TextToSpeech.QUEUE_FLUSH, options);
}
}
return true;
}
开发者ID:isis,项目名称:TTS-Module,代码行数:24,代码来源:TtsModule.java
示例9: speak
import android.speech.tts.TextToSpeech.Engine; //导入依赖的package包/类
/**
* Speak the specified text.
*
* @param text The text to speak.
* @param pitch The pitch adjustment, in the range [0 ... 1].
* @param rate The rate adjustment, in the range [0 ... 1].
* @param params The parameters to pass to the text-to-speech engine.
*/
public void speak(CharSequence text, float pitch, float rate, HashMap<String, String> params,
int stream, float volume) {
// Handle empty text immediately.
if (TextUtils.isEmpty(text)) {
mHandler.onUtteranceCompleted(params.get(Engine.KEY_PARAM_UTTERANCE_ID));
return;
}
int result;
Exception failureException = null;
try {
result = trySpeak(text, pitch, rate, params, stream, volume);
} catch (Exception e) {
failureException = e;
result = TextToSpeech.ERROR;
}
if (result == TextToSpeech.ERROR) {
attemptTtsFailover(mTtsEngine);
}
if ((result != TextToSpeech.SUCCESS)
&& params.containsKey(Engine.KEY_PARAM_UTTERANCE_ID)) {
if (failureException != null) {
if(LogUtils.LOG_LEVEL <= Log.WARN) {
Log.w(TAG, "Failed to speak " + text + " due to an exception");
}
failureException.printStackTrace();
} else {
if (LogUtils.LOG_LEVEL <= Log.WARN) {
Log.w(TAG, "Failed to speak " + text);
}
}
mHandler.onUtteranceCompleted(params.get(Engine.KEY_PARAM_UTTERANCE_ID));
}
}
开发者ID:google,项目名称:talkback,代码行数:47,代码来源:FailoverTextToSpeech.java
示例10: trySpeak
import android.speech.tts.TextToSpeech.Engine; //导入依赖的package包/类
/**
* Attempts to speak the specified text.
*
* @param text to speak, must be under 3999 chars.
* @param pitch to speak text in.
* @param rate to speak text in.
* @param params to the TTS.
* @return The result of speaking the specified text.
*/
@SuppressWarnings("unused")
private int trySpeak(CharSequence text, float pitch, float rate, HashMap<String, String> params,
int stream, float volume) {
if (mTts == null) {
return TextToSpeech.ERROR;
}
float effectivePitch = (pitch * mDefaultPitch);
float effectiveRate = (rate * mDefaultRate);
int result;
String utteranceId = params.get(Engine.KEY_PARAM_UTTERANCE_ID);
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT_WATCH) {
result = speakApi21(text, params, utteranceId, effectivePitch, effectiveRate, stream,
volume);
} else {
// Set the pitch and rate only if necessary, since that is slow.
if ((mCurrentPitch != effectivePitch) || (mCurrentRate != effectiveRate)) {
mTts.stop();
mTts.setPitch(effectivePitch);
mTts.setSpeechRate(effectiveRate);
}
result = mTts.speak(text.toString(), SPEECH_FLUSH_ALL, params);
}
mCurrentPitch = effectivePitch;
mCurrentRate = effectiveRate;
if (result != TextToSpeech.SUCCESS) {
ensureSupportedLocale();
}
if (LogUtils.LOG_LEVEL < Log.DEBUG) {
Log.d(TAG, "Speak call for " + utteranceId + " returned " + result);
}
return result;
}
开发者ID:google,项目名称:talkback,代码行数:47,代码来源:FailoverTextToSpeech.java
示例11: checkTTS
import android.speech.tts.TextToSpeech.Engine; //导入依赖的package包/类
@Kroll.method
public void checkTTS(
@Kroll.argument(optional = true) String enginepackangename) {
shutdown();
TiBaseActivity activity = TiApplication.getInstance().getRootActivity();
Intent intent;
if (enginepackangename != null) {
intent = new Intent(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA);
intent.setPackage(enginepackangename);
}else{
intent = new Intent();
}
intent.setAction(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA);
activity.launchActivityForResult(intent, CHECK_TTS, this);
}
开发者ID:isis,项目名称:TTS-Module,代码行数:16,代码来源:TtsModule.java
示例12: processNextFragmentInternal
import android.speech.tts.TextToSpeech.Engine; //导入依赖的package包/类
private boolean processNextFragmentInternal() {
if (mCurrentFragmentIterator == null || !mCurrentFragmentIterator.hasNext()) {
return false;
}
FeedbackFragment fragment = mCurrentFragmentIterator.next();
playEarconsFromFragment(fragment);
playHapticsFromFragment(fragment);
// Reuse the global instance of speech parameters.
final HashMap<String, String> params = mSpeechParametersMap;
params.clear();
// Add all custom speech parameters.
final Bundle speechParams = fragment.getSpeechParams();
for (String key : speechParams.keySet()) {
params.put(key, String.valueOf(speechParams.get(key)));
}
// Utterance ID, stream, and volume override item params.
params.put(Engine.KEY_PARAM_UTTERANCE_ID, mCurrentFeedbackItem.getUtteranceId());
params.put(Engine.KEY_PARAM_STREAM, String.valueOf(DEFAULT_STREAM));
params.put(Engine.KEY_PARAM_VOLUME, String.valueOf(mSpeechVolume));
final float pitch =
mSpeechPitch * (mUseIntonation ? parseFloatParam(params, SpeechParam.PITCH, 1) : 1);
final float rate =
mSpeechRate * (mUseIntonation ? parseFloatParam(params, SpeechParam.RATE, 1) : 1);
final CharSequence text;
if (shouldSilenceSpeech(mCurrentFeedbackItem) || TextUtils.isEmpty(fragment.getText())) {
text = null;
} else {
text = fragment.getText();
}
String logText = text == null ? null : text.toString();
LogUtils.log(this, Log.VERBOSE, "Speaking fragment text \"%s\"", logText);
mVoiceRecognitionChecker.onUtteranceStart();
// It's okay if the utterance is empty, the fail-over TTS will
// immediately call the fragment completion listener. This process is
// important for things like continuous reading.
mFailoverTts.speak(text, pitch, rate, params, DEFAULT_STREAM, mSpeechVolume);
if (mTtsOverlay != null) {
mTtsOverlay.speak(text);
}
return true;
}
开发者ID:google,项目名称:talkback,代码行数:52,代码来源:SpeechController.java
示例13: isNetworkRequiredForSynthesis
import android.speech.tts.TextToSpeech.Engine; //导入依赖的package包/类
/**
* Returns whether speech synthesis using a specific language on the
* specified TTS requires a network connection.
*
* @param tts The TTS engine to check.
* @param language The language to check.
* @return {@code true} if the language requires a network connection.
*/
public static boolean isNetworkRequiredForSynthesis(TextToSpeech tts, Locale language) {
final Set<String> features = tts.getFeatures(language);
return features.contains(Engine.KEY_FEATURE_NETWORK_SYNTHESIS) &&
!features.contains(Engine.KEY_FEATURE_EMBEDDED_SYNTHESIS);
}
开发者ID:google,项目名称:brailleback,代码行数:14,代码来源:TtsEngineUtils.java
注:本文中的android.speech.tts.TextToSpeech.Engine类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论