Exemple #1
0
 @Override
 protected void onDestroy() {
   // TODO Auto-generated method stub
   super.onDestroy();
   mTts.pauseSpeaking();
   mTts.destroy();
   //		System.exit(0);
 }
Exemple #2
0
 /**
  * 播报短信内容
  *
  * @param content
  */
 protected void broadcastContent(String content) {
   SpeechSynthesizer tts = SpeachHelper.getInstance(mContext).getSpeechSynthesizer();
   if (null != tts) {
     if (tts.isSpeaking()) {
       tts.stopSpeaking();
     } else {
       tts.startSpeaking(content, mSynListener);
     }
   }
 }
Exemple #3
0
  /**
   * 使用SpeechSynthesizer合成语音,不弹出合成Dialog.
   *
   * @param
   */
  public void playText(String playText) {

    if (!isfinish) {
      return;
    }

    if (null == mSpeechSynthesizer) {
      // 创建合成对象.
      mSpeechSynthesizer = SpeechSynthesizer.createSynthesizer(mContext, minitListener);
      initSpeechSynthesizer();
    }
    mSpeechSynthesizer.startSpeaking(playText, this);
  }
Exemple #4
0
 public void init() {
   if (mSpeechSynthesizer == null) {
     SpeechUtility.createUtility(
         mContext, SpeechConstant.APPID + mContext.getString(R.string.app_id));
     // 初始化合成对象.
     mSpeechSynthesizer = SpeechSynthesizer.createSynthesizer(mContext, minitListener);
     initSpeechSynthesizer();
   }
 }
Exemple #5
0
 private void initSpeech() {
   // 用于验证应用的key
   SpeechUtility.createUtility(RecodeActivity.this, "appid=5577f954");
   // 创建语音听写对象
   mIat = SpeechRecognizer.createRecognizer(this, mInitListener);
   // 初始化听写Dialog,如果只使用有UI听写功能,无需创建SpeechRecognizer
   // 创建语音听写UI
   iatDialog = new RecognizerDialog(this, mInitListener);
   // 创建语音合成对象
   mTts = SpeechSynthesizer.createSynthesizer(this, mInitListener);
 }
Exemple #6
0
 /** 启动语音播放 */
 public void playSpeech(String text) {
   // 设置参数
   setParam2();
   // 朗读
   int code = mTts.startSpeaking(text, mTtsListener);
   if (code != ErrorCode.SUCCESS) {
     if (code == ErrorCode.ERROR_COMPONENT_NOT_INSTALLED) {
       // 未安装则跳转到提示安装页面
     } else {
       Toast.makeText(RecodeActivity.this, "语音合成失败,错误码: " + code, Toast.LENGTH_SHORT).show();
     }
   }
 }
Exemple #7
0
 // 语音识别 设置参数
 private void setParam2() {
   // 设置合成
   mTts.setParameter(SpeechConstant.ENGINE_TYPE, SpeechConstant.TYPE_CLOUD);
   // 设置发音人
   mTts.setParameter(SpeechConstant.VOICE_NAME, voicer);
   // 设置语速
   mTts.setParameter(SpeechConstant.SPEED, "50");
   // 设置音调
   mTts.setParameter(SpeechConstant.PITCH, "50");
   // 设置音量
   mTts.setParameter(SpeechConstant.VOLUME, "50");
   // 设置播放器音频流类型
   mTts.setParameter(SpeechConstant.STREAM_TYPE, "3");
 }
Exemple #8
0
 private void initSpeechSynthesizer() {
   // 设置引擎类型
   mSpeechSynthesizer.setParameter(SpeechConstant.ENGINE_TYPE, SpeechConstant.TYPE_LOCAL);
   // 设置发音人
   mSpeechSynthesizer.setParameter(
       SpeechConstant.VOICE_NAME, mContext.getString(R.string.preference_default_tts_role));
   mSpeechSynthesizer.setParameter(SpeechConstant.STREAM_TYPE, AudioManager.STREAM_MUSIC + "");
   // 设置语速
   mSpeechSynthesizer.setParameter(
       SpeechConstant.SPEED, mContext.getString(R.string.preference_key_tts_speed));
   // 设置音量
   mSpeechSynthesizer.setParameter(
       SpeechConstant.VOLUME, mContext.getString(R.string.preference_key_tts_volume));
   // 设置语调
   mSpeechSynthesizer.setParameter(
       SpeechConstant.PITCH, mContext.getString(R.string.preference_key_tts_pitch));
 }
/**
 * * へ     /|   /\7    ∠_/   / │   / /  │ Z _,< /   /`ヽ  │     ヽ   /  〉   Y     `  /  /
 *  イ● 、 ●  ⊂⊃〈  /  ()  へ    | \〈   >ー 、_  ィ  │ // 去吧!   / へ   / ノ<| \\ 比卡丘~   ヽ_ノ  (_/  │// 消灭代码BUG
 *   7       |/   >―r ̄ ̄`ー―_ Created by WangXin on 2016/7/17 0017.
 */
public class MyJpushReciver extends BroadcastReceiver {
  private SynthesizerListener mTtsListener;
  private SpeechSynthesizer mTts =
      SpeechSynthesizer.createSynthesizer(MyApplication.getContext(), null);

  @Override
  public void onReceive(Context context, Intent intent) {
    Bundle bundle = intent.getExtras();

    if (JPushInterface.ACTION_MESSAGE_RECEIVED.equals(intent.getAction())) {
      String message = bundle.getString(JPushInterface.EXTRA_MESSAGE);
      System.out.println(message + "++++++");
      startTts("实时," + message);
    }
  }

  private void startTts(String text) {
    int code = mTts.startSpeaking(text, (com.iflytek.cloud.SynthesizerListener) mTtsListener);
    if (code != ErrorCode.SUCCESS) {
      System.out.println(code);
    }
  }
}
Exemple #10
0
 public void destroy() {
   if (mSpeechSynthesizer != null) {
     mSpeechSynthesizer.destroy();
   }
 }
Exemple #11
0
 public void stopSpeaking() {
   if (mSpeechSynthesizer != null) mSpeechSynthesizer.stopSpeaking();
 }
 private void startTts(String text) {
   int code = mTts.startSpeaking(text, (com.iflytek.cloud.SynthesizerListener) mTtsListener);
   if (code != ErrorCode.SUCCESS) {
     System.out.println(code);
   }
 }