本文整理汇总了Java中android.speech.tts.TextToSpeech.setLanguage方法的典型用法代码示例。如果您正苦于以下问题:Java TextToSpeech.setLanguage方法的具体用法?Java TextToSpeech.setLanguage怎么用?Java TextToSpeech.setLanguage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.speech.tts.TextToSpeech
的用法示例。
在下文中一共展示了TextToSpeech.setLanguage方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: Init
import android.speech.tts.TextToSpeech; //导入方法依赖的package包/类
public void Init() {
if (_ttsInitialized) {
Logger.getInstance().Warning(TAG, "Already initialized!");
return;
}
_ttsSpeaker = new TextToSpeech(_context, status -> {
if (status == TextToSpeech.SUCCESS) {
int result = _ttsSpeaker.setLanguage(Locale.US);
if (result == TextToSpeech.LANG_MISSING_DATA || result == TextToSpeech.LANG_NOT_SUPPORTED) {
Logger.getInstance().Error(TAG, "This Language is not supported!");
} else {
_receiverController.RegisterReceiver(_speakReceiver, new String[]{TTS_SPEAK_TEXT_BROADCAST});
_ttsInitialized = true;
}
} else {
Logger.getInstance().Error(TAG, "Initialization failed!");
}
});
}
示例2: 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()));
}
}
});
}
示例3: 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!");
}
}
});
}
示例4: 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;
}
});
}
示例5: 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();
}
}
});
}
示例6: 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);
}
示例7: 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);
}
示例8: 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.");
}
}
});
}
示例9: 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;
}
}
});
}
示例10: 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();
}
}
});
}