测试更改

This commit is contained in:
18401019693 2022-11-17 16:01:56 +08:00
parent b8ec25c94e
commit fffa7cdabd
8 changed files with 338 additions and 230 deletions

View File

@ -68,7 +68,17 @@ public class MsgModel extends BaseModel {
private String taskName1;
@SerializedName("taskName2")
private String taskName2;
@SerializedName("activityUrl")
private String activityUrl;
public String getActivityUrl() {
return activityUrl;
}
public MsgModel setActivityUrl(String activityUrl) {
this.activityUrl = activityUrl;
return this;
}
/**
* 星级挑战成功IM消息

View File

@ -10,9 +10,9 @@ ext {
manifestPlaceholders = [
//
// serverHost : "https://napi.yaoulive.com",
serverHost : "https://napi.yaoulive.com",
//
serverHost : "https://ceshi.yaoulive.com",
// serverHost : "https://ceshi.yaoulive.com",
//
txMapAppKey : "EOZBZ-ASLCU-4XPV3-BDCHZ-4E3Q7-H4BWB",

View File

@ -3,68 +3,37 @@ package com.yunbao.live.dialog;
import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.text.SpannableStringBuilder;
import android.text.TextUtils;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
import com.iflytek.cloud.ErrorCode;
import com.iflytek.cloud.InitListener;
import com.iflytek.cloud.RecognizerListener;
import com.iflytek.cloud.RecognizerResult;
import com.iflytek.cloud.SpeechConstant;
import com.iflytek.cloud.SpeechError;
import com.iflytek.cloud.SpeechRecognizer;
import com.yunbao.common.dialog.AbsDialogFragment;
import com.yunbao.common.utils.WordsTypeUtil;
import com.yunbao.live.R;
import com.yunbao.live.activity.LiveAudienceActivity;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.json.JSONTokener;
import java.util.Locale;
import pl.droidsonroids.gif.GifImageView;
public class VoiceDialog extends AbsDialogFragment {
// 语音识别对象
private SpeechRecognizer mIat = null;
private String TAG = "VoiceDialog";
private ImageView voiceFluctuations, iconWithdraw;
private TextView voiceChat, fingersSlide;
private GifImageView gifView;
private SpannableStringBuilder builder = new SpannableStringBuilder();
private boolean isSend = true;
private LinearLayout voiceLayout;
private Handler handler = new Handler();
public boolean isSend() {
return isSend;
}
@Override
public void onStop() {
super.onStop();
}
public String sendMessage() {
if (mIat != null) {
mIat.cancel();
mIat.destroy();
mIat = null;
}
return WordsTypeUtil.changeTraditional(builder.toString());
}
@Override
protected int getLayoutId() {
@ -106,6 +75,7 @@ public class VoiceDialog extends AbsDialogFragment {
voiceChat = (TextView) findViewById(R.id.voice_chat);
fingersSlide = (TextView) findViewById(R.id.fingers_slide);
gifView = (GifImageView) findViewById(R.id.gif_view);
voiceLayout = (LinearLayout) findViewById(R.id.voice_layout);
iconWithdraw.setVisibility(View.GONE);
gifView.setVisibility(View.GONE);
voiceFluctuations.setVisibility(View.VISIBLE);
@ -125,15 +95,14 @@ public class VoiceDialog extends AbsDialogFragment {
* 上划取消
*/
public void withdraw() {
if (mIat != null) {
mIat.stopListening();
if (!isDetached()) {
voiceFluctuations.setVisibility(View.GONE);
gifView.setVisibility(View.GONE);
iconWithdraw.setVisibility(View.VISIBLE);
fingersSlide.setText(getString(R.string.release_cancel_send));
isSend = false;
}
if (!isDetached()) {
voiceFluctuations.setVisibility(View.INVISIBLE);
gifView.setVisibility(View.INVISIBLE);
iconWithdraw.setVisibility(View.VISIBLE);
fingersSlide.setText(getString(R.string.release_cancel_send));
}
}
@ -142,9 +111,8 @@ public class VoiceDialog extends AbsDialogFragment {
* 上划取消
*/
public void notWithdraw(Context context) {
startRecognize(context);
if (!isDetached()) {
if (TextUtils.isEmpty(sendMessage())) {
if (TextUtils.isEmpty(voiceChat.getText())) {
if (gifView.getVisibility() != View.VISIBLE)
voiceFluctuations.setVisibility(View.VISIBLE);
} else {
@ -153,175 +121,21 @@ public class VoiceDialog extends AbsDialogFragment {
}
iconWithdraw.setVisibility(View.GONE);
fingersSlide.setText(getString(R.string.fingers_slide));
isSend = true;
}
}
/**
* 科大讯飞内置录音机
*/
RecognizerListener recognizerListener = new RecognizerListener() {
@Override
public void onVolumeChanged(int volume, byte[] bytes) {
if (volume > 10) {
gifView.setVisibility(View.VISIBLE);
voiceFluctuations.setVisibility(View.GONE);
}
}
@Override
public void onBeginOfSpeech() {
Log.e(TAG, "onBeginOfSpeech 开始讲话");
}
@Override
public void onEndOfSpeech() {
Log.e(TAG, "onBeginOfSpeech 结束讲话");
if (TextUtils.isEmpty(voiceChat.getText())) {
dismiss();
TextHintDialog textHintDialog = new TextHintDialog();
textHintDialog.show(((LiveAudienceActivity) mContext).getSupportFragmentManager(), "TextHintDialog");
}
}
@Override
public void onResult(RecognizerResult recognizerResult, boolean b) {
printResult(recognizerResult);
}
@Override
public void onError(SpeechError speechError) {
if (speechError.getErrorCode() == ErrorCode.ERROR_NO_NETWORK) {
Toast.makeText(
getContext(),
getContext().getString(com.yunbao.common.R.string.load_failure),
Toast.LENGTH_SHORT)
.show();
}
}
@Override
public void onEvent(int i, int i1, int i2, Bundle bundle) {
}
};
/**
* 结束录音
*/
private void endOfSpeech() {
}
/**
* 初始化监听器
*/
private InitListener mInitListener =
code -> Log.e(TAG, "onInit " + code);
/**
* 开始识别
*/
public void startRecognize(Context context) {
if (null == mIat) {
mIat = SpeechRecognizer.createRecognizer(context, mInitListener);
}
if (mIat.isListening()) {
return;
}
setParam();
int ret = mIat.startListening(recognizerListener);
if (ret != ErrorCode.SUCCESS) {
Log.e(TAG, "startRecognize ret error " + ret);
public void setVoiceChat(String voiceChatString) {
if (!isDetached()) {
voiceChat.setText(voiceChatString);
}
}
/**
* 参数设置,设置听写参数详见科大讯飞MSC API手册(Android)SpeechConstant类
*
* @param
* @return
*/
private void setParam() {
// 清空参数
mIat.setParameter(SpeechConstant.PARAMS, null);
// 设置听写引擎
mIat.setParameter(SpeechConstant.ENGINE_TYPE, SpeechConstant.TYPE_CLOUD);
// 设置返回结果格式
mIat.setParameter(SpeechConstant.RESULT_TYPE, "json");
mIat.setParameter(SpeechConstant.DOMAIN, "iat");
if ("zh".equals(Locale.getDefault().getLanguage().toLowerCase())) {
mIat.setParameter(SpeechConstant.LANGUAGE, "zh_cn");
mIat.setParameter(SpeechConstant.ACCENT, "mandarin ");
} else {
mIat.setParameter(SpeechConstant.LANGUAGE, "en_us");
public void startAnimation() {
if (!isDetached()) {
gifView.setVisibility(View.VISIBLE);
voiceFluctuations.setVisibility(View.GONE);
}
// 设置语音前端点:静音超时时间即用户多长时间不说话则当做超时处理
mIat.setParameter(SpeechConstant.VAD_BOS, "10000");
// 设置语音后端点:后端点静音检测时间即用户停止说话多长时间内即认为不再输入 自动停止录音
mIat.setParameter(SpeechConstant.VAD_EOS, "30000");
// 设置标点符号,设置为"0"返回结果无标点,设置为"1"返回结果有标点
mIat.setParameter(SpeechConstant.ASR_PTT, "1");
}
/**
* 打印数据结果
*
* @param result
*/
private void printResult(RecognizerResult result) {
String json = result.getResultString();
String text = parseRecognizeResult(result);
Log.e(TAG, "printResult " + text);
try {
JSONObject obj = new JSONObject(json);
boolean isLast = obj.getBoolean("ls");
if (isLast) {
endOfSpeech();
}
builder.append(text);
voiceChat.setText(WordsTypeUtil.changeTraditional(builder.toString()));
} catch (JSONException e) {
e.printStackTrace();
}
}
/**
* 转译语音返回
*
* @param results
* @return
*/
public String parseRecognizeResult(RecognizerResult results) {
StringBuilder ret = new StringBuilder();
try {
JSONTokener jsonTokener = new JSONTokener(results.getResultString());
JSONObject jsonObject = new JSONObject(jsonTokener);
JSONArray words = jsonObject.getJSONArray("ws");
for (int i = 0; i < words.length(); i++) {
// 转写结果词默认使用第一个结果
JSONArray items = words.getJSONObject(i).getJSONArray("cw");
JSONObject obj = items.getJSONObject(0);
ret.append(obj.getString("w"));
// 如果需要多候选结果解析数组其他字段
// for(int j = 0; j < items.length(); j++)
// {
// JSONObject obj = items.getJSONObject(j);
// ret.append(obj.getString("w"));
// }
}
} catch (Exception e) {
e.printStackTrace();
}
return ret.toString();
}
private VoiceListener listener;

View File

@ -0,0 +1,251 @@
package com.yunbao.live.utils;
import android.content.Context;
import android.os.Bundle;
import android.text.SpannableStringBuilder;
import android.text.TextUtils;
import android.util.Log;
import com.iflytek.cloud.ErrorCode;
import com.iflytek.cloud.InitListener;
import com.iflytek.cloud.RecognizerListener;
import com.iflytek.cloud.RecognizerResult;
import com.iflytek.cloud.SpeechConstant;
import com.iflytek.cloud.SpeechError;
import com.iflytek.cloud.SpeechRecognizer;
import com.yunbao.common.utils.WordsTypeUtil;
import com.yunbao.live.activity.LiveActivity;
import com.yunbao.live.activity.LiveAudienceActivity;
import com.yunbao.live.dialog.TextHintDialog;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.json.JSONTokener;
import java.util.Locale;
public class VoiceUtils {
private SpannableStringBuilder builder = new SpannableStringBuilder();
private String TAG = "VoiceUtils";
private Context mContext;
private boolean isSend = true;
// 语音识别对象
private SpeechRecognizer mIat = null;
//发送消息
private boolean sendMessage = false;
public VoiceUtils(Context context) {
mContext = context;
sendMessage = false;
startRecognize(context);
}
public VoiceUtils setSendMessage(boolean sendMessage) {
this.sendMessage = sendMessage;
return this;
}
/**
* 上划取消
*/
public void withdraw() {
if (mIat != null) {
mIat.stopListening();
isSend = false;
}
}
/**
* 上划取消
*/
public void notWithdraw(Context context) {
startRecognize(context);
isSend = true;
}
/**
* 科大讯飞内置录音机
*/
RecognizerListener recognizerListener = new RecognizerListener() {
@Override
public void onVolumeChanged(int volume, byte[] bytes) {
if (volume > 10 && callBack != null) {
callBack.volumeAnimation(true);
}
}
@Override
public void onBeginOfSpeech() {
Log.e(TAG, "onBeginOfSpeech 开始讲话");
}
@Override
public void onEndOfSpeech() {
Log.e(TAG, "onBeginOfSpeech 结束讲话");
if (TextUtils.isEmpty(builder.toString()) && callBack != null) {
callBack.timeOut();
TextHintDialog textHintDialog = new TextHintDialog();
textHintDialog.show(((LiveAudienceActivity) mContext).getSupportFragmentManager(), "TextHintDialog");
}
}
@Override
public void onResult(RecognizerResult recognizerResult, boolean b) {
printResult(recognizerResult);
}
@Override
public void onError(SpeechError speechError) {
}
@Override
public void onEvent(int i, int i1, int i2, Bundle bundle) {
}
};
/**
* 开始识别
*/
public void startRecognize(Context context) {
if (null == mIat) {
mIat = SpeechRecognizer.createRecognizer(context, mInitListener);
}
if (mIat.isListening()) {
return;
}
setParam();
int ret = mIat.startListening(recognizerListener);
if (ret != ErrorCode.SUCCESS) {
Log.e(TAG, "startRecognize ret error " + ret);
}
}
/**
* 初始化监听器
*/
private InitListener mInitListener =
code -> Log.e(TAG, "onInit " + code);
/**
* 参数设置,设置听写参数详见科大讯飞MSC API手册(Android)SpeechConstant类
*
* @param
* @return
*/
private void setParam() {
// 清空参数
mIat.setParameter(SpeechConstant.PARAMS, null);
// 设置听写引擎
mIat.setParameter(SpeechConstant.ENGINE_TYPE, SpeechConstant.TYPE_CLOUD);
// 设置返回结果格式
mIat.setParameter(SpeechConstant.RESULT_TYPE, "json");
mIat.setParameter(SpeechConstant.DOMAIN, "iat");
if ("zh".equals(Locale.getDefault().getLanguage().toLowerCase())) {
mIat.setParameter(SpeechConstant.LANGUAGE, "zh_cn");
mIat.setParameter(SpeechConstant.ACCENT, "mandarin ");
} else {
mIat.setParameter(SpeechConstant.LANGUAGE, "en_us");
}
// 设置语音前端点:静音超时时间即用户多长时间不说话则当做超时处理
mIat.setParameter(SpeechConstant.VAD_BOS, "10000");
// 设置语音后端点:后端点静音检测时间即用户停止说话多长时间内即认为不再输入 自动停止录音
mIat.setParameter(SpeechConstant.VAD_EOS, "30000");
// 设置标点符号,设置为"0"返回结果无标点,设置为"1"返回结果有标点
mIat.setParameter(SpeechConstant.ASR_PTT, "1");
}
/**
* 打印数据结果
*
* @param result
*/
private void printResult(RecognizerResult result) {
String json = result.getResultString();
String text = parseRecognizeResult(result);
Log.e(TAG, "printResult " + text);
try {
JSONObject obj = new JSONObject(json);
boolean isLast = obj.getBoolean("ls");
builder.append(text);
if (callBack != null) {
callBack.changeBuilder(WordsTypeUtil.changeTraditional(builder.toString()));
}
if (sendMessage) {
((LiveActivity) mContext).sendChatMessage(sendMessage(), null, null);
}
} catch (JSONException e) {
e.printStackTrace();
}
}
/**
* 转译语音返回
*
* @param results
* @return
*/
public String parseRecognizeResult(RecognizerResult results) {
StringBuilder ret = new StringBuilder();
try {
JSONTokener jsonTokener = new JSONTokener(results.getResultString());
JSONObject jsonObject = new JSONObject(jsonTokener);
JSONArray words = jsonObject.getJSONArray("ws");
for (int i = 0; i < words.length(); i++) {
// 转写结果词默认使用第一个结果
JSONArray items = words.getJSONObject(i).getJSONArray("cw");
JSONObject obj = items.getJSONObject(0);
ret.append(obj.getString("w"));
}
} catch (Exception e) {
e.printStackTrace();
}
return ret.toString();
}
public String sendMessage() {
if (mIat != null) {
mIat.cancel();
mIat.destroy();
mIat = null;
}
return WordsTypeUtil.changeTraditional(builder.toString());
}
private VoiceUtilsCallBack callBack;
public VoiceUtils setCallBack(VoiceUtilsCallBack callBack) {
this.callBack = callBack;
return this;
}
public interface VoiceUtilsCallBack {
/**
* 超时回调
*/
void timeOut();
/**
* 文字更改
*/
void changeBuilder(String builder);
/**
* 开启动画
*/
void volumeAnimation(boolean isAnimation);
}
}

View File

@ -53,8 +53,10 @@ import com.yunbao.live.dialog.LiveHDDialogFragment;
import com.yunbao.live.dialog.LiveMicUserDialogFragment;
import com.yunbao.live.dialog.LivePromotionDialogFragment;
import com.yunbao.live.dialog.LiveRoleDialogFragment;
import com.yunbao.live.dialog.TextHintDialog;
import com.yunbao.live.dialog.VoiceDialog;
import com.yunbao.live.event.LiveAudienceEvent;
import com.yunbao.live.utils.VoiceUtils;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
@ -313,7 +315,6 @@ public class LiveAudienceViewHolder extends AbsLiveViewHolder {
handler.postDelayed(mLongPressed, 500);
if (voiceDialog == null) {
voiceDialog = new VoiceDialog();
voiceDialog.startRecognize(mContext);
}
} else {
mProcessResultUtil.requestPermissions(new String[]{Manifest.permission.RECORD_AUDIO}, new Runnable() {
@ -329,10 +330,14 @@ public class LiveAudienceViewHolder extends AbsLiveViewHolder {
if (downY - moveY > 120) {
if (voiceDialog != null && voiceDialog.isAdded())
voiceDialog.withdraw();
if (voiceUtils != null)
voiceUtils.withdraw();
}
if ((downY - moveY < 100) && (downY - moveY > 30)) {
if (voiceDialog != null && voiceDialog.isAdded())
voiceDialog.notWithdraw(mContext);
if (voiceUtils != null)
voiceUtils.notWithdraw(mContext);
}
} else if (event.getAction() == MotionEvent.ACTION_UP) {
//松开
@ -342,13 +347,15 @@ public class LiveAudienceViewHolder extends AbsLiveViewHolder {
.setType(LiveAudienceEvent.LiveAudienceType.VOICE_PRESS));
if (voiceDialog != null) {
if (voiceDialog.isSend() && !TextUtils.isEmpty(voiceDialog.sendMessage())) {
((LiveActivity) mContext).sendChatMessage(voiceDialog.sendMessage(), null, null);
}
voiceDialog.dismiss();
voiceDialog = null;
}
if (voiceUtils != null) {
voiceUtils.withdraw();
voiceUtils.setSendMessage(true);
voiceUtils = null;
}
}
return true;
});
@ -358,6 +365,7 @@ public class LiveAudienceViewHolder extends AbsLiveViewHolder {
private float downY = 0;
private ProcessResultUtil mProcessResultUtil;
private VoiceDialog voiceDialog = null;
private VoiceUtils voiceUtils = null;
private Runnable mLongPressed = new Runnable() {
@Override
public void run() {
@ -373,21 +381,47 @@ public class LiveAudienceViewHolder extends AbsLiveViewHolder {
Bus.get().post(new LiveAudienceEvent()
.setVoicePress(false)
.setType(LiveAudienceEvent.LiveAudienceType.VOICE_PRESS));
if (voiceDialog != null) {
if (voiceDialog.isSend() && !TextUtils.isEmpty(voiceDialog.sendMessage())) {
((LiveActivity) mContext).sendChatMessage(voiceDialog.sendMessage(), null, null);
}
voiceDialog.dismiss();
voiceDialog = null;
}
if (voiceUtils != null) {
voiceUtils.withdraw();
voiceUtils.setSendMessage(true);
voiceUtils = null;
}
}
});
voiceDialog.show(((LiveAudienceActivity) mContext).getSupportFragmentManager(), "VoiceDialog");
Bus.get().post(new LiveAudienceEvent()
.setVoicePress(true)
.setType(LiveAudienceEvent.LiveAudienceType.VOICE_PRESS));
voiceUtils = new VoiceUtils(mContext).setCallBack(new VoiceUtils.VoiceUtilsCallBack() {
@Override
public void timeOut() {
if (voiceDialog != null) {
voiceDialog.dismiss();
voiceUtils.withdraw();
voiceUtils = null;
TextHintDialog textHintDialog = new TextHintDialog();
textHintDialog.show(((LiveAudienceActivity) mContext).getSupportFragmentManager(), "TextHintDialog");
}
}
@Override
public void changeBuilder(String builder) {
if (voiceDialog != null)
voiceDialog.setVoiceChat(builder);
}
@Override
public void volumeAnimation(boolean isAnimation) {
if (voiceDialog != null)
voiceDialog.startAnimation();
}
});
}
};
@ -479,7 +513,6 @@ public class LiveAudienceViewHolder extends AbsLiveViewHolder {
bundle.putString("url", url);
bundle.putInt("show_type", 0);
bundle.putInt("height", DpUtil.dp2px(1));
// bundle.putBoolean("banScrollY",true);
LiveHDDialogFragment liveHDDialogFragment = new LiveHDDialogFragment();
liveHDDialogFragment.setArguments(bundle);
liveHDDialogFragment.show(((LiveAudienceActivity) mContext).getSupportFragmentManager(), "LiveHDDialogFragment");

View File

@ -1184,7 +1184,7 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis
htmlUrl.append(CommonAppConfig.HOST)
.append("/")
.append(bean.getModel().getActivityUrl())
.append("&nickname=")
.append(bean.getModel().getActivityUrl().contains("?") ? "&nickname=" : "?nickname=")
.append(userInfo.getUserNicename())
.append("&token=")
.append(userInfo.getToken())

View File

@ -178,8 +178,7 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe
private Handler liveHandler = new Handler();
//公共參數
private OpenParametersModel openParametersModel = null;
//星级活动地址
private String activityUrl = "";
//标记是调用正常退出还是手动切后台
private boolean isQuitF = false;
@ -1647,7 +1646,7 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe
mLiveRoomViewHolder
.showStart(
new StarChallengeStatusModel(activityUrl)
new StarChallengeStatusModel(msgModel.getActivityUrl())
.setTaskNum(msgModel.getTaskNum())
.setTaskName1(msgModel.getTaskName1())
.setTaskName2(msgModel.getTaskName2())

View File

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/voice_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/bg_voice_chat"
@ -10,8 +11,8 @@
android:id="@+id/icon_withdraw"
android:layout_width="38dp"
android:layout_height="31dp"
android:layout_marginTop="23dp"
android:layout_marginStart="20dp"
android:layout_marginTop="23dp"
android:layout_marginEnd="20dp"
android:src="@mipmap/icon_withdraw" />
@ -19,8 +20,8 @@
android:id="@+id/voice_fluctuations"
android:layout_width="154dp"
android:layout_height="wrap_content"
android:layout_marginTop="23dp"
android:layout_marginStart="20dp"
android:layout_marginTop="23dp"
android:layout_marginEnd="20dp"
android:scaleType="fitCenter"
android:src="@mipmap/img_p" />
@ -29,8 +30,8 @@
android:id="@+id/gif_view"
android:layout_width="154dp"
android:layout_height="wrap_content"
android:layout_marginTop="23dp"
android:layout_marginStart="20dp"
android:layout_marginTop="23dp"
android:layout_marginEnd="20dp"
android:background="@mipmap/voice_fluctuations"
android:visibility="gone" />
@ -41,8 +42,8 @@
android:layout_height="wrap_content"
android:layout_marginStart="5dp"
android:layout_marginTop="8dp"
android:layout_marginBottom="10dp"
android:layout_marginEnd="5dp"
android:layout_marginBottom="10dp"
android:maxLines="5"
android:textColor="#FFFFFF"
android:textSize="14sp" />
@ -51,9 +52,9 @@
android:id="@+id/fingers_slide"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:layout_marginStart="5dp"
android:layout_marginEnd="5dp"
android:layout_marginBottom="16dp"
android:text="@string/fingers_slide"
android:textColor="#9A9A9A" />