语音转文字
This commit is contained in:
parent
b4e048bf74
commit
172b37ece2
@ -41,7 +41,7 @@ public class ProcessFragment extends Fragment {
|
||||
* @param permissions
|
||||
* @return true 有权限 false无权限
|
||||
*/
|
||||
private boolean checkPermissions(String[] permissions) {
|
||||
public boolean checkPermissions(String[] permissions) {
|
||||
for (String permission : permissions) {
|
||||
if (ContextCompat.checkSelfPermission(mContext, permission) != PackageManager.PERMISSION_GRANTED) {
|
||||
return false;
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.yunbao.common.utils;
|
||||
|
||||
import android.content.Intent;
|
||||
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
import androidx.fragment.app.FragmentTransaction;
|
||||
@ -28,6 +29,9 @@ public class ProcessResultUtil {
|
||||
mFragment.requestPermissions(permissions, runnable);
|
||||
}
|
||||
|
||||
public boolean checkPermissions(String[] permissions) {
|
||||
return mFragment.checkPermissions(permissions);
|
||||
}
|
||||
|
||||
public void startActivityForResult(Intent intent, ActivityResultCallback callback) {
|
||||
mFragment.startActivityForResult(intent, callback);
|
||||
|
@ -3,6 +3,7 @@
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
package="com.yunbao.live">
|
||||
<!--com.kugou.fanxing.allinone.watch.liveroominone.media.FALiveRoomInOneActivity"-->
|
||||
<uses-permission android:name="android.permission.VIBRATE" />
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
|
||||
|
@ -914,8 +914,11 @@ public class LiveAudienceActivity extends LiveActivity {
|
||||
if (IMLoginManager.get(mContext).isSlide()) {
|
||||
if (event.isVoicePress()) {
|
||||
verticalViewPager.setEnableScroll(false);
|
||||
manager.setSecondPageEnableScroll(false);
|
||||
|
||||
} else {
|
||||
verticalViewPager.setEnableScroll(true);
|
||||
manager.setSecondPageEnableScroll(true);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -83,8 +83,8 @@ public class VoiceDialog extends AbsDialogFragment {
|
||||
protected void setWindowAttributes(Window window) {
|
||||
window.setWindowAnimations(com.yunbao.common.R.style.bottomToTopAnim);
|
||||
WindowManager.LayoutParams params = window.getAttributes();
|
||||
params.width = DpUtil.dp2px(350);
|
||||
params.height = DpUtil.dp2px(200);
|
||||
params.width =WindowManager.LayoutParams.WRAP_CONTENT;
|
||||
params.height = WindowManager.LayoutParams.WRAP_CONTENT;
|
||||
params.gravity = Gravity.CENTER;
|
||||
window.setAttributes(params);
|
||||
}
|
||||
@ -99,6 +99,8 @@ public class VoiceDialog extends AbsDialogFragment {
|
||||
gifView = (GifImageView) findViewById(R.id.gif_view);
|
||||
startRecognize();
|
||||
iconWithdraw.setVisibility(View.GONE);
|
||||
gifView.setVisibility(View.GONE);
|
||||
voiceFluctuations.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -116,10 +118,13 @@ public class VoiceDialog extends AbsDialogFragment {
|
||||
* 上划取消
|
||||
*/
|
||||
public void notWithdraw() {
|
||||
if (TextUtils.isEmpty(sendMessage())){
|
||||
voiceFluctuations.setVisibility(View.VISIBLE);
|
||||
}else {
|
||||
gifView.setVisibility(View.VISIBLE);
|
||||
}
|
||||
iconWithdraw.setVisibility(View.GONE);
|
||||
fingersSlide.setText(getString(R.string.fingers_slide));
|
||||
gifView.setVisibility(View.VISIBLE);
|
||||
isSend = true;
|
||||
}
|
||||
|
||||
@ -129,7 +134,7 @@ public class VoiceDialog extends AbsDialogFragment {
|
||||
RecognizerListener recognizerListener = new RecognizerListener() {
|
||||
@Override
|
||||
public void onVolumeChanged(int volume, byte[] bytes) {
|
||||
if (volume > 20) {
|
||||
if (volume > 10) {
|
||||
gifView.setVisibility(View.VISIBLE);
|
||||
voiceFluctuations.setVisibility(View.GONE);
|
||||
}
|
||||
@ -138,14 +143,12 @@ public class VoiceDialog extends AbsDialogFragment {
|
||||
@Override
|
||||
public void onBeginOfSpeech() {
|
||||
Log.e(TAG, "onBeginOfSpeech 开始讲话");
|
||||
voiceFluctuations.setVisibility(View.GONE);
|
||||
gifView.setVisibility(View.VISIBLE);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEndOfSpeech() {
|
||||
Log.e(TAG, "onBeginOfSpeech 结束讲话");
|
||||
ImgLoader.displayGif(mContext, R.mipmap.img_p, voiceFluctuations);
|
||||
if (TextUtils.isEmpty(voiceChat.getText())) {
|
||||
dismiss();
|
||||
TextHintDialog textHintDialog = new TextHintDialog();
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.yunbao.live.views;
|
||||
|
||||
import android.Manifest;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
@ -8,6 +9,7 @@ import android.graphics.Canvas;
|
||||
import android.graphics.Color;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Vibrator;
|
||||
import android.text.TextUtils;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.util.Log;
|
||||
@ -22,6 +24,8 @@ import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
import android.widget.ViewFlipper;
|
||||
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
|
||||
import com.opensource.svgaplayer.SVGADrawable;
|
||||
import com.opensource.svgaplayer.SVGAImageView;
|
||||
import com.opensource.svgaplayer.SVGAParser;
|
||||
@ -36,6 +40,7 @@ import com.yunbao.common.http.HttpCallback;
|
||||
import com.yunbao.common.http.HttpClient;
|
||||
import com.yunbao.common.utils.Bus;
|
||||
import com.yunbao.common.utils.DpUtil;
|
||||
import com.yunbao.common.utils.ProcessResultUtil;
|
||||
import com.yunbao.common.utils.SVGAViewUtils;
|
||||
import com.yunbao.common.utils.SpUtil;
|
||||
import com.yunbao.common.utils.ToastUtil;
|
||||
@ -129,6 +134,7 @@ public class LiveAudienceViewHolder extends AbsLiveViewHolder {
|
||||
SVGADrawable drawable = new SVGADrawable(videoItem);
|
||||
svga_new_user_gif.setImageDrawable(drawable);
|
||||
SVGAViewUtils.playEndClear(svga_new_user_gif);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -269,14 +275,26 @@ public class LiveAudienceViewHolder extends AbsLiveViewHolder {
|
||||
voiceButton.setOnTouchListener((v, event) -> {
|
||||
if (event.getAction() == MotionEvent.ACTION_DOWN) {
|
||||
downY = event.getY();
|
||||
if (mProcessResultUtil.checkPermissions(new String[]{Manifest.permission.RECORD_AUDIO})) {
|
||||
//按下
|
||||
handler.postDelayed(mLongPressed, 500);
|
||||
} else {
|
||||
mProcessResultUtil.requestPermissions(new String[]{Manifest.permission.RECORD_AUDIO}, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
} else if (event.getAction() == MotionEvent.ACTION_MOVE) {
|
||||
float moveY = event.getY();
|
||||
if (downY - moveY > 120) {
|
||||
if (voiceDialog != null)
|
||||
voiceDialog.withdraw();
|
||||
}
|
||||
if ((downY - moveY < 100) && (downY - moveY > 30)) {
|
||||
if (voiceDialog != null)
|
||||
voiceDialog.notWithdraw();
|
||||
}
|
||||
} else if (event.getAction() == MotionEvent.ACTION_UP) {
|
||||
@ -297,15 +315,18 @@ public class LiveAudienceViewHolder extends AbsLiveViewHolder {
|
||||
}
|
||||
return true;
|
||||
});
|
||||
|
||||
mProcessResultUtil = new ProcessResultUtil((FragmentActivity) mContext);
|
||||
}
|
||||
|
||||
private float downY = 0;
|
||||
|
||||
private ProcessResultUtil mProcessResultUtil;
|
||||
private VoiceDialog voiceDialog = null;
|
||||
private Runnable mLongPressed = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
Vibrator vibrator = (Vibrator) mContext.getSystemService(Context.VIBRATOR_SERVICE);
|
||||
vibrator.vibrate(30);//震动时间(ms)
|
||||
if (voiceDialog == null) {
|
||||
voiceDialog = new VoiceDialog();
|
||||
}
|
||||
|
@ -14,6 +14,7 @@ import android.os.Handler;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.FrameLayout;
|
||||
@ -61,7 +62,6 @@ import com.yunbao.common.utils.WordUtil;
|
||||
import com.yunbao.common.utils.formatBigNum;
|
||||
import com.yunbao.common.views.weight.LiveFloatView;
|
||||
import com.yunbao.live.R;
|
||||
import com.yunbao.live.activity.FALiveRoomInOneActivity;
|
||||
import com.yunbao.live.activity.LiveActivity;
|
||||
import com.yunbao.live.activity.LiveAudienceActivity;
|
||||
import com.yunbao.live.bean.LiveBuyGuardMsgBean;
|
||||
@ -408,7 +408,8 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe
|
||||
@Override
|
||||
public void onStop() {
|
||||
boolean isForeground = LifecycleUtils.INSTANCE.isForeground();
|
||||
if (mLiveBean != null && !isQuitF && !isForeground) {
|
||||
boolean floatPermission = PermissionUtils.checkPermission(mContext);
|
||||
if (mLiveBean != null && !isQuitF && !isForeground && floatPermission) {
|
||||
LiveFloatView.getInstance()
|
||||
.cacheLiveData(mLiveBean, mLiveType, mLiveSDK, mLiveTypeVal)
|
||||
.builderSystemFloat(mContext, mLiveBean.getPull());
|
||||
@ -1626,4 +1627,8 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe
|
||||
mLiveRoomViewHolder.chatScrollToBottom();
|
||||
}
|
||||
}
|
||||
|
||||
public void setSecondPageEnableScroll(boolean enableScroll) {
|
||||
mViewPager.setCanScroll(enableScroll);
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<corners android:radius="9dp"/>
|
||||
<solid android:color="#000000"/>
|
||||
<solid android:color="#90000000"/>
|
||||
</shape>
|
@ -11,8 +11,8 @@
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/voice_press"
|
||||
android:layout_width="54dp"
|
||||
android:layout_height="54dp"
|
||||
android:layout_width="64dp"
|
||||
android:layout_height="64dp"
|
||||
android:visibility="gone"
|
||||
android:src="@mipmap/icon_voice_press"
|
||||
android:layout_alignParentBottom="true"
|
||||
|
@ -1,23 +1,27 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="270dp"
|
||||
android:layout_height="170dp"
|
||||
android:background="@drawable/bg_voice_chat">
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@drawable/bg_voice_chat"
|
||||
android:gravity="center_horizontal"
|
||||
android:orientation="vertical">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/icon_withdraw"
|
||||
android:layout_width="38dp"
|
||||
android:layout_height="31dp"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:layout_marginTop="5dp"
|
||||
android:layout_marginTop="23dp"
|
||||
android:layout_marginStart="20dp"
|
||||
android:layout_marginEnd="20dp"
|
||||
android:src="@mipmap/icon_withdraw" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/voice_fluctuations"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:layout_marginTop="30dp"
|
||||
android:layout_marginTop="23dp"
|
||||
android:layout_marginStart="20dp"
|
||||
android:layout_marginEnd="20dp"
|
||||
android:scaleType="fitCenter"
|
||||
android:src="@mipmap/img_p" />
|
||||
|
||||
@ -25,31 +29,31 @@
|
||||
android:id="@+id/gif_view"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:layout_marginTop="30dp"
|
||||
android:layout_marginTop="23dp"
|
||||
android:layout_marginStart="20dp"
|
||||
android:layout_marginEnd="20dp"
|
||||
android:background="@mipmap/voice_fluctuations"
|
||||
android:visibility="gone" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/fingers_slide"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:layout_marginBottom="16dp"
|
||||
android:text="@string/fingers_slide"
|
||||
android:textColor="#9A9A9A" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/voice_chat"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:layout_marginStart="8dp"
|
||||
android:layout_marginTop="55dp"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:maxLines="4"
|
||||
android:layout_marginStart="5dp"
|
||||
android:layout_marginTop="8dp"
|
||||
android:layout_marginBottom="10dp"
|
||||
android:layout_marginEnd="5dp"
|
||||
android:maxLines="5"
|
||||
android:textColor="#FFFFFF"
|
||||
android:textSize="14sp" />
|
||||
</RelativeLayout>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/fingers_slide"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="16dp"
|
||||
android:text="@string/fingers_slide"
|
||||
android:textColor="#9A9A9A" />
|
||||
|
||||
|
||||
</LinearLayout>
|
@ -93,7 +93,7 @@
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_width="99dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1">
|
||||
|
||||
@ -138,8 +138,7 @@
|
||||
android:id="@+id/btn_start"
|
||||
android:layout_width="60dp"
|
||||
android:layout_height="60dp"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_centerInParent="true"
|
||||
android:onClick="mainClick"
|
||||
android:src="@mipmap/icon_main_start" />
|
||||
</RelativeLayout>
|
||||
|
Loading…
Reference in New Issue
Block a user