示例#1
0
 @Override
 protected void onDestroy() {
   // TODO Auto-generated method stub
   super.onDestroy();
   mTts.pauseSpeaking();
   mTts.destroy();
   //		System.exit(0);
 }
示例#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);
     }
   }
 }
示例#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);
  }
示例#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();
   }
 }
示例#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);
 }
示例#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();
     }
   }
 }
示例#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");
 }
示例#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));
 }
示例#9
0
/**
 * * へ     /|   /\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);
    }
  }
}
示例#10
0
 public void destroy() {
   if (mSpeechSynthesizer != null) {
     mSpeechSynthesizer.destroy();
   }
 }
示例#11
0
 public void stopSpeaking() {
   if (mSpeechSynthesizer != null) mSpeechSynthesizer.stopSpeaking();
 }
示例#12
0
 private void startTts(String text) {
   int code = mTts.startSpeaking(text, (com.iflytek.cloud.SynthesizerListener) mTtsListener);
   if (code != ErrorCode.SUCCESS) {
     System.out.println(code);
   }
 }