本文整理匯總了Java中android.speech.tts.TextToSpeech.OnInitListener方法的典型用法代碼示例。如果您正苦於以下問題:Java TextToSpeech.OnInitListener方法的具體用法?Java TextToSpeech.OnInitListener怎麽用?Java TextToSpeech.OnInitListener使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.speech.tts.TextToSpeech
的用法示例。
在下文中一共展示了TextToSpeech.OnInitListener方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: init
import android.speech.tts.TextToSpeech; //導入方法依賴的package包/類
public void init(Context ctx) {
prefs = PreferenceManager.getDefaultSharedPreferences(ctx);
prefsÆndret();
tts = new TextToSpeech(ctx, new TextToSpeech.OnInitListener() {
@Override
public void onInit(int status) {
if (status == TextToSpeech.SUCCESS) {
initialiseret = true;
int res = tts.setLanguage(new Locale("da", ""));
if (res == TextToSpeech.LANG_MISSING_DATA || res == TextToSpeech.LANG_NOT_SUPPORTED) {
res = tts.setLanguage(Locale.getDefault());
if (res == TextToSpeech.LANG_MISSING_DATA || res == TextToSpeech.LANG_NOT_SUPPORTED) {
res = tts.setLanguage(Locale.US);
if (res == TextToSpeech.LANG_MISSING_DATA || res == TextToSpeech.LANG_NOT_SUPPORTED) {
initialiseret = false;
}
}
}
// udtal("Tekst til tale initialiseret for sproget " + tts.getLanguage().getDisplayLanguage(tts.getLanguage()));
}
}
});
}
示例2: createTTS
import android.speech.tts.TextToSpeech; //導入方法依賴的package包/類
private void createTTS() {
//Creates an instance of Google API TTS
mTTS = new TextToSpeech(mContext, new TextToSpeech.OnInitListener() {
@Override
public void onInit(int status) {
//If initializaation is sucessful so set language.
if (status == TextToSpeech.SUCCESS) {
//Set language to PT-BR and get the value returned
int result = mTTS.setLanguage(new Locale("pt", "br"));
//Check if the language is supported, if not print it on Android Monitor.
if (result == TextToSpeech.LANG_MISSING_DATA
|| result == TextToSpeech.LANG_NOT_SUPPORTED) {
Log.e("TextToSpeechManager", "This Language is not supported");
}
} else {
Log.e("TextToSpeechManager", "Initilization Failed!");
}
}
});
}
示例3: TtsPlatformImpl
import android.speech.tts.TextToSpeech; //導入方法依賴的package包/類
protected TtsPlatformImpl(long nativeTtsPlatformImplAndroid, Context context) {
mInitialized = false;
mNativeTtsPlatformImplAndroid = nativeTtsPlatformImplAndroid;
mTextToSpeech = new TextToSpeech(context, new TextToSpeech.OnInitListener() {
@Override
public void onInit(int status) {
if (status == TextToSpeech.SUCCESS) {
ThreadUtils.runOnUiThread(new Runnable() {
@Override
public void run() {
initialize();
}
});
}
}
});
addOnUtteranceProgressListener();
}
示例4: onResume
import android.speech.tts.TextToSpeech; //導入方法依賴的package包/類
@Override
public void onResume(){
// Disable keyboard
//getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
this.tts = new TextToSpeech(getContext(), new TextToSpeech.OnInitListener() {
@Override
public void onInit(int status) {
// onResume can be called due to returning from selecting the language.
// Play this selected language.
if (toSpeak != null) {
int lang = config.getLanguage();
Locale locale = Languages.getLocale(lang);
tts.setLanguage(locale);
tts.speak(toSpeak, TextToSpeech.QUEUE_FLUSH, null);
toSpeak = null;
}
}
});
super.onResume();
}
示例5: initTTS
import android.speech.tts.TextToSpeech; //導入方法依賴的package包/類
public void initTTS(Locale locale) {
ttsInit = false;
ttsLocale = locale;
// Init text to speech
tts = new TextToSpeech(this, new TextToSpeech.OnInitListener() {
@Override
public void onInit(int status) {
if (status != TextToSpeech.ERROR) {
tts.setLanguage(ttsLocale);
// Make it say it slowly
tts.setSpeechRate(0.75f);
ttsInit = true;
} else ttsInit = false;
}
});
}
示例6: onCreate
import android.speech.tts.TextToSpeech; //導入方法依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.list_standard_layout);
// Load the TTS engine and ask the user to choose a language
textToSpeech = new TextToSpeech(this, new TextToSpeech.OnInitListener() {
@Override
public void onInit(int status) {
if (status == TextToSpeech.ERROR) {
// Display an error message
setContents(new StandardListItem(getResources().getString(R.string.error_tts_engine)));
} else {
textToSpeechReady = true;
// Ask the user to choose a language
askUserToChooseALanguage();
// Show a list of languages the user must select
SupportedLanguage[] supportedLanguages = SupportedLanguage.values();
SimpleListItem[] listItems = new SimpleListItem[supportedLanguages.length];
for (int i = 0; i < supportedLanguages.length; i++) {
listItems[i] = new LanguageListItem(supportedLanguages[i]);
}
setContents(listItems);
}
}
});
}
示例7: onCreate
import android.speech.tts.TextToSpeech; //導入方法依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
// Set the resources locale
String languageExtra = getIntent().getStringExtra(SupportedLanguage.class.getSimpleName());
language = languageExtra == null ? SupportedLanguage.ENGLISH : SupportedLanguage.valueOf(languageExtra);
LocaleUtils.setResourcesLocale(language.getLocale(), this);
// Initialize the activity content
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_camera);
cameraPreview = (CameraPreview) findViewById(R.id.cameraPreview);
// Load the TTS engine and explain to the user that he can take a picture
textToSpeech = new TextToSpeech(this, new TextToSpeech.OnInitListener() {
@Override
public void onInit(int status) {
if (status == TextToSpeech.ERROR) {
Toast.makeText(CameraActivity.this, R.string.error_tts_engine, Toast.LENGTH_SHORT).show();
} else {
textToSpeechReady = true;
textToSpeech.setLanguage(language.getLocale());
askUserToTakePhoto();
openCamera();
}
}
});
}
示例8: run
import android.speech.tts.TextToSpeech; //導入方法依賴的package包/類
@Override
public void run() {
mImagePreprocessor = new ImagePreprocessor();
mTtsSpeaker = new TtsSpeaker();
mTtsSpeaker.setHasSenseOfHumor(true);
mTtsEngine = new TextToSpeech(ImageClassifierActivity.this,
new TextToSpeech.OnInitListener() {
@Override
public void onInit(int status) {
if (status == TextToSpeech.SUCCESS) {
mTtsEngine.setLanguage(Locale.US);
mTtsEngine.setOnUtteranceProgressListener(utteranceListener);
mTtsSpeaker.speakReady(mTtsEngine);
} else {
Log.w(TAG, "Could not open TTS Engine (onInit status=" + status
+ "). Ignoring text to speech");
mTtsEngine = null;
}
}
});
mCameraHandler = CameraHandler.getInstance();
mCameraHandler.initializeCamera(
ImageClassifierActivity.this, mBackgroundHandler,
ImageClassifierActivity.this);
mTensorFlowClassifier = new TensorFlowImageClassifier(ImageClassifierActivity.this);
setReady(true);
}
示例9: 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);
}
示例10: PTextToSpeech
import android.speech.tts.TextToSpeech; //導入方法依賴的package包/類
public PTextToSpeech(AppRunner appRunner) throws InterruptedException {
mTts = new TextToSpeech(appRunner.getAppContext(), new TextToSpeech.OnInitListener() {
@Override
public void onInit(int status) {
if (status == TextToSpeech.SUCCESS) {
mTts.setLanguage(Locale.getDefault());
} else {
MLog.d(TAG, "Could not initialize TextToSpeech.");
}
}
});
}
示例11: TtsProvider
import android.speech.tts.TextToSpeech; //導入方法依賴的package包/類
public TtsProvider(Context context, TextToSpeech.OnInitListener listener) {
// TODO: use the 3-arg constructor (API 14) that supports passing the engine.
// Choose the engine that supports the selected language, if there are several
// then let the user choose.
mTts = new TextToSpeech(context, listener);
mAudioPauser = new AudioPauser(context, false);
Log.i("Default TTS engine:" + mTts.getDefaultEngine());
}
示例12: initTts
import android.speech.tts.TextToSpeech; //導入方法依賴的package包/類
private void initTts() {
mTtsEngine = new TextToSpeech(A2dpSinkActivity.this,
new TextToSpeech.OnInitListener() {
@Override
public void onInit(int status) {
if (status == TextToSpeech.SUCCESS) {
mTtsEngine.setLanguage(Locale.US);
} else {
Log.w(TAG, "Could not open TTS Engine (onInit status=" + status
+ "). Ignoring text to speech");
mTtsEngine = null;
}
}
});
}
示例13: 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();
}
}
});
}