當前位置: 首頁>>代碼示例>>Java>>正文


Java TextToSpeech.OnInitListener方法代碼示例

本文整理匯總了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()));
        }
      }
    });
  }
 
開發者ID:nordfalk,項目名稱:EsperantoRadio,代碼行數:25,代碼來源:Talesyntese.java

示例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!");
                }
            }
        });
    }
 
開發者ID:aidaferreira,項目名稱:synesthesiavision,代碼行數:26,代碼來源:TextToSpeechManager.java

示例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();
}
 
開發者ID:rkshuai,項目名稱:chromium-for-android-56-debug-video,代碼行數:19,代碼來源:TtsPlatformImpl.java

示例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();
}
 
開發者ID:nelladragon,項目名稱:scab,代碼行數:23,代碼來源:SettingsConfigFragment.java

示例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;
        }
    });
}
 
開發者ID:feelfreelinux,項目名稱:WordLing,代碼行數:17,代碼來源:WordLing.java

示例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);
            }
        }
    });
}
 
開發者ID:marcplouhinec,項目名稱:speaking-glasses,代碼行數:30,代碼來源:MainActivity.java

示例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();
            }
        }
    });
}
 
開發者ID:marcplouhinec,項目名稱:speaking-glasses,代碼行數:28,代碼來源:CameraActivity.java

示例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);
}
 
開發者ID:FoxLabMakerSpace,項目名稱:SIGHT-For-the-Blind,代碼行數:31,代碼來源:ImageClassifierActivity.java

示例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);
}
 
開發者ID:jiangkang,項目名稱:KTools,代碼行數:28,代碼來源:AudioActivity.java

示例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.");
                }
            }
        });
    }
 
開發者ID:victordiaz,項目名稱:phonk,代碼行數:14,代碼來源:PTextToSpeech.java

示例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());
}
 
開發者ID:vaibhavs4424,項目名稱:AI-Powered-Intelligent-Banking-Platform,代碼行數:9,代碼來源:TtsProvider.java

示例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;
                    }
                }
            });
}
 
開發者ID:androidthings,項目名稱:sample-bluetooth-audio,代碼行數:16,代碼來源:A2dpSinkActivity.java

示例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();
            }
        }
    });
}
 
開發者ID:marcplouhinec,項目名稱:speaking-glasses,代碼行數:51,代碼來源:PhotoAnalysisActivity.java


注:本文中的android.speech.tts.TextToSpeech.OnInitListener方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。